diff --git a/apps/web/src/components/diff-viewer/index.tsx b/apps/web/src/components/diff-viewer/index.tsx
index c411194d4..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 (
{
@@ -110,8 +104,8 @@ function DiffViewer(props: DiffViewerProps) {
}}
dangerouslySetInnerHTML={{
__html:
- session.type === "diff"
- ? diff(session.oldContentTitle || "", session.note.title)
+ session.type === "diff" && session.oldTitle
+ ? diff(session.oldTitle || "", session.note.title)
: session.note.title
}}
>
@@ -145,28 +139,34 @@ function DiffViewer(props: DiffViewerProps) {
{strings.restoreThisVersion()}
-
+ )}
{
@@ -179,165 +179,183 @@ function DiffViewer(props: DiffViewerProps) {
>
) : null}
-
-
+ {strings.noContent()}
+
+ ) : (
+
- {content.locked ? (
- {
- const decryptedContent = await db.vault.decryptContent(
- content,
- password
- );
- setContent({
- ...content,
- ...decryptedContent,
- locked: false
- });
- }}
- />
- ) : (
- <>
- setSelectedContent((s) => (s === 0 ? -1 : 0))}
- resolveConflict={onResolveContent}
- sx={{
- borderStyle: "solid",
- borderWidth: 0,
- borderBottomWidth: 1,
- borderColor: "border",
- px: 2,
- pb: 1
+
+ {content.locked ? (
+ {
+ const decryptedContent = await db.vault.decryptContent(
+ content,
+ password
+ );
+ setContent({
+ ...content,
+ ...decryptedContent,
+ locked: false
+ });
}}
/>
-
-
-
+
+ setSelectedContent((s) => (s === 0 ? -1 : 0))
+ }
+ resolveConflict={onResolveContent}
sx={{
- px: 2,
- overflowY: "auto",
- flex: 1,
borderStyle: "solid",
borderWidth: 0,
- borderRightWidth: [0, 0, 1],
- borderBottomWidth: [1, 1, 0],
- borderColor: "border"
+ borderBottomWidth: 1,
+ borderColor: "border",
+ px: 2,
+ pb: 1
}}
- >
- content.data}
- session={session}
- nonce={content.dateEdited}
- options={{ readonly: true, headless: true }}
- />
-
-
- >
- )}
-
-
- {conflictedContent.locked ? (
- {
- const decryptedContent = await db.vault.decryptContent(
- conflictedContent,
- password
- );
- setConflictedContent({
- ...conflictedContent,
- ...decryptedContent,
- locked: false
- });
- }}
- />
- ) : (
- <>
- setSelectedContent((s) => (s === 1 ? -1 : 1))}
- sx={{
- alignItems: "flex-end",
- borderStyle: "solid",
- borderWidth: 0,
- borderBottomWidth: 1,
- borderColor: "border",
- px: 2,
- pb: 1,
- pt: [1, 1, 0]
+ />
+
+
+
+ content.data}
+ session={session}
+ nonce={content.dateEdited}
+ options={{ readonly: true, headless: true }}
+ />
+
+
+ >
+ )}
+
+
+ {conflictedContent.locked ? (
+ {
+ const decryptedContent = await db.vault.decryptContent(
+ conflictedContent,
+ password
+ );
+ setConflictedContent({
+ ...conflictedContent,
+ ...decryptedContent,
+ locked: false
+ });
}}
/>
-
-
-
- content.locked
- ? conflictedContent.data
- : diff(content.data, conflictedContent.data)
- }
- nonce={conflictedContent.dateEdited}
- options={{ readonly: true, headless: true }}
- />
-
-
- >
- )}
+ ) : (
+ <>
+
+ setSelectedContent((s) => (s === 1 ? -1 : 1))
+ }
+ sx={{
+ alignItems: "flex-end",
+ borderStyle: "solid",
+ borderWidth: 0,
+ borderBottomWidth: 1,
+ borderColor: "border",
+ px: 2,
+ pb: 1,
+ pt: [1, 1, 0]
+ }}
+ />
+
+
+
+ content.locked
+ ? conflictedContent.data
+ : diff(content.data, conflictedContent.data)
+ }
+ nonce={conflictedContent.dateEdited}
+ options={{ readonly: true, headless: true }}
+ />
+
+
+ >
+ )}
+
-
-
+
+ )}
);
}
@@ -379,7 +397,7 @@ async function resolveConflict({
await notesStore.refresh();
}
-async function createCopy(note: Note, content: ContentItem) {
+async function createCopy(note: Note, content: ContentItem, title?: string) {
if (content.locked) {
const contentId = await db.content.add({
locked: true,
@@ -389,7 +407,7 @@ async function createCopy(note: Note, content: ContentItem) {
});
return await db.notes.add({
contentId,
- title: note.title + " (COPY)"
+ title: title || note.title + " (COPY)"
});
} else {
return await db.notes.add({
@@ -397,7 +415,7 @@ async function createCopy(note: Note, content: ContentItem) {
type: "tiptap",
data: content.data
},
- title: note.title + " (COPY)"
+ title: title || note.title + " (COPY)"
});
}
}
diff --git a/apps/web/src/stores/editor-store.ts b/apps/web/src/stores/editor-store.ts
index a649285bc..445e7ab9c 100644
--- a/apps/web/src/stores/editor-store.ts
+++ b/apps/web/src/stores/editor-store.ts
@@ -144,8 +144,8 @@ export type DiffEditorSession = BaseEditorSession & {
type: "diff";
note: Note;
content: ContentItem;
+ oldTitle?: string;
historySessionId: string;
- oldContentTitle?: string;
};
export type EditorSession =
@@ -620,12 +620,13 @@ class EditorStore extends BaseStore {
openDiffSession = async (noteId: string, sessionId: string) => {
const session = await db.noteHistory.session(sessionId);
const note = await db.notes.note(noteId);
- if (!session || !note || !note.contentId) return;
+ if (!session || !note) return;
- const currentContent = await db.content.get(note.contentId);
+ const currentContent = note.contentId
+ ? await db.content.get(note.contentId)
+ : undefined;
const oldContent = await db.noteHistory.content(session.id);
-
- if (!oldContent || !currentContent) return;
+ if (!oldContent) return;
const {
getSession,
@@ -659,7 +660,7 @@ class EditorStore extends BaseStore {
note,
tabId,
title: label,
- oldContentTitle: oldContent.title,
+ oldTitle: oldContent.title,
historySessionId: session.id,
content: {
type: oldContent.type || "tiptap",
@@ -1356,7 +1357,7 @@ const useEditorStore = createPersistedStore(EditorStore, {
}, [] as EditorSession[])
}),
storage: db.config() as PersistStorage>
-});
+}) as ReturnType>;
export { useEditorStore, SESSION_STATES };
const MILLISECONDS_IN_A_MINUTE = 60 * 1000;