mirror of
https://github.com/streetwriters/notesnook.git
synced 2025-12-21 22:19:41 +01:00
sync: make it work (only upload working)
This commit is contained in:
@@ -62,27 +62,30 @@ export default class Sync {
|
|||||||
}
|
}
|
||||||
|
|
||||||
async _merge({ serverResponse, lastSyncedTimestamp, user }) {
|
async _merge({ serverResponse, lastSyncedTimestamp, user }) {
|
||||||
const { notes, synced, notebooks } = serverResponse;
|
const { notes, synced, notebooks,delta, text } = serverResponse;
|
||||||
|
|
||||||
if (!synced) {
|
if (!synced) {
|
||||||
syncArrayWithDatabase(
|
await syncArrayWithDatabase(
|
||||||
notes,
|
notes,
|
||||||
id => this.db.notes.note(id).data,
|
id => this.db.notes.note(id),
|
||||||
item => this.db.notes.add(item)
|
item => this.db.notes.add(item)
|
||||||
);
|
);
|
||||||
syncArrayWithDatabase(
|
await syncArrayWithDatabase(
|
||||||
notebooks,
|
notebooks,
|
||||||
id => this.db.notebooks.notebook(id).data,
|
id => this.db.notebooks.notebook(id),
|
||||||
item => this.db.notebooks.add(item)
|
item => this.db.notebooks.add(item)
|
||||||
);
|
);
|
||||||
|
|
||||||
["delta", "text"].forEach(type => {
|
await syncArrayWithDatabase(
|
||||||
syncArrayWithDatabase(
|
delta,
|
||||||
serverResponse[type],
|
id => this.db.delta.raw(id),
|
||||||
id => this.db[type].raw(id),
|
item => this.db.delta.add(item)
|
||||||
item => this.db[type].add(item)
|
);
|
||||||
|
await syncArrayWithDatabase(
|
||||||
|
text,
|
||||||
|
id => this.db.text.raw(id),
|
||||||
|
item => this.db.text.add(item)
|
||||||
);
|
);
|
||||||
});
|
|
||||||
}
|
}
|
||||||
// TODO trash, colors, tags
|
// TODO trash, colors, tags
|
||||||
return {
|
return {
|
||||||
@@ -130,7 +133,7 @@ async function syncWithDatabase(remoteItem, get, add) {
|
|||||||
}
|
}
|
||||||
|
|
||||||
async function syncArrayWithDatabase(array, get, set) {
|
async function syncArrayWithDatabase(array, get, set) {
|
||||||
array.forEach(async item => await syncWithDatabase(item, get, set));
|
return Promise.all(array.map(async item => await syncWithDatabase(item, get, set)));
|
||||||
}
|
}
|
||||||
|
|
||||||
function prepareForServer(array, user, lastSyncedTimestamp) {
|
function prepareForServer(array, user, lastSyncedTimestamp) {
|
||||||
|
|||||||
@@ -40,6 +40,10 @@ export default class Note {
|
|||||||
return this._note.notebook;
|
return this._note.notebook;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
get dateEdited() {
|
||||||
|
return this._note.dateEdited;
|
||||||
|
}
|
||||||
|
|
||||||
delta() {
|
delta() {
|
||||||
return this._notes._deltaCollection.get(this._note.content.delta);
|
return this._notes._deltaCollection.get(this._note.content.delta);
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -24,6 +24,10 @@ export default class Notebook {
|
|||||||
return new Topics(this._notebooks, this._notebook.id);
|
return new Topics(this._notebooks, this._notebook.id);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
get dateEdited() {
|
||||||
|
return this._notebook.dateEdited;
|
||||||
|
}
|
||||||
|
|
||||||
_toggle(prop) {
|
_toggle(prop) {
|
||||||
return this._notebooks.add({
|
return this._notebooks.add({
|
||||||
id: this._notebook.id,
|
id: this._notebook.id,
|
||||||
|
|||||||
Reference in New Issue
Block a user