Skip to content

Commit 9c8d82f

Browse files
author
jamesb
committed
- Misc: Formatted with prettier.
1 parent 1460dfb commit 9c8d82f

9 files changed

+134
-92
lines changed

Diff for: README.md

+1
Original file line numberDiff line numberDiff line change
@@ -27,6 +27,7 @@ If you would like to support my work, I have a [Patreon page](https://www.patreo
2727
- This plugin is not supported on mobile! (yet)
2828

2929
### Important! Priorities
30+
3031
- 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!
3132

3233
### Features

Diff for: data.json

+6-1
Original file line numberDiff line numberDiff line change
@@ -9,5 +9,10 @@
99
"autoAddNewNotes": false,
1010
"defaultFirstRepDate": "today",
1111
"askForNextRepDate": false,
12-
"dropdownNaturalDates": {"today": "today", "tomorrow": "tomorrow", "in two days": "in two days", "next week": "next week"}
12+
"dropdownNaturalDates": {
13+
"today": "today",
14+
"tomorrow": "tomorrow",
15+
"in two days": "in two days",
16+
"next week": "next week"
17+
}
1318
}

Diff for: src/settings.ts

+5-5
Original file line numberDiff line numberDiff line change
@@ -24,9 +24,9 @@ export const DefaultSettings: IWSettings = {
2424
defaultFirstRepDate: "1970-01-01",
2525
askForNextRepDate: false,
2626
dropdownNaturalDates: {
27-
"today": "today",
28-
"tomorrow": "tomorrow",
29-
"in two days": "in two days",
30-
"next week": "next week",
31-
}
27+
today: "today",
28+
tomorrow: "tomorrow",
29+
"in two days": "in two days",
30+
"next week": "next week",
31+
},
3232
};

Diff for: src/views/bulk-adding.ts

