diff --git a/web/src/components/sideMenu/SideMenu.tsx b/web/src/components/sideMenu/SideMenu.tsx index a299ea5..88a83ab 100644 --- a/web/src/components/sideMenu/SideMenu.tsx +++ b/web/src/components/sideMenu/SideMenu.tsx @@ -16,7 +16,7 @@ type SideMenuProps = { }; export default function SideMenu({ strikedItems }: SideMenuProps) { - const [{ sideMenuState }, dispatch] = useStateValue(); + const [{ sideMenuState, currentListId }, dispatch] = useStateValue(); const handleAddItemClick = () => { dispatch({ @@ -34,7 +34,7 @@ export default function SideMenu({ strikedItems }: SideMenuProps) { const [strikeItems, strikeItemsSubmitting] = useStrikeItems(); const handleUnStrikeAllClick = async () => { if (strikeItemsSubmitting) return; - await strikeItems(strikedItems); + await strikeItems(strikedItems, currentListId); handleReturnClick(); }; diff --git a/web/src/hooks/mutations/item/useStrikeItems.ts b/web/src/hooks/mutations/item/useStrikeItems.ts index 2ab8f35..9d1875d 100644 --- a/web/src/hooks/mutations/item/useStrikeItems.ts +++ b/web/src/hooks/mutations/item/useStrikeItems.ts @@ -7,41 +7,44 @@ import { sendNotification } from 'src/utils/dispatchActions'; export default function useStrikeItems() { const [mutationSubmitting, setMutationSubmitting] = useState(false); - const [{ currentListId: listId }, dispatch] = useStateValue(); + const [, dispatch] = useStateValue(); const [strikeItems] = useStrikeItemsMutation(); const mutationCooldown = useDelayedFunction(() => setMutationSubmitting(false) ); - const sendMutation = useCallback(async (itemNameArray: string[]) => { - if (mutationSubmitting) return; - setMutationSubmitting(true); + const sendMutation = useCallback( + async (itemNameArray: string[], listId: string) => { + if (mutationSubmitting) return; + setMutationSubmitting(true); - try { - const { data } = await strikeItems({ - variables: { - data: { - itemNameArray, - listId + try { + const { data } = await strikeItems({ + variables: { + data: { + itemNameArray, + listId + } } - } - }); - if (data?.strikeItems.errors) { - errorNotification(data.strikeItems.errors, dispatch); - mutationCooldown(); - } else { - dispatch({ - type: 'ADD_TO_UNDO', - payload: ['strikeItems', { itemNameArray, listId }] }); + if (data?.strikeItems.errors) { + errorNotification(data.strikeItems.errors, dispatch); + mutationCooldown(); + } else { + dispatch({ + type: 'ADD_TO_UNDO', + payload: ['strikeItems', { itemNameArray, listId }] + }); + } + dispatch({ type: 'CLEAR_STATE' }); + } catch (err) { + sendNotification(dispatch, [ + 'Connection to the server could not be established. Interacting with the list will not function offline.' + ]); + dispatch({ type: 'CLEAR_STATE' }); } - dispatch({ type: 'CLEAR_STATE' }); - } catch (err) { - sendNotification(dispatch, [ - 'Connection to the server could not be established. Interacting with the list will not function offline.' - ]); - dispatch({ type: 'CLEAR_STATE' }); - } - }, []); + }, + [] + ); return [sendMutation, mutationSubmitting] as const; }