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..aa351882a 100644 --- a/apps/mobile/app/screens/editor/tiptap/use-editor.ts +++ b/apps/mobile/app/screens/editor/tiptap/use-editor.ts @@ -298,7 +298,7 @@ export const useEditor = ( return; } - if (isContentInvalid(data) && id) { + if (!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); diff --git a/apps/web/src/components/diff-viewer/index.tsx b/apps/web/src/components/diff-viewer/index.tsx index 013e738e0..724e09722 100644 --- a/apps/web/src/components/diff-viewer/index.tsx +++ b/apps/web/src/components/diff-viewer/index.tsx @@ -17,13 +17,7 @@ You should have received a copy of the GNU General Public License along with this program. If not, see . */ -import { - useCallback, - useEffect, - useLayoutEffect, - useRef, - useState -} from "react"; +import { useCallback, useEffect, useLayoutEffect, useState } from "react"; import { Flex, Text, Button } from "@theme-ui/components"; import { Copy, Restore } from "../icons"; import ContentToggle from "./content-toggle"; @@ -59,6 +53,8 @@ function DiffViewer(props: DiffViewerProps) { const onResolveContent = useCallback( (saveCopy: boolean) => { + if (!conflictedContent) return; + const toKeep = selectedContent === 1 ? session.content?.conflicted : session.content; const toCopy = @@ -69,7 +65,7 @@ function DiffViewer(props: DiffViewerProps) { toKeep, toCopy: saveCopy ? toCopy : undefined, toKeepDateEdited: toKeep.dateEdited, - dateResolved: conflictedContent!.dateModified + dateResolved: conflictedContent.dateModified }); }, [conflictedContent, selectedContent, session.content, session.note] @@ -82,8 +78,6 @@ function DiffViewer(props: DiffViewerProps) { }); }, [session]); - if (!conflictedContent || !content) return null; - return ( { @@ -105,11 +99,16 @@ function DiffViewer(props: DiffViewerProps) { whiteSpace: "nowrap", overflow: "hidden", textOverflow: "ellipsis", - textAlign: "center" + textAlign: "center", + paddingTop: 10 }} - > - {session.note.title} - + dangerouslySetInnerHTML={{ + __html: + session.type === "diff" && session.oldTitle + ? diff(session.oldTitle || "", session.note.title) + : session.note.title + }} + > {session.type === "diff" ? ( <> @@ -140,28 +139,34 @@ function DiffViewer(props: DiffViewerProps) { {strings.restoreThisVersion()} - + await notesStore.refresh(); + await openSession(noteId); + }} + mr={2} + sx={{ + alignItems: "center", + justifyContent: "center", + display: "flex" + }} + > + + {strings.saveACopy()} + + )}