Skip to content

Commit

Permalink
Fix multichoice Back functionality.
Browse files Browse the repository at this point in the history
  • Loading branch information
chhoumann committed Jun 17, 2021
1 parent d43dd36 commit e419724
Show file tree
Hide file tree
Showing 5 changed files with 19 additions and 17 deletions.
2 changes: 1 addition & 1 deletion manifest.json
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
{
"id": "quickadd",
"name": "QuickAdd",
"version": "0.1.11",
"version": "0.1.12",
"minAppVersion": "0.12.00",
"description": "Quickly add new pages or content to your vault.",
"author": "Christian B. B. Houmann",
Expand Down
2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "quickadd",
"version": "0.1.11",
"version": "0.1.12",
"description": "Quickly add new pages or content to your vault.",
"main": "main.js",
"scripts": {
Expand Down
13 changes: 0 additions & 13 deletions src/choiceExecutor.ts
Original file line number Diff line number Diff line change
Expand Up @@ -18,10 +18,6 @@ export class ChoiceExecutor {

public async execute(): Promise<void> {
switch (this.choice.type) {
case ChoiceType.Multi:
const multiChoice: IMultiChoice = this.choice as IMultiChoice;
this.onChooseMultiType(multiChoice);
break;
case ChoiceType.Template:
const templateChoice: ITemplateChoice = this.choice as ITemplateChoice;
await this.onChooseTemplateType(templateChoice);
Expand All @@ -39,15 +35,6 @@ export class ChoiceExecutor {
}
}

private onChooseMultiType(multi: IMultiChoice) {
const choices = [...multi.choices];

if (multi.name != "← Back")
choices.push(new MultiChoice("← Back").addChoices(choices))

ChoiceSuggester.Open(this.plugin, choices);
}

private async onChooseTemplateType(templateChoice: ITemplateChoice): Promise<void> {
if (!templateChoice.templatePath) {
log.logError(`please provide a template path for ${templateChoice.name}`);
Expand Down
17 changes: 16 additions & 1 deletion src/gui/choiceSuggester.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,9 @@ import {FuzzySuggestModal} from "obsidian";
import type IChoice from "../types/choices/IChoice";
import type QuickAdd from "../main";
import {ChoiceExecutor} from "../choiceExecutor";
import type IMultiChoice from "../types/choices/IMultiChoice";
import {MultiChoice} from "../types/choices/MultiChoice";
import {ChoiceType} from "../types/choices/choiceType";

export default class ChoiceSuggester extends FuzzySuggestModal<IChoice> {
public static Open(plugin: QuickAdd, choices: IChoice[]) {
Expand All @@ -21,7 +24,19 @@ export default class ChoiceSuggester extends FuzzySuggestModal<IChoice> {
}

async onChooseItem(item: IChoice, evt: MouseEvent | KeyboardEvent): Promise<void> {
await new ChoiceExecutor(this.app, this.plugin, item).execute();
if (item.type === ChoiceType.Multi)
this.onChooseMultiType(<IMultiChoice>item);
else
await new ChoiceExecutor(this.app, this.plugin, item).execute();
}

private onChooseMultiType(multi: IMultiChoice) {
const choices = [...multi.choices];

if (multi.name != "← Back")
choices.push(new MultiChoice("← Back").addChoices(this.choices))

ChoiceSuggester.Open(this.plugin, choices);
}


Expand Down
2 changes: 1 addition & 1 deletion versions.json
Original file line number Diff line number Diff line change
@@ -1,3 +1,3 @@
{
"0.1.11": "0.12.4"
"0.1.12": "0.12.4"
}

0 comments on commit e419724

Please sign in to comment.