A fully open source & end-to-end encrypted note taking alternative to Evernote.
TypeScript asp-net-coredotnet-coreelectronfosshacktoberfestnote-managmentnote-takingnote-taking-appnotebooknotesnotes-appopen-sourceopensourceprivacyproductivityreactreact-nativereactjsself-hosted
mobile: fix notebook tree when searching notebooks
Ammar Ahmed2885b9ac3e83
diff --git a/apps/mobile/app/components/side-menu/notebook-item.tsx b/apps/mobile/app/components/side-menu/notebook-item.tsxindex 35beefbb3..2f49a731d 100644--- a/apps/mobile/app/components/side-menu/notebook-item.tsx+++ b/apps/mobile/app/components/side-menu/notebook-item.tsx@@ -49,7 +49,8 @@ export const NotebookItem = ({onPress,onLongPress,onAddNotebook,- canDisableSelectionMode+ canDisableSelectionMode,+ disableExpand}: {index: number;item: TreeItem;@@ -64,6 +65,7 @@ export const NotebookItem = ({onLongPress?: () => void;onAddNotebook?: () => void;canDisableSelectionMode?: boolean;+ disableExpand?: boolean;}) => {const notebook = item.notebook;const isFocused = focused;@@ -166,7 +168,7 @@ export const NotebookItem = ({}testID={item.hasChildren ? `expand-notebook-${index}` : ""}onPress={() => {- if (item.hasChildren) {+ if (item.hasChildren && disableExpand) {onToggleExpanded?.();} else {onPress?.();@@ -182,7 +184,7 @@ export const NotebookItem = ({borderRadius: defaultBorderRadius}}name={- !item.hasChildren+ !item.hasChildren || disableExpand? "book-outline": expanded? "chevron-down"diff --git a/apps/mobile/app/components/side-menu/side-menu-notebooks.tsx b/apps/mobile/app/components/side-menu/side-menu-notebooks.tsxindex ddfa5ce5f..291aa395d 100644--- a/apps/mobile/app/components/side-menu/side-menu-notebooks.tsx+++ b/apps/mobile/app/components/side-menu/side-menu-notebooks.tsx@@ -20,8 +20,9 @@ along with this program. If not, see <http://www.gnu.org/licenses/>.import { Notebook } from "@notesnook/core";import { strings } from "@notesnook/intl";import { useThemeColors } from "@notesnook/theme";+import { FlashList } from "@shopify/flash-list";import React, { useEffect, useState } from "react";-import { FlatList, TextInput, View } from "react-native";+import { TextInput, View } from "react-native";import { db } from "../../common/database";import NotebookScreen from "../../screens/notebook";import Navigation from "../../services/navigation";@@ -42,6 +43,7 @@ import {useSideMenuNotebookSelectionStore.setState({multiSelect: true});+export const SideMenuNotebooks = () => {const tree = useSideMenuNotebookTreeStore((state) => state.tree);const [notebooks, loading] = useNotebooks();@@ -64,6 +66,9 @@ export const SideMenuNotebooks = () => {const updateNotebooks = React.useCallback(() => {if (lastQuery.current) {+ useSideMenuNotebookTreeStore.setState({+ isSearching: true+ });db.lookup.notebooks(lastQuery.current).sorted(db.settings.getGroupOptions("notebooks"))@@ -71,6 +76,9 @@ export const SideMenuNotebooks = () => {setFilteredNotebooks(filtered);});} else {+ useSideMenuNotebookTreeStore.setState({+ isSearching: false+ });setFilteredNotebooks(notebooks);}}, [notebooks]);@@ -137,13 +145,13 @@ export const SideMenuNotebooks = () => {/>) : (<>- <FlatList+ <FlashListdata={tree}bounces={false}bouncesZoom={false}overScrollMode="never"- keyExtractor={(item) => item.notebook.id}- windowSize={3}+ // keyExtractor={(item,) => item.notebook.id}+ estimatedItemSize={30}ListHeaderComponent={<Viewstyle={{@@ -196,7 +204,9 @@ const NotebookItemWrapper = React.memo(const expanded = useSideMenuNotebookExpandedStore((state) => state.expanded[item.notebook.id]);-+ const disableExpand = useSideMenuNotebookTreeStore(+ (state) => state.isSearching+ );const selectionEnabled = useSideMenuNotebookSelectionStore((state) => state.enabled);@@ -256,6 +266,7 @@ const NotebookItemWrapper = React.memo(.removeChildren(item.notebook.id);}}}+ disableExpand={disableExpand}selected={selected}selectionEnabled={selectionEnabled}selectionStore={useSideMenuNotebookSelectionStore}diff --git a/apps/mobile/app/screens/link-notebooks/index.tsx b/apps/mobile/app/screens/link-notebooks/index.tsxindex d85664f35..0e6398417 100644--- a/apps/mobile/app/screens/link-notebooks/index.tsx+++ b/apps/mobile/app/screens/link-notebooks/index.tsx@@ -118,8 +118,14 @@ const LinkNotebooks = (props: NavigationProps<"LinkNotebooks">) => {.then((filtered) => {setFilteredNotebooks(filtered);});+ useNotebookTreeStore.setState({+ isSearching: true+ });} else {setFilteredNotebooks(notebooks);+ useNotebookTreeStore.setState({+ isSearching: false+ });}}, [notebooks]);@@ -300,6 +306,8 @@ const NotebookItemWrapper = React.memo(const expanded = useNotebookExpandedStore((state) => state.expanded[item.notebook.id]);+ const disableExpand = useNotebookTreeStore((state) => state.isSearching);+const selectionEnabled = useNotebookSelectionStore((state) => state.enabled);@@ -371,6 +379,7 @@ const NotebookItemWrapper = React.memo(selectionEnabled={selectionEnabled}selectionStore={useNotebookSelectionStore}onItemUpdate={onItemUpdate}+ disableExpand={disableExpand}focused={false}onPress={onPress}onAddNotebook={() => {diff --git a/apps/mobile/app/screens/move-notebook/index.tsx b/apps/mobile/app/screens/move-notebook/index.tsxindex a8a78071b..d963c98e4 100644--- a/apps/mobile/app/screens/move-notebook/index.tsx+++ b/apps/mobile/app/screens/move-notebook/index.tsx@@ -90,8 +90,14 @@ export const MoveNotebook = (props: NavigationProps<"MoveNotebook">) => {.then((filtered) => {setFilteredNotebooks(filtered);});+ useNotebookTreeStore.setState({+ isSearching: true+ });} else {setFilteredNotebooks(notebooks);+ useNotebookTreeStore.setState({+ isSearching: false+ });}}, [notebooks]);@@ -328,6 +334,8 @@ const NotebookItemWrapper = React.memo(const expanded = useNotebookExpandedStore((state) => state.expanded[item.notebook.id]);+ const disableExpand = useNotebookTreeStore((state) => state.isSearching);+const selectionEnabled = useNotebookSelectionStore((state) => state.enabled);@@ -378,6 +386,7 @@ const NotebookItemWrapper = React.memo(useNotebookTreeStore.getState().removeChildren(item.notebook.id);}}}+ disableExpand={disableExpand}selected={selected}selectionEnabled={selectionEnabled}selectionStore={useNotebookSelectionStore}diff --git a/apps/mobile/app/stores/create-notebook-tree-stores.ts b/apps/mobile/app/stores/create-notebook-tree-stores.tsindex 281d36209..dcb2d2acd 100644--- a/apps/mobile/app/stores/create-notebook-tree-stores.ts+++ b/apps/mobile/app/stores/create-notebook-tree-stores.ts@@ -49,6 +49,7 @@ export function createNotebookTreeStores() {const useNotebookTreeStore = create<{tree: TreeItem[];+ isSearching?: boolean;setTree: (tree: TreeItem[]) => void;removeItem: (id: string) => void;addNotebooks: (@@ -130,7 +131,7 @@ export function createNotebookTreeStores(const expanded =useNotebookExpandedStore.getState().expanded[item.notebook.id] &&item.hasChildren;- if (expanded) {+ if (expanded && !get().isSearching) {newTree = await get().fetchAndAdd(item.notebook.id,depth + 1,