diff --git a/src/main.ts b/src/main.ts index 85eeb74..52a99d1 100644 --- a/src/main.ts +++ b/src/main.ts @@ -31,7 +31,7 @@ export default class BookTrackerPlugin extends Plugin { this.templater = new Templater(this.app); this.storage = new Storage(this.app, this); - this.readingLog = new ReadingLog(this.app, this); + this.readingLog = new ReadingLog(this); this.addCommand({ id: "search-goodreads", diff --git a/src/utils/storage.ts b/src/utils/storage.ts index 0908e50..fa91ed3 100644 --- a/src/utils/storage.ts +++ b/src/utils/storage.ts @@ -37,10 +37,7 @@ export class Storage { export class ReadingLog { private entries: ReadingLogEntry[] = []; - public constructor( - private readonly app: App, - private readonly plugin: BookTrackerPlugin - ) { + public constructor(private readonly plugin: BookTrackerPlugin) { this.loadEntries().catch((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() { + this.sortEntries(); await this.plugin.storage.writeJSON("reading-log.json", this.entries); }