From 9b86c6ebb72586f06b884a8526003ffd9a4c6175 Mon Sep 17 00:00:00 2001 From: ammarahm-ed Date: Thu, 23 Mar 2023 13:17:13 +0500 Subject: [PATCH] mobile: fix multiselection bugs --- .../components/sheets/add-to/filtered-list.js | 1 - .../app/components/sheets/add-to/index.js | 56 ++++++++++++------- .../app/components/sheets/add-to/list-item.js | 6 +- apps/mobile/app/package.json | 2 +- 4 files changed, 41 insertions(+), 24 deletions(-) diff --git a/apps/mobile/app/components/sheets/add-to/filtered-list.js b/apps/mobile/app/components/sheets/add-to/filtered-list.js index 53b70e75d..ca7936444 100644 --- a/apps/mobile/app/components/sheets/add-to/filtered-list.js +++ b/apps/mobile/app/components/sheets/add-to/filtered-list.js @@ -71,7 +71,6 @@ export const FilteredList = ({ } keyboardShouldPersistTaps="always" keyboardDismissMode="none" - nestedScrollEnabled /> ); }; diff --git a/apps/mobile/app/components/sheets/add-to/index.js b/apps/mobile/app/components/sheets/add-to/index.js index 9aca6b8f9..0f654053a 100644 --- a/apps/mobile/app/components/sheets/add-to/index.js +++ b/apps/mobile/app/components/sheets/add-to/index.js @@ -26,6 +26,7 @@ import Navigation from "../../../services/navigation"; import SearchService from "../../../services/search"; import { useNotebookStore } from "../../../stores/use-notebook-store"; import { useSelectionStore } from "../../../stores/use-selection-store"; +import { useSettingStore } from "../../../stores/use-setting-store"; import { useThemeStore } from "../../../stores/use-theme-store"; import { Dialog } from "../../dialog"; import DialogHeader from "../../dialog/dialog-header"; @@ -42,7 +43,7 @@ const MoveNoteSheet = ({ note, actionSheetRef }) => { const notebooks = useNotebookStore((state) => state.notebooks.filter((n) => n?.type === "notebook") ); - + const dimensions = useSettingStore((state) => state.dimensions); const selectedItemsList = useSelectionStore( (state) => state.selectedItemsList ); @@ -132,6 +133,10 @@ const MoveNoteSheet = ({ note, actionSheetRef }) => { useEffect(() => { resetItemState(); + return () => { + useItemSelectionStore.getState().setMultiSelect(false); + useItemSelectionStore.getState().setItemState({}); + }; // eslint-disable-next-line react-hooks/exhaustive-deps }, []); @@ -139,6 +144,7 @@ const MoveNoteSheet = ({ note, actionSheetRef }) => { (state) => { const itemState = {}; const notebooks = db.notebooks.all; + let count = 0; for (let notebook of notebooks) { itemState[notebook.id] = state ? state @@ -148,6 +154,7 @@ const MoveNoteSheet = ({ note, actionSheetRef }) => { ? "intermediate" : "deselected"; if (itemState[notebook.id] === "selected") { + count++; contextValue.select(notebook); } else { contextValue.deselect(notebook); @@ -162,13 +169,18 @@ const MoveNoteSheet = ({ note, actionSheetRef }) => { ? "intermediate" : "deselected"; if (itemState[topic.id] === "selected") { + count++; contextValue.select(topic); } else { contextValue.deselect(topic); } } } - + if (count > 1) { + useItemSelectionStore.getState().setMultiSelect(true); + } else { + useItemSelectionStore.getState().setMultiSelect(false); + } useItemSelectionStore.getState().setItemState(itemState); }, [contextValue, getSelectedNotesCountInItem, selectedItemsList] @@ -335,31 +347,32 @@ const MoveNoteSheet = ({ note, actionSheetRef }) => { /> - {multiSelect ? ( - +