Skip to content

A fully open source & end-to-end encrypted note taking alternative to Evernote.

fix: sort everything by dateCreated descending

thecodrr8eb590f9d29f
diff --git a/packages/core/collections/notes.js b/packages/core/collections/notes.js
index b819c0a6d..d5985e049 100644
--- a/packages/core/collections/notes.js
+++ b/packages/core/collections/notes.js
@@ -11,6 +11,7 @@ import getId from "../utils/id";
import { EV, EVENTS } from "../common";
import { getContentFromData } from "../content-types";
import qclone from "qclone/src/qclone";
+import sort from "fast-sort";
export default class Notes extends Collection {
async add(noteArg) {
@@ -158,11 +159,12 @@ export default class Notes extends Collection {
_getTagItems(tagId, collection) {
const tag = this._db[collection].tag(tagId);
if (!tag || tag.noteIds.length <= 0) return [];
- return tag.noteIds.reduce((arr, id) => {
+ const array = tag.noteIds.reduce((arr, id) => {
const item = this._collection.getItem(id);
if (item) arr.push(item);
return arr;
}, []);
+ return sort(array).desc((note) => note.dateCreated);
}
/**
diff --git a/packages/core/collections/topics.js b/packages/core/collections/topics.js
index 30b3c8416..20a8c585a 100644
--- a/packages/core/collections/topics.js
+++ b/packages/core/collections/topics.js
@@ -1,6 +1,7 @@
import Topic from "../models/topic";
import { qclone } from "qclone";
import id from "../utils/id";
+import sort from "fast-sort";
export default class Topics {
/**
@@ -74,7 +75,9 @@ export default class Topics {
* @returns {Array} an array containing all the topics
*/
get all() {
- return this._db.notebooks.notebook(this._notebookId).data.topics;
+ return sort(this._db.notebooks.notebook(this._notebookId).data.topics).desc(
+ (topic) => topic.dateCreated
+ );
}
/**
diff --git a/packages/core/collections/trash.js b/packages/core/collections/trash.js
index 4d70ddc3b..81e7f8411 100644
--- a/packages/core/collections/trash.js
+++ b/packages/core/collections/trash.js
@@ -1,5 +1,4 @@
-import Collection from "./collection";
-import getId from "../utils/id";
+import sort from "fast-sort";
import { get7DayTimestamp } from "../utils/date";
export default class Trash {
@@ -14,10 +13,6 @@ export default class Trash {
notebooks: db.notebooks,
};
}
- // async init() {
- // await super.init();
- // await this.cleanup();
- // }
async init() {
await this.cleanup();
@@ -38,7 +33,7 @@ export default class Trash {
const collection = this.collections[key];
trashItems.push(...collection.deleted);
}
- return trashItems;
+ return sort(trashItems).desc((item) => item.dateDeleted);
}
_getItem(id) {
diff --git a/packages/core/database/cached-collection.js b/packages/core/database/cached-collection.js
index 0c3ecbc08..4559e2df5 100644
--- a/packages/core/database/cached-collection.js
+++ b/packages/core/database/cached-collection.js
@@ -1,6 +1,4 @@
-import Indexer from "./indexer";
import sort from "fast-sort";
-import { EV, EVENTS } from "../common";
import IndexedCollection from "./indexed-collection";
export default class CachedCollection extends IndexedCollection {
diff --git a/packages/core/models/topic.js b/packages/core/models/topic.js
index 7c9fac910..298a9eacf 100644
--- a/packages/core/models/topic.js
+++ b/packages/core/models/topic.js
@@ -1,4 +1,6 @@
import { qclone } from "qclone";
+import sort from "fast-sort";
+
export default class Topic {
/**
* @param {Object} topic
@@ -83,11 +85,11 @@ export default class Topic {
}
get all() {
- return this._topic.notes
- .map((note) => {
- let fullNote = this._db.notes.note(note);
- if (fullNote) return fullNote.data;
- })
- .filter((v) => v);
+ const notes = this._topic.notes.reduce((arr, noteId) => {
+ let note = this._db.notes.note(noteId);
+ if (note) arr.push(note.data);
+ return arr;
+ }, []);
+ return sort(notes).desc((note) => note.dateCreated);
}
}