mirror of
https://github.com/streetwriters/notesnook.git
synced 2026-09-01 11:39:21 +02:00
Compare commits
2 Commits
fix-cache-
...
fix-editor
| Author | SHA1 | Date | |
|---|---|---|---|
|
|
0ecdbe5ff0 | ||
|
|
79c71f1cc6 |
@@ -224,13 +224,14 @@ export default function TabsView() {
|
|||||||
);
|
);
|
||||||
}
|
}
|
||||||
|
|
||||||
const MemoizedEditorView = React.memo(
|
const MemoizedEditorView = React.memo(EditorView, (prev, next) => {
|
||||||
EditorView,
|
return (
|
||||||
(prev, next) =>
|
|
||||||
prev.session.id === next.session.id &&
|
prev.session.id === next.session.id &&
|
||||||
prev.session.type === next.session.type &&
|
(prev.session.type === next.session.type ||
|
||||||
prev.session.needsHydration === next.session.needsHydration
|
(prev.session.type === "new" && next.session.type === "default")) &&
|
||||||
);
|
!!prev.session.needsHydration === !!next.session.needsHydration
|
||||||
|
);
|
||||||
|
});
|
||||||
function EditorView({
|
function EditorView({
|
||||||
session
|
session
|
||||||
}: {
|
}: {
|
||||||
@@ -251,10 +252,14 @@ function EditorView({
|
|||||||
const event = db.eventManager.subscribe(
|
const event = db.eventManager.subscribe(
|
||||||
EVENTS.syncItemMerged,
|
EVENTS.syncItemMerged,
|
||||||
async (item?: MaybeDeletedItem<Item>) => {
|
async (item?: MaybeDeletedItem<Item>) => {
|
||||||
|
const defaultSession = session as DefaultEditorSession;
|
||||||
|
const sessionType = useEditorStore
|
||||||
|
.getState()
|
||||||
|
.getSession(defaultSession.id)?.type;
|
||||||
if (
|
if (
|
||||||
session.type === "new" ||
|
sessionType === "new" ||
|
||||||
!editor ||
|
!editor ||
|
||||||
!session.note ||
|
!defaultSession.note ||
|
||||||
!item ||
|
!item ||
|
||||||
isDeleted(item) ||
|
isDeleted(item) ||
|
||||||
(item.type !== "tiptap" && item.type !== "note") ||
|
(item.type !== "tiptap" && item.type !== "note") ||
|
||||||
@@ -265,8 +270,9 @@ function EditorView({
|
|||||||
}
|
}
|
||||||
|
|
||||||
const isContent =
|
const isContent =
|
||||||
item.type === "tiptap" && item.noteId === session.note.id;
|
item.type === "tiptap" && item.noteId === defaultSession.note.id;
|
||||||
const isNote = item.type === "note" && item.id === session.note.id;
|
const isNote =
|
||||||
|
item.type === "note" && item.id === defaultSession.note.id;
|
||||||
if (isContent && lastChangedTime.current < item.dateModified) {
|
if (isContent && lastChangedTime.current < item.dateModified) {
|
||||||
if (!item.locked) return editor.updateContent(item.data);
|
if (!item.locked) return editor.updateContent(item.data);
|
||||||
|
|
||||||
@@ -275,7 +281,7 @@ function EditorView({
|
|||||||
.catch(() => EV.publish(EVENTS.vaultLocked));
|
.catch(() => EV.publish(EVENTS.vaultLocked));
|
||||||
if (!result) return;
|
if (!result) return;
|
||||||
editor.updateContent(result.data);
|
editor.updateContent(result.data);
|
||||||
} else if (isNote && session.note.title !== item.title) {
|
} else if (isNote && defaultSession.note.title !== item.title) {
|
||||||
AppEventManager.publish(AppEvents.changeNoteTitle, {
|
AppEventManager.publish(AppEvents.changeNoteTitle, {
|
||||||
sessionId: session.id,
|
sessionId: session.id,
|
||||||
title: item.title,
|
title: item.title,
|
||||||
|
|||||||
@@ -910,8 +910,8 @@ class EditorStore extends BaseStore<EditorStore> {
|
|||||||
ignoreEdit?: boolean;
|
ignoreEdit?: boolean;
|
||||||
}
|
}
|
||||||
) => {
|
) => {
|
||||||
const currentSession = this.getSession(id, ["new", "default"]);
|
const session = this.getSession(id, ["new", "default"]);
|
||||||
if (!currentSession) return;
|
if (!session) return;
|
||||||
|
|
||||||
// do not allow saving of readonly session
|
// do not allow saving of readonly session
|
||||||
if (partial.note?.readonly) return;
|
if (partial.note?.readonly) return;
|
||||||
@@ -919,6 +919,13 @@ class EditorStore extends BaseStore<EditorStore> {
|
|||||||
await saveMutex.runExclusive(async () => {
|
await saveMutex.runExclusive(async () => {
|
||||||
this.setSaveState(id, 0);
|
this.setSaveState(id, 0);
|
||||||
try {
|
try {
|
||||||
|
// Get session again as it might have changed to default.
|
||||||
|
const currentSession =
|
||||||
|
session.type === "new"
|
||||||
|
? this.getSession(id, ["new", "default"])
|
||||||
|
: session;
|
||||||
|
|
||||||
|
if (!currentSession) return;
|
||||||
const sessionId = getSessionId(currentSession);
|
const sessionId = getSessionId(currentSession);
|
||||||
let noteId =
|
let noteId =
|
||||||
"note" in currentSession ? currentSession.note.id : partial.note?.id;
|
"note" in currentSession ? currentSession.note.id : partial.note?.id;
|
||||||
@@ -1041,8 +1048,8 @@ class EditorStore extends BaseStore<EditorStore> {
|
|||||||
this.setSaveState(id, SaveState.NotSaved);
|
this.setSaveState(id, SaveState.NotSaved);
|
||||||
console.error(err);
|
console.error(err);
|
||||||
if (err instanceof Error) logger.error(err);
|
if (err instanceof Error) logger.error(err);
|
||||||
if (isLockedSession(currentSession) && "note" in currentSession) {
|
if (isLockedSession(session) && "note" in session) {
|
||||||
this.get().openSession(currentSession.note, { force: true });
|
this.get().openSession(session.note, { force: true });
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
|
|||||||
Reference in New Issue
Block a user