A fully open source & end-to-end encrypted note taking alternative to Evernote.
TypeScript asp-net-coredotnet-coreelectronfosshacktoberfestnote-managmentnote-takingnote-taking-appnotebooknotesnotes-appopen-sourceopensourceprivacyproductivityreactreact-nativereactjsself-hosted
web: reopen editor session if conflict is resolved/created
Abdullah Atta780e1e9db00c
diff --git a/apps/web/src/components/diff-viewer/index.tsx b/apps/web/src/components/diff-viewer/index.tsxindex 3ed019da1..64ecaef37 100644--- a/apps/web/src/components/diff-viewer/index.tsx+++ b/apps/web/src/components/diff-viewer/index.tsx@@ -331,12 +331,6 @@ async function resolveConflict({toKeepDateEdited: number;dateResolved?: number;}) {- await db.notes.add({- id: note.id,- dateEdited: toKeepDateEdited,- conflicted: false- });-await db.content.add({id: note.contentId,data: toKeep,@@ -345,12 +339,17 @@ async function resolveConflict({sessionId: `${Date.now()}`});+ await db.notes.add({+ id: note.id,+ dateEdited: toKeepDateEdited,+ conflicted: false+ });+if (toCopy) {await createCopy(note, toCopy);}await notesStore.refresh();- useEditorStore.getState().openSession(note.id, { force: true });}async function createCopy(note: Note, content: ContentItem) {diff --git a/apps/web/src/stores/editor-store.ts b/apps/web/src/stores/editor-store.tsindex a377a5fb8..6981533d3 100644--- a/apps/web/src/stores/editor-store.ts+++ b/apps/web/src/stores/editor-store.ts@@ -233,6 +233,15 @@ class EditorStore extends BaseStore<EditorStore> {if (noteId && session.id !== noteId && session.note.id !== noteId)continue;if (isDeleted(item) || isTrashItem(item)) clearIds.push(session.id);+ // if a note becomes conflicted, reopen the session+ else if (+ session.type !== "conflicted" &&+ item.type === "tiptap" &&+ item.conflicted+ )+ waitForSync().then(() =>+ openSession(session.note.id, { force: true, silent: true })+ );// if a note is locked, reopen the sessionelse if (session.type === "default" &&@@ -257,9 +266,7 @@ class EditorStore extends BaseStore<EditorStore> {}// if a deleted note is restored, reopen the sessionelse if (session.type === "deleted" && item.type === "note") {- waitForSync().then(() =>- openSession(session.note.id, { force: true, silent: true })- );+ openSession(session.note.id, { force: true, silent: true });}// if a readonly note is made editable, reopen the sessionelse if (@@ -267,9 +274,7 @@ class EditorStore extends BaseStore<EditorStore> {item.type === "note" &&!item.readonly)- waitForSync().then(() =>- openSession(session.note.id, { force: true, silent: true })- );+ openSession(session.note.id, { force: true, silent: true });// update the note in all sessionselse if (item.type === "note") {updateSession(@@ -344,6 +349,10 @@ class EditorStore extends BaseStore<EditorStore> {session.type !== "new" && session.note.contentId;if (!contentId || !event.ids.includes(contentId)) continue;if (+ // if note's conflict is resolved+ (session.type === "conflicted" && !event.item.conflicted) ||+ // if note becomes conflicted+ (session.type !== "conflicted" && event.item.conflicted) ||// if note is locked(session.type === "default" &&!session.locked &&@@ -548,12 +557,14 @@ class EditorStore extends BaseStore<EditorStore> {const noteId = typeof noteOrId === "string" ? noteOrId : noteOrId.id;const session = getSession(noteId);- if (session && !options.force && !session.needsHydration) {- return this.activateSession(noteId, options.activeBlockId);- }+ if (session && !options.force) {+ if (!session.needsHydration) {+ return this.activateSession(noteId, options.activeBlockId);+ }- if (session && (session.type === "diff" || session.type === "conflicted")) {- return openDiffSession(session.note.id, session.id);+ if (session.type === "diff" || session.type === "conflicted") {+ return openDiffSession(session.note.id, session.id);+ }}if (session && session.id) await db.fs().cancel(session.id);@@ -566,19 +577,7 @@ class EditorStore extends BaseStore<EditorStore> {const isPreview = session ? session.preview : !options?.newSession;const isLocked = await db.vaults.itemExists(note);- if (isLocked && note.type !== "trash") {- this.addSession(- {- type: "locked",- id: note.id,- pinned: session?.pinned,- note,- preview: isPreview,- activeBlockId: options.activeBlockId- },- !options.silent- );- } else if (note.conflicted) {+ if (note.conflicted) {const content = note.contentId? await db.content.get(note.contentId): undefined;@@ -612,6 +611,18 @@ class EditorStore extends BaseStore<EditorStore> {},!options.silent);+ } else if (isLocked && note.type !== "trash") {+ this.addSession(+ {+ type: "locked",+ id: note.id,+ pinned: session?.pinned,+ note,+ preview: isPreview,+ activeBlockId: options.activeBlockId+ },+ !options.silent+ );} else {const content = note.contentId? await db.content.get(note.contentId)