From 46583e12d939b9292ddfdb159dc1cc3f4ee1da62 Mon Sep 17 00:00:00 2001 From: Ammar Ahmed Date: Wed, 29 Jan 2025 12:30:18 +0500 Subject: [PATCH] mobile: update tabs --- .../components/sheets/editor-tabs/index.tsx | 41 ++--- apps/mobile/app/screens/editor/source.ts | 2 +- .../app/screens/editor/tiptap/commands.ts | 99 ++++-------- .../mobile/app/screens/editor/tiptap/types.ts | 4 +- .../editor/tiptap/use-editor-events.tsx | 8 +- .../app/screens/editor/tiptap/use-editor.ts | 146 +++++++++++++++--- .../screens/editor/tiptap/use-tab-store.ts | 146 ++++++++++-------- .../mobile/app/screens/editor/tiptap/utils.ts | 6 +- .../editor-mobile/src/components/editor.tsx | 7 +- .../src/hooks/useEditorController.ts | 10 +- .../editor-mobile/src/hooks/useTabStore.ts | 12 +- packages/editor-mobile/src/utils/index.ts | 16 +- .../editor-mobile/src/utils/pending-saves.ts | 8 +- 13 files changed, 277 insertions(+), 228 deletions(-) diff --git a/apps/mobile/app/components/sheets/editor-tabs/index.tsx b/apps/mobile/app/components/sheets/editor-tabs/index.tsx index a485b00b8..ec2b63034 100644 --- a/apps/mobile/app/components/sheets/editor-tabs/index.tsx +++ b/apps/mobile/app/components/sheets/editor-tabs/index.tsx @@ -25,7 +25,10 @@ import { FlatList } from "react-native-actions-sheet"; import Icon from "react-native-vector-icons/MaterialCommunityIcons"; import { db } from "../../../common/database"; import { useDBItem } from "../../../hooks/use-db-item"; -import { useTabStore } from "../../../screens/editor/tiptap/use-tab-store"; +import { + TabItem, + useTabStore +} from "../../../screens/editor/tiptap/use-tab-store"; import { editorController } from "../../../screens/editor/tiptap/utils"; import { eSendEvent, presentSheet } from "../../../services/event-manager"; import { eUnlockNote } from "../../../utils/events"; @@ -37,23 +40,13 @@ import Heading from "../../ui/typography/heading"; import Paragraph from "../../ui/typography/paragraph"; import { strings } from "@notesnook/intl"; -type TabItem = { - id: number; - noteId?: string; - previewTab?: boolean; - locked?: boolean; - noteLocked?: boolean; - readonly?: boolean; - pinned?: boolean; -}; - const TabItemComponent = (props: { tab: TabItem; isFocused: boolean; close?: (ctx?: string | undefined) => void; }) => { const { colors } = useThemeColors(); - const [item, update] = useDBItem(props.tab.noteId, "note"); + const [item, update] = useDBItem(props.tab.session?.noteId, "note"); useEffect(() => { const syncCompletedSubscription = db.eventManager?.subscribe( @@ -85,11 +78,11 @@ const TabItemComponent = (props: { onPress={() => { if (!props.isFocused) { useTabStore.getState().focusTab(props.tab.id); - if (props.tab.locked) { + if (props.tab.session?.locked) { eSendEvent(eUnlockNote); } - if (!props.tab.noteId) { + if (!props.tab.session?.noteId) { setTimeout(() => { editorController?.current?.commands?.focus(props.tab.id); }, 300); @@ -107,9 +100,9 @@ const TabItemComponent = (props: { flexShrink: 1 }} > - {props.tab.noteLocked ? ( + {props.tab.session?.noteLocked ? ( <> - {props.tab.locked ? ( + {props.tab.session?.locked ? ( ) : ( @@ -117,7 +110,9 @@ const TabItemComponent = (props: { ) : null} - {props.tab.readonly ? : null} + {props.tab.session?.readonly ? ( + + ) : null} - {props.tab.noteId + {props.tab.session?.noteId ? item?.title || strings.untitledNote() : strings.newNote()} @@ -230,11 +220,6 @@ export default function EditorTabs({