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
fix: use selected content's dateEdited on conflict resolve
thecodrre408d95b6cb5
diff --git a/apps/web/src/components/diff-viewer/content-toggle.js b/apps/web/src/components/diff-viewer/content-toggle.jsindex 77dcb74bd..4ab4648f1 100644--- a/apps/web/src/components/diff-viewer/content-toggle.js+++ b/apps/web/src/components/diff-viewer/content-toggle.js@@ -28,7 +28,8 @@ function ContentToggle(props) {await cleanDiff(document.getElementById(selectedEditor).innerHTML),- await cleanDiff(document.getElementById(otherEditor).innerHTML)+ await cleanDiff(document.getElementById(otherEditor).innerHTML),+ dateEdited);}}p={1}@@ -43,17 +44,12 @@ function ContentToggle(props) {console.log("isOtherSelected", isOtherSelected);if (isOtherSelected) {const { selectedEditor } = editors;- console.log(- selectedEditor,- document.getElementById(selectedEditor).innerHTML,- await cleanDiff(- document.getElementById(selectedEditor).innerHTML- )- );await resolveConflict(await cleanDiff(document.getElementById(selectedEditor).innerHTML- )+ ),+ null,+ dateEdited);} else {onToggle();diff --git a/apps/web/src/components/diff-viewer/index.js b/apps/web/src/components/diff-viewer/index.jsindex 66b8c9720..89aedf451 100644--- a/apps/web/src/components/diff-viewer/index.js+++ b/apps/web/src/components/diff-viewer/index.js@@ -49,17 +49,20 @@ function DiffViewer(props) {const [htmlDiff, setHtmlDiff] = useState({});const resolveConflict = useCallback(- async (note, selectedContent, otherContent) => {- if (!note) return;+ async (selectedContent, otherContent, selectedContentDateEdited) => {+ if (!conflictedNote) return;selectedContent = {data: selectedContent,type: "tiny",- resolved: true,+ // HACK: we need to set remote = true so the database doesn't+ // overwrite the dateEdited of the content.+ remote: true,+ dateEdited: selectedContentDateEdited,};await db.notes.add({- id: note.id,+ id: conflictedNote.id,content: selectedContent,conflicted: false,});@@ -69,17 +72,12 @@ function DiffViewer(props) {type: "tiny",};await db.notes.add({- ...note,content: otherContent,- id: undefined,- dateCreated: undefined,- dateEdited: undefined,- conflicted: false,- title: note.title + " (DUPLICATE)",+ title: conflictedNote.title + " (COPY)",});}notesStore.refresh();- hashNavigate(`/notes/${note.id}/edit`, { replace: true });+ hashNavigate(`/notes/${conflictedNote.id}/edit`, { replace: true });const conflictsCount = db.notes.conflicted?.length;if (conflictsCount) {@@ -92,7 +90,7 @@ function DiffViewer(props) {await sync();}},- [sync]+ [conflictedNote, sync]);useEffect(() => {@@ -208,7 +206,7 @@ function DiffViewer(props) {><ContentTogglelabel="Current note"- resolveConflict={(data) => resolveConflict(conflictedNote, data)}+ resolveConflict={resolveConflict}dateEdited={localContent.dateEdited}isSelected={selectedContent === 0}isOtherSelected={selectedContent === 1}@@ -262,7 +260,7 @@ function DiffViewer(props) {pb: 1,pt: [1, 1, 0],}}- resolveConflict={(data) => resolveConflict(conflictedNote, data)}+ resolveConflict={resolveConflict}label="Incoming note"isSelected={selectedContent === 1}isOtherSelected={selectedContent === 0}diff --git a/apps/web/src/stores/app-store.js b/apps/web/src/stores/app-store.jsindex c729ed70e..b86924f6d 100644--- a/apps/web/src/stores/app-store.js+++ b/apps/web/src/stores/app-store.js@@ -4,6 +4,7 @@ import { store as noteStore } from "./note-store";import { store as notebookStore } from "./notebook-store";import { store as trashStore } from "./trash-store";import { store as tagStore } from "./tag-store";+import { store as editorstore } from "./editor-store";import BaseStore from "./index";import { showToast } from "../utils/toast";import { resetReminders } from "../common/reminders";@@ -136,7 +137,11 @@ class AppStore extends BaseStore {.catch(async (err) => {showToast("error", err.message);console.error(err);- if (err.code === "MERGE_CONFLICT") await this.refresh();+ if (err.code === "MERGE_CONFLICT") {+ if (editorstore.get().session.id)+ editorstore.openSession(editorstore.get().session.id, true);+ await this.refresh();+ }}).finally(() => {this.set((state) => (state.isSyncing = false));