From 59760313c9da3aea3c7d5c0c66b8a56e8912f58c Mon Sep 17 00:00:00 2001 From: dartungar Date: Fri, 5 Apr 2024 23:13:30 +0400 Subject: [PATCH] fix critical bug that caused plugin freeze if there was empty noteset --- main.ts | 2 +- manifest.json | 2 +- src/UI/noteset/noteSetEditModal.ts | 2 +- src/UI/settingsTab.ts | 2 +- src/UI/sidebar/sidebarView.ts | 2 +- src/noteSet/noteSetService.ts | 15 --------------- src/queues/reviewService.ts | 9 +++++---- 7 files changed, 10 insertions(+), 24 deletions(-) diff --git a/main.ts b/main.ts index 4fee281..4f98b1f 100644 --- a/main.ts +++ b/main.ts @@ -121,7 +121,7 @@ export default class SimpleNoteReviewPlugin extends Plugin { id: "reset-queue", name: "reset queue for the current note set", callback: () => { - this.reviewService.resetNotesetQueue( + this.reviewService.resetNotesetQueueWithValidation( this.settings.currentNoteSetId ); }, diff --git a/manifest.json b/manifest.json index 4117fc3..56da27d 100644 --- a/manifest.json +++ b/manifest.json @@ -1,7 +1,7 @@ { "id": "simple-note-review", "name": "Simple Note Review", - "version": "1.2.5", + "version": "1.2.6", "minAppVersion": "1.1.0", "description": "Simple, customizable plugin for easy note review, resurfacing & repetition.", "author": "dartungar", diff --git a/src/UI/noteset/noteSetEditModal.ts b/src/UI/noteset/noteSetEditModal.ts index a5be128..9e33fd4 100644 --- a/src/UI/noteset/noteSetEditModal.ts +++ b/src/UI/noteset/noteSetEditModal.ts @@ -154,7 +154,7 @@ export class NoteSetEditModal extends Modal { } }); this._plugin.noteSetService.validateRulesAndSave(this._noteSet); - this._plugin.reviewService.resetNotesetQueue(this._noteSet.id); + this._plugin.reviewService.resetNotesetQueueWithValidation(this._noteSet.id); this._plugin.noteSetService.updateNoteSetDisplayNameAndDescription(this._noteSet); this._plugin.noteSetService.updateNoteSetStats(this._noteSet); await this._plugin.saveSettings(); diff --git a/src/UI/settingsTab.ts b/src/UI/settingsTab.ts index 054031c..4673e1a 100644 --- a/src/UI/settingsTab.ts +++ b/src/UI/settingsTab.ts @@ -111,7 +111,7 @@ export class SimpleNoteReviewPluginSettingsTab extends PluginSettingTab { .setTooltip("Reset review queue and update stats for this note set") .onClick(async () => { await this._plugin.noteSetService.validateRulesAndSave(noteSet); - await this._plugin.reviewService.resetNotesetQueue(noteSet.id); + await this._plugin.reviewService.resetNotesetQueueWithValidation(noteSet.id); await this._plugin.noteSetService.updateNoteSetStats(noteSet); this.display(); } diff --git a/src/UI/sidebar/sidebarView.ts b/src/UI/sidebar/sidebarView.ts index 2ed85fa..c8c77fb 100644 --- a/src/UI/sidebar/sidebarView.ts +++ b/src/UI/sidebar/sidebarView.ts @@ -197,7 +197,7 @@ export class SimpleNoteReviewSidebarView extends ItemView { .setTooltip("reset review queue for this note set") .onClick(async () => { await this._plugin.noteSetService.validateRulesAndSave(noteSet); - await this._plugin.reviewService.resetNotesetQueue(noteSet.id); + await this._plugin.reviewService.resetNotesetQueueWithValidation(noteSet.id); await this.renderView(); } ); diff --git a/src/noteSet/noteSetService.ts b/src/noteSet/noteSetService.ts index c003c63..2acede2 100644 --- a/src/noteSet/noteSetService.ts +++ b/src/noteSet/noteSetService.ts @@ -107,8 +107,6 @@ export class NoteSetService { public async validateRulesAndSave(noteSet: INoteSet): Promise { const validationErrors = await this.getValidationErrors(noteSet); noteSet.validationErrors = validationErrors; - - this.fixQueueEmptyError(noteSet); await this.saveNoteSet(noteSet); } @@ -147,17 +145,4 @@ export class NoteSetService { } return errors; } - - private async fixQueueEmptyError(noteSet: INoteSet): Promise { - if ( - noteSet.validationErrors.contains( - NotesetValidationErrors.QueueEmpty - ) && - !noteSet.validationErrors.contains( - NotesetValidationErrors.RulesDoNotMatchAnyNotes - ) - ) { - await this._plugin.reviewService.resetNotesetQueue(noteSet.id); - } - } } diff --git a/src/queues/reviewService.ts b/src/queues/reviewService.ts index 21b36c6..8d3bc5b 100644 --- a/src/queues/reviewService.ts +++ b/src/queues/reviewService.ts @@ -18,9 +18,9 @@ export class ReviewService { await this.openNextNoteInQueue(noteset); } - public async resetNotesetQueue(noteSetId: string): Promise { + public async resetNotesetQueueWithValidation(noteSetId: string): Promise { const noteset = this._plugin.noteSetService.getNoteSet(noteSetId); - await this.createNotesetQueue(noteset); + await this.createNotesetQueueWithValidation(noteset); } /** Mark note as reviewed today. If setting "open next note in noteSet after reviewing" is enabled, @@ -108,7 +108,7 @@ export class ReviewService { await leaf.openFile(abstractFile as TFile); } - private async createNotesetQueue(noteSet: INoteSet): Promise { + private async createNotesetQueueWithValidation(noteSet: INoteSet): Promise { const files = await this.generateNotesetQueue(noteSet); noteSet.queue = new NoteQueue(files); await this._plugin.noteSetService.validateRulesAndSave(noteSet); @@ -120,6 +120,7 @@ export class ReviewService { } } + private async createNotesetQueueIfNotExists( noteSet: INoteSet ): Promise { @@ -128,7 +129,7 @@ export class ReviewService { !noteSet.queue?.filenames?.length || noteSet.queue.filenames.length === 0 ) { - await this.createNotesetQueue(noteSet); + await this.createNotesetQueueWithValidation(noteSet); } }