fix: make conflict resolution work again

This commit is contained in:
thecodrr
2020-12-08 14:56:42 +05:00
parent 50810dc2f8
commit 754640343c
6 changed files with 38 additions and 40 deletions

View File

@@ -174,7 +174,8 @@ export default class ReactQuill extends Component {
}
textChangeHandler = (_delta, _oldDelta, source) => {
this.props.onWordCountChanged(this.getWordCount());
if (this.props.onWordCountChanged)
this.props.onWordCountChanged(this.getWordCount());
if (source === "init") return;
clearTimeout(this.changeTimeout);
this.changeTimeout = setTimeout(

View File

@@ -27,7 +27,9 @@ function menuItems(note, context) {
{
title: "Add to notebook",
onClick: async () => {
await showMoveNoteDialog([note.id]);
if (await showMoveNoteDialog([note.id])) {
store.refresh();
}
},
},
{
@@ -197,8 +199,9 @@ function Note(props) {
{note.conflicted && (
<Text
ml={1}
p={1}
px={"3px"}
bg="error"
fontSize="subBody"
color="static"
sx={{ borderRadius: "default" }}
>

View File

@@ -23,18 +23,21 @@ function DeltaToggle(props) {
const resolveConflict = useCallback(
async (selectedContent, otherContent) => {
selectedContent.delta = {
data: { ops: selectedContent.delta },
selectedContent = {
data: selectedContent,
type: "delta",
resolved: true,
};
await db.notes.add({
id: note.id,
content: selectedContent,
conflicted: false,
});
if (otherContent) {
otherContent.delta = {
data: { ops: otherContent.delta },
otherContent = {
data: otherContent,
type: "delta",
};
await db.notes.add({
...note,
@@ -62,20 +65,12 @@ function DeltaToggle(props) {
onClick={async () => {
const { selectedEditor, otherEditor } = editors();
await resolveConflict(
{
delta: deltaTransformer.cleanDifference(
selectedEditor.getContents()
),
text: selectedEditor.getText(),
},
{
delta: deltaTransformer.cleanDifference(
otherEditor.getContents()
),
text: otherEditor.getText(),
}
deltaTransformer.cleanDifference(selectedEditor.getContents()),
deltaTransformer.cleanDifference(otherEditor.getContents())
);
}}
p={1}
px={2}
>
Save copy
</Button>
@@ -85,16 +80,15 @@ function DeltaToggle(props) {
onClick={async () => {
if (isOtherSelected) {
const { selectedEditor } = editors();
await resolveConflict({
delta: deltaTransformer.cleanDifference(
selectedEditor.getContents()
),
text: selectedEditor.getText(),
});
await resolveConflict(
deltaTransformer.cleanDifference(selectedEditor.getContents())
);
} else {
onToggle();
}
}}
p={1}
px={2}
bg={isOtherSelected ? "error" : "primary"}
>
{isSelected ? "Undo" : isOtherSelected ? "Discard" : "Keep"}

View File

@@ -25,7 +25,7 @@ function SplitEditor(props) {
notesStore.setSelectedNote(diffId);
note = note.data;
(async function () {
const delta = await db.delta.raw(note.content.delta);
const delta = await db.content.raw(note.contentId);
setConflictedNote(note);
setLocalDelta({ ...delta, conflicted: false });
setRemoteDelta(delta.conflicted);
@@ -94,6 +94,7 @@ function SplitEditor(props) {
width="50%"
flex="1 1 auto"
sx={{ borderRight: "1px solid", borderColor: "border" }}
px={2}
>
<SimpleEditor
pref={localEditor}
@@ -106,7 +107,7 @@ function SplitEditor(props) {
)}
/>
</Box>
<Box className="secondEditor" flex="1 1 auto" width="50%">
<Box className="secondEditor" flex="1 1 auto" width="50%" px={2}>
<SimpleEditor
pref={remoteEditor}
container=".secondEditor"

View File

@@ -13,25 +13,13 @@ class NoteStore extends BaseStore {
context = undefined;
selectedNote = 0;
init = async () => {
init = () => {
EV.subscribe("notes:removeEmptyNote", (id) => {
const { session, newSession } = editorStore.get();
if (session.id === id) {
newSession();
}
});
/* const note = db.notes.note("b2ce3a6053afab9cb1d8012d").data;
const delta = await db.delta.raw(note.content.delta);
const note2 = db.notes.note("b2f68f306c560dab97aa196a").data;
const delta2 = await db.delta.raw(note2.content.delta);
const delta3 = { ...delta, conflicted: delta2 };
await db.delta.add(delta3);
await db.notes.add({ id: note.id, conflicted: true, resolved: false });
console.log(delta3); */
};
setSelectedNote = (id) => {

View File

@@ -11,6 +11,17 @@ function Home() {
(async function () {
await db.notes.init();
store.refresh();
// const note = db.notes.note("7180399cb8ea4b7dfa015a0f").data;
// const delta = await db.content.raw(note.contentId);
// const note2 = db.notes.note("f85150f4a3850fb44dc65569").data;
// const delta2 = await db.content.raw(note2.contentId);
// const delta3 = { ...delta, conflicted: delta2 };
// await db.content.add(delta3);
// await db.notes.add({ id: note.id, conflicted: true, resolved: false });
// console.log(delta3);
setIsLoading(false);
})();
}, []);