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: add notebook search
Ammar Ahmedc6af310b2df8
diff --git a/apps/mobile/app/components/sheets/add-notebook/index.tsx b/apps/mobile/app/components/sheets/add-notebook/index.tsxindex 89994779d..0e99ebcf9 100644--- a/apps/mobile/app/components/sheets/add-notebook/index.tsx+++ b/apps/mobile/app/components/sheets/add-notebook/index.tsx@@ -45,14 +45,16 @@ export const AddNotebookSheet = ({notebook,parentNotebook,close,- showMoveNotesOnComplete+ showMoveNotesOnComplete,+ defaultTitle}: {notebook?: Notebook;parentNotebook?: Notebook;close?: (didAddNotebook: boolean) => void;showMoveNotesOnComplete: boolean;+ defaultTitle?: string;}) => {- const title = useRef(notebook?.title);+ const title = useRef(notebook?.title || defaultTitle);const description = useRef(notebook?.description);const titleInput = useRef<TextInput>(null);const descriptionInput = useRef<TextInput>(null);@@ -139,7 +141,7 @@ export const AddNotebookSheet = ({}}returnKeyLabel="Next"returnKeyType="next"- defaultValue={notebook ? notebook.title : ""}+ defaultValue={notebook ? notebook.title : title.current}/><Input@@ -174,7 +176,8 @@ AddNotebookSheet.present = (parentNotebook?: Notebook,context?: string,onClose?: (didAddNotebook: boolean) => void,- showMoveNotesOnComplete = true+ showMoveNotesOnComplete = true,+ defaultTitle?: string) => {presentSheet({context: context,@@ -187,6 +190,7 @@ AddNotebookSheet.present = (onClose?.(didAddNotebook);}}showMoveNotesOnComplete={showMoveNotesOnComplete || false}+ defaultTitle={defaultTitle}/>)});diff --git a/apps/mobile/app/components/sheets/add-to/index.tsx b/apps/mobile/app/components/sheets/add-to/index.tsxindex 165a4e67b..ff29d5e97 100644--- a/apps/mobile/app/components/sheets/add-to/index.tsx+++ b/apps/mobile/app/components/sheets/add-to/index.tsx@@ -19,7 +19,13 @@ along with this program. If not, see <http://www.gnu.org/licenses/>.import { Note } from "@notesnook/core";import { useThemeColors } from "@notesnook/theme";-import React, { RefObject, useCallback, useEffect } from "react";+import React, {+ RefObject,+ useCallback,+ useEffect,+ useRef,+ useState+} from "react";import {ActivityIndicator,Keyboard,@@ -47,6 +53,8 @@ import Paragraph from "../../ui/typography/paragraph";import { NotebookItem } from "./notebook-item";import { useNotebookItemSelectionStore } from "./store";import { AddNotebookSheet } from "../add-notebook";+import Input from "../../ui/input";+import { presentDialog } from "../../dialog/functions";async function updateInitialSelectionState(items: string[]) {const relations = await db.relations@@ -93,7 +101,11 @@ const MoveNoteSheet = ({actionSheetRef: RefObject<ActionSheetRef>;}) => {const { colors } = useThemeColors();- const [notebooks, loading] = useNotebooks();+ const [rootNotebooks, loading] = useNotebooks();+ const searchQuery = useRef("");+ const searchTimer = useRef<NodeJS.Timeout>();+ const [notebooks, setNotebooks] = useState(rootNotebooks);+const dimensions = useSettingStore((state) => state.dimensions);const selectedItemsList = useSelectionStore((state) => state.selectedItemsList@@ -103,6 +115,12 @@ const MoveNoteSheet = ({(state) => state.multiSelect);+ useEffect(() => {+ if (!loading) {+ setNotebooks(rootNotebooks);+ }+ }, [loading, rootNotebooks]);+useEffect(() => {const items = note ? [note.id] : selectedItemsList;updateInitialSelectionState(items);@@ -199,7 +217,6 @@ const MoveNoteSheet = ({{hasSelected() ? (<IconButtonname="restore"- type="secondaryAccented"color={colors.primary.icon}onPress={() => {const items = note ? [note.id] : selectedItemsList;@@ -239,33 +256,48 @@ const MoveNoteSheet = ({style={{width: "100%"}}+ keyboardShouldPersistTaps="handled"ListHeaderComponent={<Viewstyle={{paddingHorizontal: 12,- width: "100%"+ width: "100%",+ paddingTop: 12}}>- <Button- title="Add new notebook"- style={{- alignSelf: "flex-start",- paddingHorizontal: 12,- justifyContent: "space-between"+ <Input+ placeholder="Search notebooks...."+ button={{+ icon: "plus",+ onPress: () => {+ AddNotebookSheet.present(+ undefined,+ undefined,+ "link-notebooks",+ undefined,+ false,+ searchQuery.current+ );+ },+ color: colors.primary.icon}}- onPress={() => {- AddNotebookSheet.present(- undefined,- undefined,- "link-notebooks",- undefined,- false- );+ onChangeText={(value) => {+ searchQuery.current = value;+ if (!searchQuery.current) {+ setNotebooks(rootNotebooks);+ return;+ }+ searchTimer.current = setTimeout(() => {+ db.lookup+ .notebooks(searchQuery.current)+ .sorted()+ .then((result) => {+ if (searchQuery.current === value) {+ setNotebooks(result);+ }+ });+ }, 300);}}- icon="plus"- iconPosition="right"- type="secondaryAccented"- width="100%"/></View>}