+14-8
Original file line numberDiff line numberDiff line change
@@ -143,15 +143,17 @@ export class BulkAdderModal extends ModalBase {
143143
// Rep Dates
144144

145145
this.contentEl.appendText("Earliest Rep Date: ");
146-
this.inputFirstRepMin = new TextComponent(contentEl)
147-
.setPlaceholder("1970-01-01")
148-
new NaturalDateSuggest(this.plugin, this.inputFirstRepMin.inputEl)
146+
this.inputFirstRepMin = new TextComponent(contentEl).setPlaceholder(
147+
"1970-01-01"
148+
);
149+
new NaturalDateSuggest(this.plugin, this.inputFirstRepMin.inputEl);
149150
this.contentEl.createEl("br");
150151

151152
this.contentEl.appendText("Latest Rep Date: ");
152-
this.inputFirstRepMax = new TextComponent(contentEl)
153-
.setPlaceholder("1970-01-01")
154-
new NaturalDateSuggest(this.plugin, this.inputFirstRepMax.inputEl)
153+
this.inputFirstRepMax = new TextComponent(contentEl).setPlaceholder(
154+
"1970-01-01"
155+
);
156+
new NaturalDateSuggest(this.plugin, this.inputFirstRepMax.inputEl);
155157
this.contentEl.createEl("br");
156158
//
157159
// Events
@@ -184,8 +186,12 @@ export class BulkAdderModal extends ModalBase {
184186
const priMax = Number(this.maxPriorityComponent.getValue());
185187
const dateMinStr = this.inputFirstRepMin.getValue();
186188
const dateMaxStr = this.inputFirstRepMax.getValue();
187-
const dateMin = this.parseDate(dateMinStr === "" ? "1970-01-01" : dateMinStr);
188-
const dateMax = this.parseDate(dateMaxStr === "" ? "1970-01-01" : dateMaxStr);
189+
const dateMin = this.parseDate(
190+
dateMinStr === "" ? "1970-01-01" : dateMinStr
191+
);
192+
const dateMax = this.parseDate(
193+
dateMaxStr === "" ? "1970-01-01" : dateMaxStr
194+
);
189195

190196
if (
191197
!(

Diff for: src/views/date-suggest.ts

+7-6
Original file line numberDiff line numberDiff line change
@@ -1,16 +1,17 @@
1-
import IW from 'src/main';
2-
import { TextInputSuggest } from './suggest'
1+
import IW from "src/main";
2+
import { TextInputSuggest } from "./suggest";
33

44
export class NaturalDateSuggest extends TextInputSuggest<string> {
55
private plugin: IW;
66
constructor(plugin: IW, inputEl: HTMLInputElement) {
7-
super(plugin.app, inputEl);
8-
this.plugin = plugin;
7+
super(plugin.app, inputEl);
8+
this.plugin = plugin;
99
}
1010

1111
getSuggestions(inputStr: string): string[] {
12-
return Object.keys(this.plugin.settings.dropdownNaturalDates)
13-
.filter(date => date.contains(inputStr));
12+
return Object.keys(
13+
this.plugin.settings.dropdownNaturalDates
14+
).filter((date) => date.contains(inputStr));
1415
}
1516

1617
renderSuggestion(date: string, el: HTMLElement): void {

Diff for: src/views/edit-data.ts

+10-4
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,9 @@
1-
import { SliderComponent, TextComponent, ButtonComponent, DropdownComponent } from "obsidian";
1+
import {
2+
SliderComponent,
3+
TextComponent,
4+
ButtonComponent,
5+
DropdownComponent,
6+
} from "obsidian";
27
import IW from "../main";
38
import { ModalBase } from "./modal-base";
49
import { LogTo } from "../logger";
@@ -31,8 +36,9 @@ export class EditDataModal extends ModalBase {
3136
// Next Rep Date
3237

3338
contentEl.appendText("Next Rep Date: ");
34-
this.inputNextRep = new TextComponent(contentEl)
35-
.setPlaceholder(this.currentRep.nextRepDate.formatYYMMDD());
39+
this.inputNextRep = new TextComponent(contentEl).setPlaceholder(
40+
this.currentRep.nextRepDate.formatYYMMDD()
41+
);
3642
new NaturalDateSuggest(this.plugin, this.inputNextRep.inputEl);
3743
contentEl.createEl("br");
3844

@@ -85,7 +91,7 @@ export class EditDataModal extends ModalBase {
8591
}
8692

8793
async updateRepData() {
88-
const dateStr = this.inputNextRep.getValue();
94+
const dateStr = this.inputNextRep.getValue();
8995
const date = this.parseDate(dateStr === "" ? "1970-01-01" : dateStr);
9096
if (!date) {
9197
LogTo.Console("Failed to parse next repetition date!", true);

Diff for: src/views/modals.ts

+6-5
Original file line numberDiff line numberDiff line change
@@ -54,8 +54,9 @@ abstract class ReviewModal extends ModalBase {
5454

5555
const firstRepDate = this.plugin.settings.defaultFirstRepDate;
5656
contentEl.appendText("First Rep Date: ");
57-
this.inputFirstRep = new TextComponent(contentEl)
58-
.setPlaceholder(firstRepDate);
57+
this.inputFirstRep = new TextComponent(contentEl).setPlaceholder(
58+
firstRepDate
59+
);
5960
new NaturalDateSuggest(this.plugin, this.inputFirstRep.inputEl);
6061
contentEl.createEl("br");
6162

@@ -134,7 +135,7 @@ export class ReviewNoteModal extends ReviewModal {
134135
}
135136

136137
async addToOutstanding() {
137-
const dateStr = this.inputFirstRep.getValue();
138+
const dateStr = this.inputFirstRep.getValue();
138139
const date = this.parseDate(dateStr === "" ? "1970-01-01" : dateStr);
139140
if (!date) {
140141
LogTo.Console("Failed to parse initial repetition date!");
@@ -172,7 +173,7 @@ export class ReviewFileModal extends ReviewModal {
172173
}
173174

174175
async addToOutstanding() {
175-
const dateStr = this.inputFirstRep.getValue();
176+
const dateStr = this.inputFirstRep.getValue();
176177
const date = this.parseDate(dateStr === "" ? "1970-01-01" : dateStr);
177178
if (!date) {
178179
LogTo.Console("Failed to parse initial repetition date!");
@@ -224,7 +225,7 @@ export class ReviewBlockModal extends ReviewModal {
224225
}
225226

226227
async addToOutstanding() {
227-
const dateStr = this.inputFirstRep.getValue();
228+
const dateStr = this.inputFirstRep.getValue();
228229
const date = this.parseDate(dateStr === "" ? "1970-01-01" : dateStr);
229230
if (!date) {
230231
LogTo.Console("Failed to parse initial repetition date!");

Diff for: src/views/next-rep-schedule.ts

+5-4
Original file line numberDiff line numberDiff line change
@@ -29,9 +29,10 @@ export class NextRepScheduler extends ModalBase {
2929
// Date
3030

3131
contentEl.appendText("Next repetition date: ");
32-
this.repDateComponent = new TextComponent(contentEl)
33-
.setPlaceholder(this.curRep.nextRepDate.formatYYMMDD())
34-
new NaturalDateSuggest(this.plugin, this.repDateComponent.inputEl)
32+
this.repDateComponent = new TextComponent(contentEl).setPlaceholder(
33+
this.curRep.nextRepDate.formatYYMMDD()
34+
);
35+
new NaturalDateSuggest(this.plugin, this.repDateComponent.inputEl);
3536
contentEl.createEl("br");
3637

3738
this.repDateComponent.inputEl.focus();
@@ -84,7 +85,7 @@ export class NextRepScheduler extends ModalBase {
8485
}
8586

8687
async schedule() {
87-
const dateStr = this.repDateComponent.getValue();
88+
const dateStr = this.repDateComponent.getValue();
8889
const date = this.parseDate(dateStr === "" ? "1970-01-01" : dateStr);
8990
if (!date) {
9091
LogTo.Console("Failed to parse next repetition date!", true);

Diff for: src/views/settings-tab.ts

+80-59
Original file line numberDiff line numberDiff line change
@@ -88,52 +88,72 @@ export class IWSettingsTab extends PluginSettingTab {
8888
this.plugin.saveData(settings);
8989
});
9090
});
91-
9291

93-
const nldates = (<any>this.plugin.app).plugins.getPlugin(
94-
"nldates-obsidian"
95-
);
92+
const nldates = (<any>this.plugin.app).plugins.getPlugin(
93+
"nldates-obsidian"
94+
);
9695
const hasNlDates = nldates != null;
9796

9897
//
9998
// Dropdown Dates
10099
new Setting(containerEl)
101-
.setName("Dropdown Date List")
102-
.setDesc("Sets the default list of dropdown dates that show up in modals so you can quickly set repetition dates.")
103-
.addTextArea((comp) => {
104-
comp.setPlaceholder("Example:\ntoday\ntomorrow\nnext week")
105-
const currentValue = Object.keys(this.plugin.settings.dropdownNaturalDates).join("\n");
106-
comp.setValue(currentValue).onChange(
107-
debounce(value => {
100+
.setName("Dropdown Date List")
101+
.setDesc(
102+
"Sets the default list of dropdown dates that show up in modals so you can quickly set repetition dates."
103+
)
104+
.addTextArea((comp) => {
105+
comp.setPlaceholder("Example:\ntoday\ntomorrow\nnext week");
106+
const currentValue = Object.keys(
107+
this.plugin.settings.dropdownNaturalDates
108+
).join("\n");
109+
comp.setValue(currentValue).onChange(
110+
debounce(
111+
(value) => {
108112
if (hasNlDates) {
109-
const inputDates = String(value)
110-
?.split(/\r?\n/)
111-
?.map(str => [str, nldates.parseDate(str)]) || [];
112-
113-
if (!inputDates || inputDates.length === 0) {
114-
LogTo.Debug("User inputted dates were null or empty");
115-
settings.dropdownNaturalDates = {};
116-
this.plugin.saveData(settings);
117-
return;
118-
}
119-
120-
const validDates = inputDates
121-
.filter(([_, date]) => date != null && date.date)
122-
.map(([s, _]) => s);
123-
124-
if (inputDates.length !== validDates.length) {
125-
LogTo.Debug(`Ignoring ${inputDates.length - validDates.length} invalid natural language date strings.`);
126-
}
127-
128-
const dateOptionsRecord: Record<string, string> = validDates
129-
.reduce((acc: Record<string, string>, x: string) => acc[x]=x, {});
130-
LogTo.Debug("Setting dropdown date options to " + JSON.stringify(dateOptionsRecord));
113+
const inputDates =
114+
String(value)
115+
?.split(/\r?\n/)
116+
?.map((str) => [str, nldates.parseDate(str)]) || [];
117+
118+
if (!inputDates || inputDates.length === 0) {
119+
LogTo.Debug("User inputted dates were null or empty");
120+
settings.dropdownNaturalDates = {};
121+
this.plugin.saveData(settings);
122+
return;
123+
}
124+
125+
const validDates = inputDates
126+
.filter(([_, date]) => date != null && date.date)
127+
.map(([s, _]) => s);
128+
129+
if (inputDates.length !== validDates.length) {
130+
LogTo.Debug(
131+
`Ignoring ${
132+
inputDates.length - validDates.length
133+
} invalid natural language date strings.`
134+
);
135+
}
136+
137+
const dateOptionsRecord: Record<
138+
string,
139+
string
140+
> = validDates.reduce(
141+
(acc: Record<string, string>, x: string) => (acc[x] = x),
142+
{}
143+
);
144+
LogTo.Debug(
145+
"Setting dropdown date options to " +
146+
JSON.stringify(dateOptionsRecord)
147+
);
131148
settings.dropdownNaturalDates = dateOptionsRecord;
132149
this.plugin.saveData(settings);
133150
}
134-
}, 500, true)
135-
)
136-
})
151+
},
152+
500,
153+
true
154+
)
155+
);
156+
});
137157

138158
//
139159
// First Rep Date
@@ -144,30 +164,31 @@ export class IWSettingsTab extends PluginSettingTab {
144164
"Sets the default first repetition date for new repetitions. Example: today, tomorrow, next week. **Requires that you have installed the Natural Language Dates plugin.**"
145165
)
146166
.addText((comp) => {
147-
new NaturalDateSuggest(this.plugin, comp.inputEl);
148-
comp.setValue(String(settings.defaultFirstRepDate))
149-
.setPlaceholder("1970-01-01")
150-
.onChange(
151-
debounce(
152-
(value) => {
153-
if (hasNlDates) {
154-
const dateString = String(value);
155-
const date = nldates.parseDate(dateString);
156-
if (date && date.date) {
157-
LogTo.Debug(
158-
"Setting default first rep date to " + dateString
159-
);
160-
settings.defaultFirstRepDate = dateString;
161-
this.plugin.saveData(settings);
162-
} else {
163-
LogTo.Debug("Invalid natural language date string.");
167+
new NaturalDateSuggest(this.plugin, comp.inputEl);
168+
comp
169+
.setValue(String(settings.defaultFirstRepDate))
170+
.setPlaceholder("1970-01-01")
171+
.onChange(
172+
debounce(
173+
(value) => {
174+
if (hasNlDates) {
175+
const dateString = String(value);
176+
const date = nldates.parseDate(dateString);
177+
if (date && date.date) {
178+
LogTo.Debug(
179+
"Setting default first rep date to " + dateString
180+
);
181+
settings.defaultFirstRepDate = dateString;
182+
this.plugin.saveData(settings);
183+
} else {
184+
LogTo.Debug("Invalid natural language date string.");
185+
}
164186
}
165-
}
166-
},
167-
500,
168-
true
169-
)
170-
);
187+
},
188+
500,
189+
true
190+
)
191+
);
171192
});
172193

173194
//

0 commit comments

Comments
 (0)