From 1e023500be29bd811b7a92105a5d76d0d75ccc9a Mon Sep 17 00:00:00 2001 From: Ammar Ahmed Date: Sat, 10 Jan 2026 12:55:03 +0500 Subject: [PATCH] mobile: add support for setting note history session title --- .../app/components/note-history/index.tsx | 5 +- .../note-history/{preview.jsx => preview.tsx} | 85 ++++++++++++++----- .../app/screens/editor/tiptap/use-editor.ts | 5 +- 3 files changed, 69 insertions(+), 26 deletions(-) rename apps/mobile/app/components/note-history/{preview.jsx => preview.tsx} (72%) diff --git a/apps/mobile/app/components/note-history/index.tsx b/apps/mobile/app/components/note-history/index.tsx index a369975db..a39cd11b8 100644 --- a/apps/mobile/app/components/note-history/index.tsx +++ b/apps/mobile/app/components/note-history/index.tsx @@ -47,7 +47,7 @@ const HistoryItem = ({ }: { index: number; items?: VirtualizedGrouping; - note?: Note; + note: Note; }) => { const [item] = useDBItem(index, "noteHistory", items); const { colors } = useThemeColors(); @@ -73,6 +73,7 @@ const HistoryItem = ({ session: getDate(item.dateCreated, item.dateModified) }} content={content} + note={note} /> ), context: "note_history" @@ -135,7 +136,7 @@ export default function NoteHistory({ const renderItem = useCallback( ({ index }: { index: number }) => ( - + ), [history] ); diff --git a/apps/mobile/app/components/note-history/preview.jsx b/apps/mobile/app/components/note-history/preview.tsx similarity index 72% rename from apps/mobile/app/components/note-history/preview.jsx rename to apps/mobile/app/components/note-history/preview.tsx index 65dc0ba0f..c61f972c3 100644 --- a/apps/mobile/app/components/note-history/preview.jsx +++ b/apps/mobile/app/components/note-history/preview.tsx @@ -37,21 +37,43 @@ import Paragraph from "../ui/typography/paragraph"; import { diff } from "diffblazer"; import { strings } from "@notesnook/intl"; import { DefaultAppStyles } from "../../utils/styles"; +import { + HistorySession, + isEncryptedContent, + Note, + NoteContent, + SessionContentItem, + TrashOrItem +} from "@notesnook/core"; /** * * @param {any} param0 * @returns */ -export default function NotePreview({ session, content, note }) { +export default function NotePreview({ + session, + content, + note +}: { + session: HistorySession & { session: string }; + content: + | Partial< + NoteContent & { + title: string; + } + > + | undefined; + note: TrashOrItem; +}) { const { colors } = useThemeColors(); const [locked, setLocked] = useState(false); async function restore() { if (note && note.type === "trash") { - if ((await db.trash.restore(note.id)) === false) return; + await db.trash.restore(note.id); Navigation.queueRoutesForUpdate(); - useSelectionStore.getState().setSelectionMode(false); + useSelectionStore.getState().setSelectionMode(); ToastManager.show({ heading: strings.noteRestored(), type: "success" @@ -91,15 +113,17 @@ export default function NotePreview({ session, content, note }) { negativeText: strings.cancel(), context: "local", positivePress: async () => { - await db.trash.delete(note.id); - useTrashStore.getState().refresh(); - useSelectionStore.getState().setSelectionMode(false); - ToastManager.show({ - heading: strings.noteDeleted(), - type: "success", - context: "local" - }); - eSendEvent(eCloseSheet); + if (note) { + await db.trash.delete(note.id); + useTrashStore.getState().refresh(); + useSelectionStore.getState().setSelectionMode(); + ToastManager.show({ + heading: strings.noteDeleted(), + type: "success", + context: "local" + }); + eSendEvent(eCloseSheet); + } }, positiveType: "error" }); @@ -113,8 +137,11 @@ export default function NotePreview({ session, content, note }) { }} > - - {!session?.locked && !locked ? ( + + {!session?.locked && !locked && content?.data ? ( { try { - if (content.data) { - const _note = note || (await db.notes.note(session?.noteId)); - const currentContent = await db.content.get(_note.contentId); - loadContent({ - data: diff(currentContent.data, content.data), - id: _note.id - }); + if (content?.data) { + const currentContent = note?.contentId + ? await db.content.get(note.contentId) + : undefined; + + if ( + currentContent?.data && + !isEncryptedContent(currentContent) + ) { + loadContent({ + data: diff( + currentContent?.data || "

", + content.data as string + ), + id: session?.noteId + }); + } } } catch (e) { ToastManager.error( - e, + e as Error, "Failed to load history preview", "local" ); @@ -153,7 +190,9 @@ export default function NotePreview({ session, content, note }) { }} > - {strings.encryptedNoteHistoryNotice()} + {!content?.data + ? strings.noContent() + : strings.encryptedNoteHistoryNotice()}
)} diff --git a/apps/mobile/app/screens/editor/tiptap/use-editor.ts b/apps/mobile/app/screens/editor/tiptap/use-editor.ts index 478b7dfeb..a2123fbfa 100644 --- a/apps/mobile/app/screens/editor/tiptap/use-editor.ts +++ b/apps/mobile/app/screens/editor/tiptap/use-editor.ts @@ -298,7 +298,8 @@ export const useEditor = ( return; } - if (isContentInvalid(data) && id) { + if (!title && isContentInvalid(data) && id) { + console.log("new editor session", title, isContentInvalid(data), id); // Create a new history session if recieved empty or invalid content // To ensure that history is preserved for correct content. currentSessionHistoryId = editorSessionHistory.newSession(id); @@ -312,6 +313,8 @@ export const useEditor = ( sessionId: `${currentSessionHistoryId}` }; + console.log(noteData.sessionId); + noteData.title = title; if (ignoreEdit) {