diff --git a/src/main.ts b/src/main.ts index b47c741..d5994b3 100644 --- a/src/main.ts +++ b/src/main.ts @@ -70,9 +70,9 @@ export default class IW extends Plugin { } getDefaultQueuePath() { - return normalizePath([this.settings.queueFolderPath, this.settings.queueFileName].join( - "/" - )); + return normalizePath( + [this.settings.queueFolderPath, this.settings.queueFileName].join("/") + ); } createTagMap() { diff --git a/src/views/bulk-adding.ts b/src/views/bulk-adding.ts index 7be8d55..e6a8b4e 100644 --- a/src/views/bulk-adding.ts +++ b/src/views/bulk-adding.ts @@ -67,9 +67,13 @@ export class BulkAdderModal extends ModalBase { } protected getQueuePath() { - const queue = this.queueComponent.getValue() === "" - ? path.relative(this.plugin.settings.queueFolderPath, this.plugin.queue.queuePath) - : this.queueComponent.getValue().withExtension(".md"); + const queue = + this.queueComponent.getValue() === "" + ? path.relative( + this.plugin.settings.queueFolderPath, + this.plugin.queue.queuePath + ) + : this.queueComponent.getValue().withExtension(".md"); return normalizePath( [this.plugin.settings.queueFolderPath, queue].join("/") @@ -86,7 +90,12 @@ export class BulkAdderModal extends ModalBase { contentEl.appendText("Queue: "); this.queueComponent = new TextComponent(contentEl) - .setPlaceholder(path.relative(this.plugin.settings.queueFolderPath, this.plugin.queue.queuePath)) + .setPlaceholder( + path.relative( + this.plugin.settings.queueFolderPath, + this.plugin.queue.queuePath + ) + ) .onChange( debounce( (_: string) => { diff --git a/src/views/create-queue.ts b/src/views/create-queue.ts index da181e5..f348f78 100644 --- a/src/views/create-queue.ts +++ b/src/views/create-queue.ts @@ -13,7 +13,6 @@ import "../helpers/str-utils"; import { AFactorScheduler, Scheduler, SimpleScheduler } from "src/scheduler"; export class CreateQueueModal extends ModalBase { - private queueNameText: TextComponent; private intervalText: TextComponent; private afactorText: TextComponent; @@ -31,34 +30,35 @@ export class CreateQueueModal extends ModalBase { // // Queue Name contentEl.appendText("Queue Name: "); - this.queueNameText = new TextComponent(contentEl) - .setPlaceholder("Examples: queue, folder/queue"); + this.queueNameText = new TextComponent(contentEl).setPlaceholder( + "Examples: queue, folder/queue" + ); contentEl.createEl("br"); this.queueNameText.inputEl.focus(); this.queueNameText.inputEl.select(); // // Queue Type - contentEl.appendText("Scheduler: ") + contentEl.appendText("Scheduler: "); this.schedulerDropdown = new DropdownComponent(contentEl) - .addOption("afactor", "A-Factor Scheduler") - .addOption("simple", "Simple Scheduler") - .setValue(this.plugin.settings.defaultQueueType) - .onChange((value: "afactor" | "simple") => this.showHideSchedulerSettings(value)); + .addOption("afactor", "A-Factor Scheduler") + .addOption("simple", "Simple Scheduler") + .setValue(this.plugin.settings.defaultQueueType) + .onChange((value: "afactor" | "simple") => + this.showHideSchedulerSettings(value) + ); contentEl.createEl("br"); - + // // Interval contentEl.appendText("Default Interval: "); - this.intervalText = new TextComponent(contentEl) - .setValue("1") + this.intervalText = new TextComponent(contentEl).setValue("1"); contentEl.createEl("br"); // // Afactor contentEl.appendText("Default A-Factor: "); - this.afactorText = new TextComponent(contentEl) - .setValue("2"); + this.afactorText = new TextComponent(contentEl).setValue("2"); contentEl.createEl("br"); // @@ -75,7 +75,7 @@ export class CreateQueueModal extends ModalBase { this.subscribeToEvents(); } -subscribeToEvents() { + subscribeToEvents() { this.contentEl.addEventListener("keydown", async (ev) => { if (ev.key === "Enter") { await this.create(); @@ -84,67 +84,66 @@ subscribeToEvents() { }); } - createScheduler(): Scheduler { - if (this.schedulerDropdown.getValue() === "afactor") { - const interval = Number(this.intervalText.getValue()); - if (!interval.isValidInterval()) { - LogTo.Debug("Invalid interval data.", true); - return; - } - - const afactor = Number(this.afactorText.getValue()); - if (!afactor.isValidAFactor()) { - LogTo.Debug("Invalid afactor data.", true); - return; - } - - return new AFactorScheduler(afactor, interval); - } - else { - return new SimpleScheduler(); - } + createScheduler(): Scheduler { + if (this.schedulerDropdown.getValue() === "afactor") { + const interval = Number(this.intervalText.getValue()); + if (!interval.isValidInterval()) { + LogTo.Debug("Invalid interval data.", true); + return; + } + + const afactor = Number(this.afactorText.getValue()); + if (!afactor.isValidAFactor()) { + LogTo.Debug("Invalid afactor data.", true); + return; + } + + return new AFactorScheduler(afactor, interval); + } else { + return new SimpleScheduler(); + } + } + async create() { + const queueName = this.queueNameText.getValue(); + if (!queueName || queueName.length === 0) { + LogTo.Debug("Invalid queue name.", true); + return; } - async create() { - const queueName = this.queueNameText.getValue(); - if (!queueName || queueName.length === 0) { - LogTo.Debug("Invalid queue name.", true); - return; - } - - const queueNameWithExt = queueName.withExtension(".md"); - const queueFile = normalizePath([this.plugin.settings.queueFolderPath, queueNameWithExt].join("/")); - if (await this.plugin.files.exists(queueFile)) { - LogTo.Debug("Queue already exists!", true); - return; - } - - const schedulerData = this.createScheduler()?.toString(); - if (!schedulerData || schedulerData.length === 0) - return; - - LogTo.Debug("Creating queue: " + queueName, true); - await this.plugin.files.createIfNotExists(queueFile, schedulerData); - await this.plugin.loadQueue(queueFile); + const queueNameWithExt = queueName.withExtension(".md"); + const queueFile = normalizePath( + [this.plugin.settings.queueFolderPath, queueNameWithExt].join("/") + ); + if (await this.plugin.files.exists(queueFile)) { + LogTo.Debug("Queue already exists!", true); + return; } - showHideSchedulerSettings(value: "simple" | "afactor") { - switch (value) { - case "simple": - this.intervalText.setDisabled(true); - this.afactorText.setDisabled(true); - this.intervalText.setValue("---"); - this.afactorText.setValue("---"); - return; - case "afactor": - this.intervalText.setDisabled(false); - this.afactorText.setDisabled(false); - this.intervalText.setValue("1"); - this.afactorText.setValue("2"); - return; - default: - throw new Error("Expected simple or afactor, got: " + value); - } + const schedulerData = this.createScheduler()?.toString(); + if (!schedulerData || schedulerData.length === 0) return; + + LogTo.Debug("Creating queue: " + queueName, true); + await this.plugin.files.createIfNotExists(queueFile, schedulerData); + await this.plugin.loadQueue(queueFile); + } + + showHideSchedulerSettings(value: "simple" | "afactor") { + switch (value) { + case "simple": + this.intervalText.setDisabled(true); + this.afactorText.setDisabled(true); + this.intervalText.setValue("---"); + this.afactorText.setValue("---"); + return; + case "afactor": + this.intervalText.setDisabled(false); + this.afactorText.setDisabled(false); + this.intervalText.setValue("1"); + this.afactorText.setValue("2"); + return; + default: + throw new Error("Expected simple or afactor, got: " + value); } + } } diff --git a/src/views/file-suggest.ts b/src/views/file-suggest.ts index 0e6531f..cb3b54e 100644 --- a/src/views/file-suggest.ts +++ b/src/views/file-suggest.ts @@ -23,19 +23,15 @@ export class FileSuggest extends TextInputSuggest { const files: TFile[] = []; for (const file of abstractFiles) { - if (!(file instanceof TFile)) - continue; + if (!(file instanceof TFile)) continue; - if (!(this.plugin.files.isDescendantOf(file, this.folder()))) - continue; - - if (file.extension !== "md") - continue + if (!this.plugin.files.isDescendantOf(file, this.folder())) continue; + + if (file.extension !== "md") continue; const relPath = path.relative(this.folder().path, file.path); - if (relPath.contains(inputStr)) - files.push(file); - } + if (relPath.contains(inputStr)) files.push(file); + } return files; } @@ -45,7 +41,10 @@ export class FileSuggest extends TextInputSuggest { } selectSuggestion(file: TFile): void { - this.inputEl.value = path.relative(this.plugin.settings.queueFolderPath, file.path) + this.inputEl.value = path.relative( + this.plugin.settings.queueFolderPath, + file.path + ); this.inputEl.trigger("input"); this.close(); } diff --git a/src/views/modals.ts b/src/views/modals.ts index 0995653..35483f8 100644 --- a/src/views/modals.ts +++ b/src/views/modals.ts @@ -40,8 +40,12 @@ abstract class ReviewModal extends ModalBase { // Queue contentEl.appendText("Queue: "); - this.inputQueueField = new TextComponent(contentEl) - .setPlaceholder(path.relative(this.plugin.settings.queueFolderPath, this.plugin.queue.queuePath)); + this.inputQueueField = new TextComponent(contentEl).setPlaceholder( + path.relative( + this.plugin.settings.queueFolderPath, + this.plugin.queue.queuePath + ) + ); let folderFunc = () => this.plugin.app.vault.getAbstractFileByPath( this.plugin.settings.queueFolderPath @@ -114,9 +118,13 @@ abstract class ReviewModal extends ModalBase { } getQueuePath() { - const queue = this.inputQueueField.getValue() === "" - ? path.relative(this.plugin.settings.queueFolderPath, this.plugin.queue.queuePath) - : this.inputQueueField.getValue().withExtension(".md"); + const queue = + this.inputQueueField.getValue() === "" + ? path.relative( + this.plugin.settings.queueFolderPath, + this.plugin.queue.queuePath + ) + : this.inputQueueField.getValue().withExtension(".md"); return normalizePath( [this.plugin.settings.queueFolderPath, queue].join("/") diff --git a/src/views/queue-modal.ts b/src/views/queue-modal.ts index bd1b706..e2ebcf6 100644 --- a/src/views/queue-modal.ts +++ b/src/views/queue-modal.ts @@ -1,5 +1,5 @@ import { normalizePath, FuzzySuggestModal } from "obsidian"; -import * as path from 'path'; +import * as path from "path"; import { LogTo } from "src/logger"; import IW from "../main"; @@ -18,8 +18,11 @@ export class QueueLoadModal extends FuzzySuggestModal { } getItems(): string[] { - const queueFolderPath = normalizePath(this.plugin.settings.queueFolderPath) - const defaultQueue = path.relative(queueFolderPath, this.plugin.getDefaultQueuePath()); + const queueFolderPath = normalizePath(this.plugin.settings.queueFolderPath); + const defaultQueue = path.relative( + queueFolderPath, + this.plugin.getDefaultQueuePath() + ); const folder = this.plugin.files.getTFolder(queueFolderPath); if (folder) { let files = this.plugin.app.vault @@ -27,8 +30,7 @@ export class QueueLoadModal extends FuzzySuggestModal { .filter((file) => this.plugin.files.isDescendantOf(file, folder)) .map((file) => path.relative(queueFolderPath, file.path)); - if (!files.some((f) => f === defaultQueue)) - files.push(defaultQueue); + if (!files.some((f) => f === defaultQueue)) files.push(defaultQueue); return files; } diff --git a/src/views/settings-tab.ts b/src/views/settings-tab.ts index 47820a4..dc93a75 100644 --- a/src/views/settings-tab.ts +++ b/src/views/settings-tab.ts @@ -123,7 +123,9 @@ export class IWSettingsTab extends PluginSettingTab { } const validDates: string[] = inputDates - .filter(([_, date]: [string, any]) => date != null && date.date) + .filter( + ([_, date]: [string, any]) => date != null && date.date + ) .map(([s, _]: [string, Date]) => s); if (inputDates.length !== validDates.length) { @@ -134,12 +136,13 @@ export class IWSettingsTab extends PluginSettingTab { ); } - const dateOptionsRecord: Record = validDates - .reduce((acc, x) => - { - acc[x] = x; - return acc; - }, {} as Record); + const dateOptionsRecord: Record< + string, + string + > = validDates.reduce((acc, x) => { + acc[x] = x; + return acc; + }, {} as Record); LogTo.Debug( "Setting dropdown date options to " + diff --git a/src/views/status-bar.ts b/src/views/status-bar.ts index a72853e..bf779ed 100644 --- a/src/views/status-bar.ts +++ b/src/views/status-bar.ts @@ -39,7 +39,9 @@ export class StatusBar { updateCurrentQueue(queuePath: string) { const normalized = normalizePath(queuePath); - const name = path.relative(this.plugin.settings.queueFolderPath, normalized).rtrim(".md") + const name = path + .relative(this.plugin.settings.queueFolderPath, normalized) + .rtrim(".md"); this.queueText.innerText = name && name.length > 0 ? "Queue: " + name : "Queue: None"; }