diff --git a/README.md b/README.md index 0919c40..9715c9b 100644 --- a/README.md +++ b/README.md @@ -27,6 +27,7 @@ If you would like to support my work, I have a [Patreon page](https://www.patreo - This plugin is not supported on mobile! (yet) ### Important! Priorities + - Confusingly, low priority numbers correspond to high priorities! That means your daily queue of repetitions will be sorted from lowest priority number (most important) to highest priority number (least important). This is because this is the way priorities work in SuperMemo and having used it for a couple years I just got used to thinking about it like that. I didn't realise how confusing this could be until someone mentioned it in an issue. Apologies for any confusion! ### Features diff --git a/data.json b/data.json index ae55e4e..a4248fd 100644 --- a/data.json +++ b/data.json @@ -9,5 +9,10 @@ "autoAddNewNotes": false, "defaultFirstRepDate": "today", "askForNextRepDate": false, - "dropdownNaturalDates": {"today": "today", "tomorrow": "tomorrow", "in two days": "in two days", "next week": "next week"} + "dropdownNaturalDates": { + "today": "today", + "tomorrow": "tomorrow", + "in two days": "in two days", + "next week": "next week" + } } diff --git a/src/settings.ts b/src/settings.ts index 1e4429b..b41e86c 100644 --- a/src/settings.ts +++ b/src/settings.ts @@ -24,9 +24,9 @@ export const DefaultSettings: IWSettings = { defaultFirstRepDate: "1970-01-01", askForNextRepDate: false, dropdownNaturalDates: { - "today": "today", - "tomorrow": "tomorrow", - "in two days": "in two days", - "next week": "next week", - } + today: "today", + tomorrow: "tomorrow", + "in two days": "in two days", + "next week": "next week", + }, }; diff --git a/src/views/bulk-adding.ts b/src/views/bulk-adding.ts index 1a1576c..4eb950c 100644 --- a/src/views/bulk-adding.ts +++ b/src/views/bulk-adding.ts @@ -143,15 +143,17 @@ export class BulkAdderModal extends ModalBase { // Rep Dates this.contentEl.appendText("Earliest Rep Date: "); - this.inputFirstRepMin = new TextComponent(contentEl) - .setPlaceholder("1970-01-01") - new NaturalDateSuggest(this.plugin, this.inputFirstRepMin.inputEl) + this.inputFirstRepMin = new TextComponent(contentEl).setPlaceholder( + "1970-01-01" + ); + new NaturalDateSuggest(this.plugin, this.inputFirstRepMin.inputEl); this.contentEl.createEl("br"); this.contentEl.appendText("Latest Rep Date: "); - this.inputFirstRepMax = new TextComponent(contentEl) - .setPlaceholder("1970-01-01") - new NaturalDateSuggest(this.plugin, this.inputFirstRepMax.inputEl) + this.inputFirstRepMax = new TextComponent(contentEl).setPlaceholder( + "1970-01-01" + ); + new NaturalDateSuggest(this.plugin, this.inputFirstRepMax.inputEl); this.contentEl.createEl("br"); // // Events @@ -184,8 +186,12 @@ export class BulkAdderModal extends ModalBase { const priMax = Number(this.maxPriorityComponent.getValue()); const dateMinStr = this.inputFirstRepMin.getValue(); const dateMaxStr = this.inputFirstRepMax.getValue(); - const dateMin = this.parseDate(dateMinStr === "" ? "1970-01-01" : dateMinStr); - const dateMax = this.parseDate(dateMaxStr === "" ? "1970-01-01" : dateMaxStr); + const dateMin = this.parseDate( + dateMinStr === "" ? "1970-01-01" : dateMinStr + ); + const dateMax = this.parseDate( + dateMaxStr === "" ? "1970-01-01" : dateMaxStr + ); if ( !( diff --git a/src/views/date-suggest.ts b/src/views/date-suggest.ts index 4f4d7f9..bb8e88b 100644 --- a/src/views/date-suggest.ts +++ b/src/views/date-suggest.ts @@ -1,16 +1,17 @@ -import IW from 'src/main'; -import { TextInputSuggest } from './suggest' +import IW from "src/main"; +import { TextInputSuggest } from "./suggest"; export class NaturalDateSuggest extends TextInputSuggest { private plugin: IW; constructor(plugin: IW, inputEl: HTMLInputElement) { - super(plugin.app, inputEl); - this.plugin = plugin; + super(plugin.app, inputEl); + this.plugin = plugin; } getSuggestions(inputStr: string): string[] { - return Object.keys(this.plugin.settings.dropdownNaturalDates) - .filter(date => date.contains(inputStr)); + return Object.keys( + this.plugin.settings.dropdownNaturalDates + ).filter((date) => date.contains(inputStr)); } renderSuggestion(date: string, el: HTMLElement): void { diff --git a/src/views/edit-data.ts b/src/views/edit-data.ts index 0677034..1ba72b7 100644 --- a/src/views/edit-data.ts +++ b/src/views/edit-data.ts @@ -1,4 +1,9 @@ -import { SliderComponent, TextComponent, ButtonComponent, DropdownComponent } from "obsidian"; +import { + SliderComponent, + TextComponent, + ButtonComponent, + DropdownComponent, +} from "obsidian"; import IW from "../main"; import { ModalBase } from "./modal-base"; import { LogTo } from "../logger"; @@ -31,8 +36,9 @@ export class EditDataModal extends ModalBase { // Next Rep Date contentEl.appendText("Next Rep Date: "); - this.inputNextRep = new TextComponent(contentEl) - .setPlaceholder(this.currentRep.nextRepDate.formatYYMMDD()); + this.inputNextRep = new TextComponent(contentEl).setPlaceholder( + this.currentRep.nextRepDate.formatYYMMDD() + ); new NaturalDateSuggest(this.plugin, this.inputNextRep.inputEl); contentEl.createEl("br"); @@ -85,7 +91,7 @@ export class EditDataModal extends ModalBase { } async updateRepData() { - const dateStr = this.inputNextRep.getValue(); + const dateStr = this.inputNextRep.getValue(); const date = this.parseDate(dateStr === "" ? "1970-01-01" : dateStr); if (!date) { LogTo.Console("Failed to parse next repetition date!", true); diff --git a/src/views/modals.ts b/src/views/modals.ts index b53a63b..3a45f94 100644 --- a/src/views/modals.ts +++ b/src/views/modals.ts @@ -54,8 +54,9 @@ abstract class ReviewModal extends ModalBase { const firstRepDate = this.plugin.settings.defaultFirstRepDate; contentEl.appendText("First Rep Date: "); - this.inputFirstRep = new TextComponent(contentEl) - .setPlaceholder(firstRepDate); + this.inputFirstRep = new TextComponent(contentEl).setPlaceholder( + firstRepDate + ); new NaturalDateSuggest(this.plugin, this.inputFirstRep.inputEl); contentEl.createEl("br"); @@ -134,7 +135,7 @@ export class ReviewNoteModal extends ReviewModal { } async addToOutstanding() { - const dateStr = this.inputFirstRep.getValue(); + const dateStr = this.inputFirstRep.getValue(); const date = this.parseDate(dateStr === "" ? "1970-01-01" : dateStr); if (!date) { LogTo.Console("Failed to parse initial repetition date!"); @@ -172,7 +173,7 @@ export class ReviewFileModal extends ReviewModal { } async addToOutstanding() { - const dateStr = this.inputFirstRep.getValue(); + const dateStr = this.inputFirstRep.getValue(); const date = this.parseDate(dateStr === "" ? "1970-01-01" : dateStr); if (!date) { LogTo.Console("Failed to parse initial repetition date!"); @@ -224,7 +225,7 @@ export class ReviewBlockModal extends ReviewModal { } async addToOutstanding() { - const dateStr = this.inputFirstRep.getValue(); + const dateStr = this.inputFirstRep.getValue(); const date = this.parseDate(dateStr === "" ? "1970-01-01" : dateStr); if (!date) { LogTo.Console("Failed to parse initial repetition date!"); diff --git a/src/views/next-rep-schedule.ts b/src/views/next-rep-schedule.ts index 77bca8b..0c29f93 100644 --- a/src/views/next-rep-schedule.ts +++ b/src/views/next-rep-schedule.ts @@ -29,9 +29,10 @@ export class NextRepScheduler extends ModalBase { // Date contentEl.appendText("Next repetition date: "); - this.repDateComponent = new TextComponent(contentEl) - .setPlaceholder(this.curRep.nextRepDate.formatYYMMDD()) - new NaturalDateSuggest(this.plugin, this.repDateComponent.inputEl) + this.repDateComponent = new TextComponent(contentEl).setPlaceholder( + this.curRep.nextRepDate.formatYYMMDD() + ); + new NaturalDateSuggest(this.plugin, this.repDateComponent.inputEl); contentEl.createEl("br"); this.repDateComponent.inputEl.focus(); @@ -84,7 +85,7 @@ export class NextRepScheduler extends ModalBase { } async schedule() { - const dateStr = this.repDateComponent.getValue(); + const dateStr = this.repDateComponent.getValue(); const date = this.parseDate(dateStr === "" ? "1970-01-01" : dateStr); if (!date) { LogTo.Console("Failed to parse next repetition date!", true); diff --git a/src/views/settings-tab.ts b/src/views/settings-tab.ts index 4e560a5..57e995c 100644 --- a/src/views/settings-tab.ts +++ b/src/views/settings-tab.ts @@ -88,52 +88,72 @@ export class IWSettingsTab extends PluginSettingTab { this.plugin.saveData(settings); }); }); - - const nldates = (this.plugin.app).plugins.getPlugin( - "nldates-obsidian" - ); + const nldates = (this.plugin.app).plugins.getPlugin( + "nldates-obsidian" + ); const hasNlDates = nldates != null; // // Dropdown Dates new Setting(containerEl) - .setName("Dropdown Date List") - .setDesc("Sets the default list of dropdown dates that show up in modals so you can quickly set repetition dates.") - .addTextArea((comp) => { - comp.setPlaceholder("Example:\ntoday\ntomorrow\nnext week") - const currentValue = Object.keys(this.plugin.settings.dropdownNaturalDates).join("\n"); - comp.setValue(currentValue).onChange( - debounce(value => { + .setName("Dropdown Date List") + .setDesc( + "Sets the default list of dropdown dates that show up in modals so you can quickly set repetition dates." + ) + .addTextArea((comp) => { + comp.setPlaceholder("Example:\ntoday\ntomorrow\nnext week"); + const currentValue = Object.keys( + this.plugin.settings.dropdownNaturalDates + ).join("\n"); + comp.setValue(currentValue).onChange( + debounce( + (value) => { if (hasNlDates) { - const inputDates = String(value) - ?.split(/\r?\n/) - ?.map(str => [str, nldates.parseDate(str)]) || []; - - if (!inputDates || inputDates.length === 0) { - LogTo.Debug("User inputted dates were null or empty"); - settings.dropdownNaturalDates = {}; - this.plugin.saveData(settings); - return; - } - - const validDates = inputDates - .filter(([_, date]) => date != null && date.date) - .map(([s, _]) => s); - - if (inputDates.length !== validDates.length) { - LogTo.Debug(`Ignoring ${inputDates.length - validDates.length} invalid natural language date strings.`); - } - - const dateOptionsRecord: Record = validDates - .reduce((acc: Record, x: string) => acc[x]=x, {}); - LogTo.Debug("Setting dropdown date options to " + JSON.stringify(dateOptionsRecord)); + const inputDates = + String(value) + ?.split(/\r?\n/) + ?.map((str) => [str, nldates.parseDate(str)]) || []; + + if (!inputDates || inputDates.length === 0) { + LogTo.Debug("User inputted dates were null or empty"); + settings.dropdownNaturalDates = {}; + this.plugin.saveData(settings); + return; + } + + const validDates = inputDates + .filter(([_, date]) => date != null && date.date) + .map(([s, _]) => s); + + if (inputDates.length !== validDates.length) { + LogTo.Debug( + `Ignoring ${ + inputDates.length - validDates.length + } invalid natural language date strings.` + ); + } + + const dateOptionsRecord: Record< + string, + string + > = validDates.reduce( + (acc: Record, x: string) => (acc[x] = x), + {} + ); + LogTo.Debug( + "Setting dropdown date options to " + + JSON.stringify(dateOptionsRecord) + ); settings.dropdownNaturalDates = dateOptionsRecord; this.plugin.saveData(settings); } - }, 500, true) - ) - }) + }, + 500, + true + ) + ); + }); // // First Rep Date @@ -144,30 +164,31 @@ export class IWSettingsTab extends PluginSettingTab { "Sets the default first repetition date for new repetitions. Example: today, tomorrow, next week. **Requires that you have installed the Natural Language Dates plugin.**" ) .addText((comp) => { - new NaturalDateSuggest(this.plugin, comp.inputEl); - comp.setValue(String(settings.defaultFirstRepDate)) - .setPlaceholder("1970-01-01") - .onChange( - debounce( - (value) => { - if (hasNlDates) { - const dateString = String(value); - const date = nldates.parseDate(dateString); - if (date && date.date) { - LogTo.Debug( - "Setting default first rep date to " + dateString - ); - settings.defaultFirstRepDate = dateString; - this.plugin.saveData(settings); - } else { - LogTo.Debug("Invalid natural language date string."); + new NaturalDateSuggest(this.plugin, comp.inputEl); + comp + .setValue(String(settings.defaultFirstRepDate)) + .setPlaceholder("1970-01-01") + .onChange( + debounce( + (value) => { + if (hasNlDates) { + const dateString = String(value); + const date = nldates.parseDate(dateString); + if (date && date.date) { + LogTo.Debug( + "Setting default first rep date to " + dateString + ); + settings.defaultFirstRepDate = dateString; + this.plugin.saveData(settings); + } else { + LogTo.Debug("Invalid natural language date string."); + } } - } - }, - 500, - true - ) - ); + }, + 500, + true + ) + ); }); //