Skip to content

Commit

Permalink
fix critical bug that caused plugin freeze if there was empty noteset
Browse files Browse the repository at this point in the history
  • Loading branch information
dartungar committed Apr 5, 2024
1 parent 376bc34 commit 5976031
Show file tree
Hide file tree
Showing 7 changed files with 10 additions and 24 deletions.
2 changes: 1 addition & 1 deletion main.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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
);
},
Expand Down
2 changes: 1 addition & 1 deletion manifest.json
Original file line number Diff line number Diff line change
@@ -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",
Expand Down
2 changes: 1 addition & 1 deletion src/UI/noteset/noteSetEditModal.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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();
Expand Down
2 changes: 1 addition & 1 deletion src/UI/settingsTab.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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();
}
Expand Down
2 changes: 1 addition & 1 deletion src/UI/sidebar/sidebarView.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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();
}
);
Expand Down
15 changes: 0 additions & 15 deletions src/noteSet/noteSetService.ts
Original file line number Diff line number Diff line change
Expand Up @@ -107,8 +107,6 @@ export class NoteSetService {
public async validateRulesAndSave(noteSet: INoteSet): Promise<void> {
const validationErrors = await this.getValidationErrors(noteSet);
noteSet.validationErrors = validationErrors;

this.fixQueueEmptyError(noteSet);
await this.saveNoteSet(noteSet);
}

Expand Down Expand Up @@ -147,17 +145,4 @@ export class NoteSetService {
}
return errors;
}

private async fixQueueEmptyError(noteSet: INoteSet): Promise<void> {
if (
noteSet.validationErrors.contains(
NotesetValidationErrors.QueueEmpty
) &&
!noteSet.validationErrors.contains(
NotesetValidationErrors.RulesDoNotMatchAnyNotes
)
) {
await this._plugin.reviewService.resetNotesetQueue(noteSet.id);
}
}
}
9 changes: 5 additions & 4 deletions src/queues/reviewService.ts
Original file line number Diff line number Diff line change
Expand Up @@ -18,9 +18,9 @@ export class ReviewService {
await this.openNextNoteInQueue(noteset);
}

public async resetNotesetQueue(noteSetId: string): Promise<void> {
public async resetNotesetQueueWithValidation(noteSetId: string): Promise<void> {
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,
Expand Down Expand Up @@ -108,7 +108,7 @@ export class ReviewService {
await leaf.openFile(abstractFile as TFile);
}

private async createNotesetQueue(noteSet: INoteSet): Promise<void> {
private async createNotesetQueueWithValidation(noteSet: INoteSet): Promise<void> {
const files = await this.generateNotesetQueue(noteSet);
noteSet.queue = new NoteQueue(files);
await this._plugin.noteSetService.validateRulesAndSave(noteSet);
Expand All @@ -120,6 +120,7 @@ export class ReviewService {
}
}


private async createNotesetQueueIfNotExists(
noteSet: INoteSet
): Promise<void> {
Expand All @@ -128,7 +129,7 @@ export class ReviewService {
!noteSet.queue?.filenames?.length ||
noteSet.queue.filenames.length === 0
) {
await this.createNotesetQueue(noteSet);
await this.createNotesetQueueWithValidation(noteSet);
}
}

Expand Down

0 comments on commit 5976031

Please sign in to comment.