fix: sort everything by dateCreated descending

This commit is contained in:
thecodrr
2021-02-27 11:55:13 +05:00
parent bb41b8c9cb
commit 8eb590f9d2
5 changed files with 17 additions and 17 deletions

View File

@@ -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);
}
/**

View File

@@ -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
);
}
/**

View File

@@ -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) {

View File

@@ -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 {

View File

@@ -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);
}
}