mirror of
https://github.com/streetwriters/notesnook.git
synced 2025-12-24 23:49:33 +01:00
fix: recursive conflicts when keeping local note
This commit is contained in:
@@ -10,8 +10,6 @@ function ContentToggle(props) {
|
||||
sx,
|
||||
label,
|
||||
dateEdited,
|
||||
editors,
|
||||
cleanDiff,
|
||||
resolveConflict,
|
||||
} = props;
|
||||
|
||||
@@ -22,16 +20,7 @@ function ContentToggle(props) {
|
||||
<Button
|
||||
variant="primary"
|
||||
mr={2}
|
||||
onClick={async () => {
|
||||
const { selectedEditor, otherEditor } = editors;
|
||||
await resolveConflict(
|
||||
await cleanDiff(
|
||||
document.getElementById(selectedEditor).innerHTML
|
||||
),
|
||||
await cleanDiff(document.getElementById(otherEditor).innerHTML),
|
||||
dateEdited
|
||||
);
|
||||
}}
|
||||
onClick={() => resolveConflict({ saveCopy: true })}
|
||||
p={1}
|
||||
px={2}
|
||||
>
|
||||
@@ -40,17 +29,9 @@ function ContentToggle(props) {
|
||||
)}
|
||||
<Button
|
||||
variant="primary"
|
||||
onClick={async () => {
|
||||
console.log("isOtherSelected", isOtherSelected);
|
||||
onClick={() => {
|
||||
if (isOtherSelected) {
|
||||
const { selectedEditor } = editors;
|
||||
await resolveConflict(
|
||||
await cleanDiff(
|
||||
document.getElementById(selectedEditor).innerHTML
|
||||
),
|
||||
null,
|
||||
dateEdited
|
||||
);
|
||||
resolveConflict({ saveCopy: false });
|
||||
} else {
|
||||
onToggle();
|
||||
}
|
||||
|
||||
@@ -49,33 +49,39 @@ function DiffViewer(props) {
|
||||
const [htmlDiff, setHtmlDiff] = useState({});
|
||||
|
||||
const resolveConflict = useCallback(
|
||||
async (selectedContent, otherContent, selectedContentDateEdited) => {
|
||||
async ({ toKeep, toCopy, toKeepDateEdited, dateResolved }) => {
|
||||
if (!conflictedNote) return;
|
||||
|
||||
selectedContent = {
|
||||
data: selectedContent,
|
||||
toKeep = await differ.clean(toKeep);
|
||||
if (toCopy) toCopy = await differ.clean(toCopy);
|
||||
|
||||
const toKeepContent = {
|
||||
data: toKeep,
|
||||
type: "tiny",
|
||||
// HACK: we need to set remote = true so the database doesn't
|
||||
// overwrite the dateEdited of the content.
|
||||
remote: true,
|
||||
dateEdited: selectedContentDateEdited,
|
||||
dateEdited: toKeepDateEdited,
|
||||
dateResolved,
|
||||
};
|
||||
|
||||
await db.notes.add({
|
||||
id: conflictedNote.id,
|
||||
content: selectedContent,
|
||||
content: toKeepContent,
|
||||
conflicted: false,
|
||||
});
|
||||
if (otherContent) {
|
||||
otherContent = {
|
||||
data: otherContent,
|
||||
|
||||
if (toCopy) {
|
||||
const toCopyContent = {
|
||||
data: toCopy,
|
||||
type: "tiny",
|
||||
};
|
||||
await db.notes.add({
|
||||
content: otherContent,
|
||||
content: toCopyContent,
|
||||
title: conflictedNote.title + " (COPY)",
|
||||
});
|
||||
}
|
||||
|
||||
notesStore.refresh();
|
||||
hashNavigate(`/notes/${conflictedNote.id}/edit`, { replace: true });
|
||||
|
||||
@@ -105,7 +111,11 @@ function DiffViewer(props) {
|
||||
note = note.data;
|
||||
|
||||
const content = await db.content.raw(note.contentId);
|
||||
if (!content.conflicted) return resolveConflict(note, content.data);
|
||||
if (!content.conflicted)
|
||||
return resolveConflict({
|
||||
toKeep: content.data,
|
||||
dateEdited: content.dateEdited,
|
||||
});
|
||||
|
||||
setConflictedNote(note);
|
||||
setLocalContent({ ...content, conflicted: false });
|
||||
@@ -206,15 +216,17 @@ function DiffViewer(props) {
|
||||
>
|
||||
<ContentToggle
|
||||
label="Current note"
|
||||
resolveConflict={resolveConflict}
|
||||
dateEdited={localContent.dateEdited}
|
||||
isSelected={selectedContent === 0}
|
||||
isOtherSelected={selectedContent === 1}
|
||||
onToggle={() => setSelectedContent((s) => (s === 0 ? -1 : 0))}
|
||||
cleanDiff={async (html) => await differ.clean(html)}
|
||||
editors={{
|
||||
selectedEditor: "diffViewAfter",
|
||||
otherEditor: "diffViewBefore",
|
||||
resolveConflict={({ saveCopy }) => {
|
||||
resolveConflict({
|
||||
toKeep: htmlDiff.after,
|
||||
toCopy: saveCopy ? htmlDiff.before : null,
|
||||
toKeepDateEdited: localContent.dateEdited,
|
||||
dateResolved: remoteContent.dateEdited,
|
||||
});
|
||||
}}
|
||||
sx={{
|
||||
borderStyle: "solid",
|
||||
@@ -250,6 +262,19 @@ function DiffViewer(props) {
|
||||
width={["100%", "100%", "50%"]}
|
||||
>
|
||||
<ContentToggle
|
||||
resolveConflict={({ saveCopy }) => {
|
||||
resolveConflict({
|
||||
toKeep: htmlDiff.before,
|
||||
toCopy: saveCopy ? htmlDiff.after : null,
|
||||
toKeepDateEdited: remoteContent.dateEdited,
|
||||
dateResolved: remoteContent.dateEdited,
|
||||
});
|
||||
}}
|
||||
label="Incoming note"
|
||||
isSelected={selectedContent === 1}
|
||||
isOtherSelected={selectedContent === 0}
|
||||
dateEdited={remoteContent.dateEdited}
|
||||
onToggle={() => setSelectedContent((s) => (s === 1 ? -1 : 1))}
|
||||
sx={{
|
||||
alignItems: "flex-end",
|
||||
borderStyle: "solid",
|
||||
@@ -260,17 +285,6 @@ function DiffViewer(props) {
|
||||
pb: 1,
|
||||
pt: [1, 1, 0],
|
||||
}}
|
||||
resolveConflict={resolveConflict}
|
||||
label="Incoming note"
|
||||
isSelected={selectedContent === 1}
|
||||
isOtherSelected={selectedContent === 0}
|
||||
dateEdited={remoteContent.dateEdited}
|
||||
onToggle={() => setSelectedContent((s) => (s === 1 ? -1 : 1))}
|
||||
cleanDiff={async (html) => await differ.clean(html)}
|
||||
editors={{
|
||||
selectedEditor: "diffViewBefore",
|
||||
otherEditor: "diffViewAfter",
|
||||
}}
|
||||
/>
|
||||
<ScrollSyncPane>
|
||||
<Box
|
||||
|
||||
@@ -1924,7 +1924,7 @@
|
||||
fastq "^1.6.0"
|
||||
|
||||
"@notesnook/desktop@./desktop/":
|
||||
version "1.4.2"
|
||||
version "1.5.0"
|
||||
dependencies:
|
||||
diary "^0.1.6"
|
||||
electron-better-ipc "^2.0.1"
|
||||
@@ -8636,9 +8636,22 @@ normalize-url@^3.0.0:
|
||||
resolved "https://registry.npmjs.org/normalize-url/-/normalize-url-3.3.0.tgz"
|
||||
integrity sha512-U+JJi7duF1o+u2pynbp2zXDW2/PADgC30f0GsHZtRh+HOcXHnw137TrNlyxxRvWW5fjKd3bcLHPxofWuCjaeZg==
|
||||
|
||||
notes-core@../notesnook-core/:
|
||||
version "6.8.2"
|
||||
dependencies:
|
||||
"@stablelib/blake2s" "^1.0.1"
|
||||
dayjs "^1.10.6"
|
||||
fast-sort "^2.0.1"
|
||||
lean-he "^2.1.2"
|
||||
no-internet "^1.5.2"
|
||||
qclone "^1.0.4"
|
||||
quill-delta-to-html "^0.12.0"
|
||||
showdown "https://github.com/thecodrr/showdown"
|
||||
spark-md5 "^3.0.1"
|
||||
|
||||
"notes-core@git+https://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:x-oauth-basic@github.com/streetwriters/notesnook-core.git":
|
||||
version "6.8.1"
|
||||
resolved "git+https://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:x-oauth-basic@github.com/streetwriters/notesnook-core.git#3cc1b4cbd028f04861e53dbb8b35418d26624b7e"
|
||||
version "6.8.2"
|
||||
resolved "git+https://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:x-oauth-basic@github.com/streetwriters/notesnook-core.git#9f6479b5fc5375b74e58fb8b731085f4709eaa48"
|
||||
dependencies:
|
||||
"@stablelib/blake2s" "^1.0.1"
|
||||
dayjs "^1.10.6"
|
||||
|
||||
Reference in New Issue
Block a user