generated from tpl/obsidian-sample-plugin
Sort entries before storing
This commit is contained in:
parent
bd21890885
commit
976fe482b4
|
@ -31,7 +31,7 @@ export default class BookTrackerPlugin extends Plugin {
|
||||||
|
|
||||||
this.templater = new Templater(this.app);
|
this.templater = new Templater(this.app);
|
||||||
this.storage = new Storage(this.app, this);
|
this.storage = new Storage(this.app, this);
|
||||||
this.readingLog = new ReadingLog(this.app, this);
|
this.readingLog = new ReadingLog(this);
|
||||||
|
|
||||||
this.addCommand({
|
this.addCommand({
|
||||||
id: "search-goodreads",
|
id: "search-goodreads",
|
||||||
|
|
|
@ -37,10 +37,7 @@ export class Storage {
|
||||||
export class ReadingLog {
|
export class ReadingLog {
|
||||||
private entries: ReadingLogEntry[] = [];
|
private entries: ReadingLogEntry[] = [];
|
||||||
|
|
||||||
public constructor(
|
public constructor(private readonly plugin: BookTrackerPlugin) {
|
||||||
private readonly app: App,
|
|
||||||
private readonly plugin: BookTrackerPlugin
|
|
||||||
) {
|
|
||||||
this.loadEntries().catch((error) => {
|
this.loadEntries().catch((error) => {
|
||||||
console.error("Failed to load reading log entries:", error);
|
console.error("Failed to load reading log entries:", error);
|
||||||
});
|
});
|
||||||
|
@ -58,7 +55,14 @@ export class ReadingLog {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
private sortEntries() {
|
||||||
|
this.entries = this.entries.sort(
|
||||||
|
(a, b) => b.createdAt.getTime() - a.createdAt.getTime()
|
||||||
|
);
|
||||||
|
}
|
||||||
|
|
||||||
private async storeEntries() {
|
private async storeEntries() {
|
||||||
|
this.sortEntries();
|
||||||
await this.plugin.storage.writeJSON("reading-log.json", this.entries);
|
await this.plugin.storage.writeJSON("reading-log.json", this.entries);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
Loading…
Reference in New Issue