mirror of
https://github.com/streetwriters/notesnook.git
synced 2025-12-23 23:19:40 +01:00
fix: send raw collections
This commit is contained in:
@@ -148,13 +148,13 @@ class Merger {
|
|||||||
|
|
||||||
await this._mergeArray(
|
await this._mergeArray(
|
||||||
tags,
|
tags,
|
||||||
id => this._db.tags.raw(id),
|
id => this._db.tags.tag(id),
|
||||||
item => this._db.tags.merge(item)
|
item => this._db.tags.merge(item)
|
||||||
);
|
);
|
||||||
|
|
||||||
await this._mergeArray(
|
await this._mergeArray(
|
||||||
colors,
|
colors,
|
||||||
id => this._db.colors.raw(id),
|
id => this._db.colors.tag(id),
|
||||||
item => this._db.colors.merge(item)
|
item => this._db.colors.merge(item)
|
||||||
);
|
);
|
||||||
|
|
||||||
@@ -182,20 +182,20 @@ class Prepare {
|
|||||||
async get(lastSyncedTimestamp) {
|
async get(lastSyncedTimestamp) {
|
||||||
this._lastSyncedTimestamp = lastSyncedTimestamp;
|
this._lastSyncedTimestamp = lastSyncedTimestamp;
|
||||||
return {
|
return {
|
||||||
notes: this._prepareForServer(this._db.notes.all),
|
notes: this._prepareForServer(this._db.notes.raw),
|
||||||
notebooks: this._prepareForServer(this._db.notebooks.all),
|
notebooks: this._prepareForServer(this._db.notebooks.raw),
|
||||||
delta: this._prepareForServer(await this._db.delta.all()),
|
delta: this._prepareForServer(await this._db.delta.all()),
|
||||||
text: this._prepareForServer(await this._db.text.all()),
|
text: this._prepareForServer(await this._db.text.all()),
|
||||||
tags: this._prepareForServer(this._db.tags.all),
|
tags: this._prepareForServer(this._db.tags.raw),
|
||||||
colors: this._prepareForServer(this._db.colors.all),
|
colors: this._prepareForServer(this._db.colors.raw),
|
||||||
trash: this._prepareForServer(this._db.trash.all),
|
trash: this._prepareForServer(this._db.trash.raw),
|
||||||
lastSynced: Date.now()
|
lastSynced: Date.now()
|
||||||
};
|
};
|
||||||
}
|
}
|
||||||
|
|
||||||
_prepareForServer(array) {
|
_prepareForServer(array) {
|
||||||
return tfun
|
return tfun
|
||||||
.filter(`.deleted || .dateEdited > ${this._lastSyncedTimestamp}`)
|
.filter(`.deleted === true || .dateEdited > ${this._lastSyncedTimestamp}`)
|
||||||
.map(item => ({
|
.map(item => ({
|
||||||
id: item.id,
|
id: item.id,
|
||||||
dateEdited: item.dateEdited,
|
dateEdited: item.dateEdited,
|
||||||
|
|||||||
@@ -63,6 +63,10 @@ export default class Notebooks {
|
|||||||
return notebook;
|
return notebook;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
get raw() {
|
||||||
|
return this._collection.getRaw();
|
||||||
|
}
|
||||||
|
|
||||||
get all() {
|
get all() {
|
||||||
return sort(this._collection.getAllItems()).desc(t => t.pinned);
|
return sort(this._collection.getAllItems()).desc(t => t.pinned);
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -134,6 +134,10 @@ export default class Notes {
|
|||||||
return new Note(this, note);
|
return new Note(this, note);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
get raw() {
|
||||||
|
return this._collection.getRaw();
|
||||||
|
}
|
||||||
|
|
||||||
get all() {
|
get all() {
|
||||||
return this._collection.getAllItems();
|
return this._collection.getAllItems();
|
||||||
}
|
}
|
||||||
@@ -148,13 +152,13 @@ export default class Notes {
|
|||||||
|
|
||||||
tagged(tag) {
|
tagged(tag) {
|
||||||
return this._tagsCollection
|
return this._tagsCollection
|
||||||
.get(tag)
|
.notes(tag)
|
||||||
.map(id => this._collection.getItem(id));
|
.map(id => this._collection.getItem(id));
|
||||||
}
|
}
|
||||||
|
|
||||||
colored(color) {
|
colored(color) {
|
||||||
return this._colorsCollection
|
return this._colorsCollection
|
||||||
.get(color)
|
.notes(color)
|
||||||
.map(id => this._collection.getItem(id));
|
.map(id => this._collection.getItem(id));
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@@ -12,13 +12,13 @@ export default class Tags {
|
|||||||
return this._collection.init();
|
return this._collection.init();
|
||||||
}
|
}
|
||||||
|
|
||||||
get(tag) {
|
notes(tag) {
|
||||||
const tagItem = this.all.find(t => t.title === tag);
|
const tagItem = this.all.find(t => t.title === tag);
|
||||||
if (!tagItem) return [];
|
if (!tagItem) return [];
|
||||||
return tagItem.noteIds;
|
return tagItem.noteIds;
|
||||||
}
|
}
|
||||||
|
|
||||||
raw(id) {
|
tag(id) {
|
||||||
const tagItem = this.all.find(t => t.id === id);
|
const tagItem = this.all.find(t => t.id === id);
|
||||||
if (!tagItem) return;
|
if (!tagItem) return;
|
||||||
return tagItem;
|
return tagItem;
|
||||||
@@ -55,6 +55,10 @@ export default class Tags {
|
|||||||
await this._collection.addItem(tag);
|
await this._collection.addItem(tag);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
get raw() {
|
||||||
|
return this._collection.getRaw();
|
||||||
|
}
|
||||||
|
|
||||||
get all() {
|
get all() {
|
||||||
return this._collection.getAllItems();
|
return this._collection.getAllItems();
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -35,6 +35,10 @@ export default class Trash {
|
|||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
|
get raw() {
|
||||||
|
return this._collection.getRaw();
|
||||||
|
}
|
||||||
|
|
||||||
get all() {
|
get all() {
|
||||||
return this._collection.getAllItems(u => u.dateDeleted);
|
return this._collection.getAllItems(u => u.dateDeleted);
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -62,10 +62,14 @@ export default class CachedCollection {
|
|||||||
return this.map.get(id);
|
return this.map.get(id);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
getRaw() {
|
||||||
|
return Array.from(this.map.values());
|
||||||
|
}
|
||||||
|
|
||||||
getAllItems(sortFn = u => u.dateCreated) {
|
getAllItems(sortFn = u => u.dateCreated) {
|
||||||
let items = [];
|
let items = [];
|
||||||
this.map.forEach(value => {
|
this.map.forEach(value => {
|
||||||
if (value.deleted) return; // if item is deleted we skip it.
|
if (value.deleted) return;
|
||||||
items[items.length] = value;
|
items[items.length] = value;
|
||||||
});
|
});
|
||||||
return sort(items).desc(sortFn);
|
return sort(items).desc(sortFn);
|
||||||
|
|||||||
Reference in New Issue
Block a user