Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 5 additions & 1 deletion src/core/store.ts
Original file line number Diff line number Diff line change
Expand Up @@ -120,7 +120,11 @@ export const reducer = (state: ToasterState, action: Action): ToasterState => {
};

case ActionType.END_PAUSE:
const diff = action.time - (state.pausedAt || 0);
// Only update pauseDuration if we were actually paused
if (!state.pausedAt) {
return state;
}
const diff = action.time - state.pausedAt;

return {
...state,
Expand Down
25 changes: 12 additions & 13 deletions src/core/toast.ts
Original file line number Diff line number Diff line change
Expand Up @@ -64,17 +64,16 @@ toast.custom = createHandler('custom');
* Dismisses the toast with the given id. If no id is given, dismisses all toasts.
* The toast will transition out and then be removed from the DOM.
* Applies to all toasters, except when a `toasterId` is given.
* Also ends pause state to ensure pause timer is reset when manually dismissing.
*/
toast.dismiss = (toastId?: string, toasterId?: string) => {
const action: Action = {
type: ActionType.DISMISS_TOAST,
toastId,
};

if (toasterId) {
createDispatch(toasterId)(action);
const dispatch = createDispatch(toasterId);
dispatch({ type: ActionType.DISMISS_TOAST, toastId });
dispatch({ type: ActionType.END_PAUSE, time: Date.now() });
} else {
dispatchAll(action);
dispatchAll({ type: ActionType.DISMISS_TOAST, toastId });
dispatchAll({ type: ActionType.END_PAUSE, time: Date.now() });
}
};

Expand All @@ -86,16 +85,16 @@ toast.dismissAll = (toasterId?: string) => toast.dismiss(undefined, toasterId);
/**
* Removes the toast with the given id.
* The toast will be removed from the DOM without any transition.
* Also ends pause state to ensure pause timer is reset when manually removing.
*/
toast.remove = (toastId?: string, toasterId?: string) => {
const action: Action = {
type: ActionType.REMOVE_TOAST,
toastId,
};
if (toasterId) {
createDispatch(toasterId)(action);
const dispatch = createDispatch(toasterId);
dispatch({ type: ActionType.REMOVE_TOAST, toastId});
dispatch({ type: ActionType.END_PAUSE, time: Date.now() });
} else {
dispatchAll(action);
dispatchAll({ type: ActionType.REMOVE_TOAST, toastId });
dispatchAll({ type: ActionType.END_PAUSE, time: Date.now() });
}
};

Expand Down