Skip to content

Commit

Permalink
Merge pull request #59 from dartungar/dev
Browse files Browse the repository at this point in the history
fixed bug with refreshing noteset queue for noteset with empty queue …
  • Loading branch information
dartungar authored Feb 1, 2024
2 parents 4d800fb + 59ced1f commit 93dc02e
Show file tree
Hide file tree
Showing 4 changed files with 27 additions and 9 deletions.
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.0",
"version": "1.2.1",
"minAppVersion": "1.1.0",
"description": "Simple, customizable plugin for easy note review, resurfacing & repetition.",
"author": "dartungar",
Expand Down
6 changes: 4 additions & 2 deletions src/UI/sidebar/sidebarView.ts
Original file line number Diff line number Diff line change
Expand Up @@ -195,8 +195,10 @@ export class SimpleNoteReviewSidebarView extends ItemView {
section.addExtraButton((cb) => {
cb.setIcon("rotate-cw")
.setTooltip("reset review queue for this note set")
.onClick(async () =>
await this._plugin.reviewService.resetNotesetQueue(noteSet)
.onClick(async () => {
await this._plugin.noteSetService.validateRules(noteSet);
await this._plugin.reviewService.resetNotesetQueue(noteSet);
}
);
});

Expand Down
3 changes: 2 additions & 1 deletion src/noteSet/noteSetService.ts
Original file line number Diff line number Diff line change
Expand Up @@ -63,7 +63,8 @@ export class NoteSetService {
}

public async validateRules(noteSet: INoteSet): Promise<void> {
this._plugin.settings.noteSets.find(x => x.id === noteSet.id).validationError = await this.notesetRuleError(noteSet);
const notesetRuleError = await this.notesetRuleError(noteSet);
this._plugin.settings.noteSets.find(x => x.id === noteSet.id).validationError = notesetRuleError;
await this._plugin.saveSettings();
}

Expand Down
25 changes: 20 additions & 5 deletions src/queues/reviewService.ts
Original file line number Diff line number Diff line change
Expand Up @@ -70,19 +70,34 @@ export class ReviewService {
}

private async openNextNoteInQueue(noteSet: INoteSet): Promise<void> {
const errorMsgBase = `Error opening next note in note set ${noteSet.displayName}: `;
if (noteSet.queue?.filenames?.length && noteSet.queue?.filenames?.length === 0) {
this._plugin.showNotice(errorMsgBase + "review queue is empty.");
return;
}
const filePath = noteSet.queue.filenames[0];
const abstractFile = this._app.vault.getAbstractFileByPath(filePath);
await this._app.workspace.getMostRecentLeaf().openFile(abstractFile as TFile);
if (!abstractFile || !(abstractFile instanceof TFile)) {
this._plugin.showNotice(errorMsgBase + `could not get the note file with path "${filePath}" from Obsidian.`);
return;
}
const leaf = this._app.workspace.getMostRecentLeaf();
if (!leaf) {
this._plugin.showNotice(errorMsgBase + "could not get a leaf from Obsidian.");
return;
}
await leaf.openFile(abstractFile as TFile);
}

private async createNotesetQueue(noteSet: INoteSet): Promise<void> {
if (noteSet.validationError) {
this._plugin.showNotice(`note set "${noteSet.displayName}" has validation errors; you might want to fix them before starting the review.`)
return;
}
const files = await this.generateNotesetQueue(noteSet);
noteSet.queue = new NoteQueue(files);
await this._plugin.noteSetService.validateRules(noteSet);
await this._plugin.saveSettings();
if (noteSet.validationError) {
this._plugin.showNotice(`Error while trying to create review queue for note set "${noteSet.displayName}":\n ${noteSet.validationError}`);
return;
}
}

private async createNotesetQueueIfNotExists(noteSet: INoteSet): Promise<void> {
Expand Down

0 comments on commit 93dc02e

Please sign in to comment.