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.storage = new Storage(this.app, this);
 | 
			
		||||
		this.readingLog = new ReadingLog(this.app, this);
 | 
			
		||||
		this.readingLog = new ReadingLog(this);
 | 
			
		||||
 | 
			
		||||
		this.addCommand({
 | 
			
		||||
			id: "search-goodreads",
 | 
			
		||||
| 
						 | 
				
			
			
 | 
			
		|||
| 
						 | 
				
			
			@ -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);
 | 
			
		||||
	}
 | 
			
		||||
 | 
			
		||||
| 
						 | 
				
			
			
 | 
			
		|||
		Loading…
	
		Reference in New Issue