Cockatrice/webclient/src/components/Toast/reducer.ts
Jeremy Letto 26d7fe2ff0
Webatrice: update deps (#4700)
* save work

* fix reset styling

* fix toast reducer

* update non-react deps

* update react libraries

* remove jquery, use sanitize-html instead

* add missing change

* fix deps and dev deps

* update workflow to target Node 16

* run @mui/codemod to remove @mui/styles

* add default body font size

* update react 17 to 18

* declare enum before use

* add rel attr to links

* fix font sizing issue

* trailing commas

* refactor deep destructuring

Co-authored-by: Jeremy Letto <jeremy.letto@datasite.com>
2022-11-01 12:41:42 -05:00

61 lines
1.1 KiB
TypeScript

export const ACTIONS = {
ADD_TOAST: 'ADD_TOAST',
OPEN_TOAST: 'OPEN_TOAST',
CLOSE_TOAST: 'CLOSE_TOAST',
REMOVE_TOAST: 'REMOVE_TOAST',
}
export const initialState = {
toasts: {}
}
export function reducer(state, { type, payload }) {
const { key, children } = payload;
switch (type) {
case ACTIONS.ADD_TOAST: {
return {
...state,
toasts: {
...state.toasts,
[key]: {
isOpen: false,
children,
},
},
};
}
case ACTIONS.OPEN_TOAST: {
return {
...state,
toasts: {
...state.toasts,
[key]: {
...state.toasts[key],
isOpen: true,
},
},
};
}
case ACTIONS.CLOSE_TOAST: {
return {
...state,
toasts: {
...state.toasts,
[key]: {
...state.toasts[key],
isOpen: false,
},
},
};
}
case ACTIONS.REMOVE_TOAST: {
const newState = { ...state };
delete newState.toasts[key];
return newState;
}
default:
throw Error('Please pick an available action')
}
}