From 9a031a4a4368e625037706354dd3a4b60d3f724d Mon Sep 17 00:00:00 2001 From: Ammar Ahmed Date: Mon, 30 Oct 2023 13:22:03 +0500 Subject: [PATCH] mobile: fix selection state causing delete to fail --- .../list-items/selection-wrapper/index.js | 3 +++ apps/mobile/app/utils/functions.js | 15 ++++++--------- 2 files changed, 9 insertions(+), 9 deletions(-) diff --git a/apps/mobile/app/components/list-items/selection-wrapper/index.js b/apps/mobile/app/components/list-items/selection-wrapper/index.js index ffa55e8a6..6a6a25683 100644 --- a/apps/mobile/app/components/list-items/selection-wrapper/index.js +++ b/apps/mobile/app/components/list-items/selection-wrapper/index.js @@ -43,6 +43,9 @@ const SelectionWrapper = ({ const onLongPress = () => { if (!useSelectionStore.getState().selectionMode) { + useSelectionStore.setState({ + selectedItemsList: [] + }); useSelectionStore.getState().setSelectionMode(true); } useSelectionStore.getState().setSelectedItem(item); diff --git a/apps/mobile/app/utils/functions.js b/apps/mobile/app/utils/functions.js index 9bc68848d..1b27dcff1 100644 --- a/apps/mobile/app/utils/functions.js +++ b/apps/mobile/app/utils/functions.js @@ -67,15 +67,10 @@ export const deleteItems = async (item, context) => { }); return; } - if ( - item && - item.id && - useSelectionStore.getState().selectedItemsList.length === 0 - ) { - useSelectionStore.getState().setSelectedItem(item); - } - const { selectedItemsList } = useSelectionStore.getState(); + const selectedItemsList = item + ? [item] + : useSelectionStore.getState().selectedItemsList; let notes = selectedItemsList.filter((i) => i.type === "note"); let notebooks = selectedItemsList.filter((i) => i.type === "notebook"); @@ -179,7 +174,9 @@ export const deleteItems = async (item, context) => { }); } Navigation.queueRoutesForUpdate(); - useSelectionStore.getState().clearSelection(); + if (!item) { + useSelectionStore.getState().clearSelection(); + } useMenuStore.getState().setMenuPins(); useMenuStore.getState().setColorNotes(); SearchService.updateAndSearch();