Skip to content

Commit 7add55a

Browse files
author
jamesb
committed
- Misc: formatted code
1 parent 471c8af commit 7add55a

8 files changed

+129
-107
lines changed

Diff for: src/main.ts

+3-3
Original file line numberDiff line numberDiff line change
@@ -70,9 +70,9 @@ export default class IW extends Plugin {
7070
}
7171

7272
getDefaultQueuePath() {
73-
return normalizePath([this.settings.queueFolderPath, this.settings.queueFileName].join(
74-
"/"
75-
));
73+
return normalizePath(
74+
[this.settings.queueFolderPath, this.settings.queueFileName].join("/")
75+
);
7676
}
7777

7878
createTagMap() {

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

+13-4
Original file line numberDiff line numberDiff line change
@@ -67,9 +67,13 @@ export class BulkAdderModal extends ModalBase {
6767
}
6868

6969
protected getQueuePath() {
70-
const queue = this.queueComponent.getValue() === ""
71-
? path.relative(this.plugin.settings.queueFolderPath, this.plugin.queue.queuePath)
72-
: this.queueComponent.getValue().withExtension(".md");
70+
const queue =
71+
this.queueComponent.getValue() === ""
72+
? path.relative(
73+
this.plugin.settings.queueFolderPath,
74+
this.plugin.queue.queuePath
75+
)
76+
: this.queueComponent.getValue().withExtension(".md");
7377

7478
return normalizePath(
7579
[this.plugin.settings.queueFolderPath, queue].join("/")
@@ -86,7 +90,12 @@ export class BulkAdderModal extends ModalBase {
8690

8791
contentEl.appendText("Queue: ");
8892
this.queueComponent = new TextComponent(contentEl)
89-
.setPlaceholder(path.relative(this.plugin.settings.queueFolderPath, this.plugin.queue.queuePath))
93+
.setPlaceholder(
94+
path.relative(
95+
this.plugin.settings.queueFolderPath,
96+
this.plugin.queue.queuePath
97+
)
98+
)
9099
.onChange(
91100
debounce(
92101
(_: string) => {

Diff for: src/views/create-queue.ts

+70-71
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,6 @@ import "../helpers/str-utils";
1313
import { AFactorScheduler, Scheduler, SimpleScheduler } from "src/scheduler";
1414

1515
export class CreateQueueModal extends ModalBase {
16-
1716
private queueNameText: TextComponent;
1817
private intervalText: TextComponent;
1918
private afactorText: TextComponent;
@@ -31,34 +30,35 @@ export class CreateQueueModal extends ModalBase {
3130
//
3231
// Queue Name
3332
contentEl.appendText("Queue Name: ");
34-
this.queueNameText = new TextComponent(contentEl)
35-
.setPlaceholder("Examples: queue, folder/queue");
33+
this.queueNameText = new TextComponent(contentEl).setPlaceholder(
34+
"Examples: queue, folder/queue"
35+
);
3636
contentEl.createEl("br");
3737
this.queueNameText.inputEl.focus();
3838
this.queueNameText.inputEl.select();
3939

4040
//
4141
// Queue Type
42-
contentEl.appendText("Scheduler: ")
42+
contentEl.appendText("Scheduler: ");
4343
this.schedulerDropdown = new DropdownComponent(contentEl)
44-
.addOption("afactor", "A-Factor Scheduler")
45-
.addOption("simple", "Simple Scheduler")
46-
.setValue(this.plugin.settings.defaultQueueType)
47-
.onChange((value: "afactor" | "simple") => this.showHideSchedulerSettings(value));
44+
.addOption("afactor", "A-Factor Scheduler")
45+
.addOption("simple", "Simple Scheduler")
46+
.setValue(this.plugin.settings.defaultQueueType)
47+
.onChange((value: "afactor" | "simple") =>
48+
this.showHideSchedulerSettings(value)
49+
);
4850
contentEl.createEl("br");
49-
51+
5052
//
5153
// Interval
5254
contentEl.appendText("Default Interval: ");
53-
this.intervalText = new TextComponent(contentEl)
54-
.setValue("1")
55+
this.intervalText = new TextComponent(contentEl).setValue("1");
5556
contentEl.createEl("br");
5657

5758
//
5859
// Afactor
5960
contentEl.appendText("Default A-Factor: ");
60-
this.afactorText = new TextComponent(contentEl)
61-
.setValue("2");
61+
this.afactorText = new TextComponent(contentEl).setValue("2");
6262
contentEl.createEl("br");
6363

6464
//
@@ -75,7 +75,7 @@ export class CreateQueueModal extends ModalBase {
7575
this.subscribeToEvents();
7676
}
7777

78-
subscribeToEvents() {
78+
subscribeToEvents() {
7979
this.contentEl.addEventListener("keydown", async (ev) => {
8080
if (ev.key === "Enter") {
8181
await this.create();
@@ -84,67 +84,66 @@ subscribeToEvents() {
8484
});
8585
}
8686

87-
createScheduler(): Scheduler {
88-
if (this.schedulerDropdown.getValue() === "afactor") {
89-
const interval = Number(this.intervalText.getValue());
90-
if (!interval.isValidInterval()) {
91-
LogTo.Debug("Invalid interval data.", true);
92-
return;
93-
}
94-
95-
const afactor = Number(this.afactorText.getValue());
96-
if (!afactor.isValidAFactor()) {
97-
LogTo.Debug("Invalid afactor data.", true);
98-
return;
99-
}
100-
101-
return new AFactorScheduler(afactor, interval);
102-
}
103-
else {
104-
return new SimpleScheduler();
105-
}
87+
createScheduler(): Scheduler {
88+
if (this.schedulerDropdown.getValue() === "afactor") {
89+
const interval = Number(this.intervalText.getValue());
90+
if (!interval.isValidInterval()) {
91+
LogTo.Debug("Invalid interval data.", true);
92+
return;
93+
}
94+
95+
const afactor = Number(this.afactorText.getValue());
96+
if (!afactor.isValidAFactor()) {
97+
LogTo.Debug("Invalid afactor data.", true);
98+
return;
99+
}
100+
101+
return new AFactorScheduler(afactor, interval);
102+
} else {
103+
return new SimpleScheduler();
104+
}
105+
}
106106

107+
async create() {
108+
const queueName = this.queueNameText.getValue();
109+
if (!queueName || queueName.length === 0) {
110+
LogTo.Debug("Invalid queue name.", true);
111+
return;
107112
}
108113

109-
async create() {
110-
const queueName = this.queueNameText.getValue();
111-
if (!queueName || queueName.length === 0) {
112-
LogTo.Debug("Invalid queue name.", true);
113-
return;
114-
}
115-
116-
const queueNameWithExt = queueName.withExtension(".md");
117-
const queueFile = normalizePath([this.plugin.settings.queueFolderPath, queueNameWithExt].join("/"));
118-
if (await this.plugin.files.exists(queueFile)) {
119-
LogTo.Debug("Queue already exists!", true);
120-
return;
121-
}
122-
123-
const schedulerData = this.createScheduler()?.toString();
124-
if (!schedulerData || schedulerData.length === 0)
125-
return;
126-
127-
LogTo.Debug("Creating queue: " + queueName, true);
128-
await this.plugin.files.createIfNotExists(queueFile, schedulerData);
129-
await this.plugin.loadQueue(queueFile);
114+
const queueNameWithExt = queueName.withExtension(".md");
115+
const queueFile = normalizePath(
116+
[this.plugin.settings.queueFolderPath, queueNameWithExt].join("/")
117+
);
118+
if (await this.plugin.files.exists(queueFile)) {
119+
LogTo.Debug("Queue already exists!", true);
120+
return;
130121
}
131122

132-
showHideSchedulerSettings(value: "simple" | "afactor") {
133-
switch (value) {
134-
case "simple":
135-
this.intervalText.setDisabled(true);
136-
this.afactorText.setDisabled(true);
137-
this.intervalText.setValue("---");
138-
this.afactorText.setValue("---");
139-
return;
140-
case "afactor":
141-
this.intervalText.setDisabled(false);
142-
this.afactorText.setDisabled(false);
143-
this.intervalText.setValue("1");
144-
this.afactorText.setValue("2");
145-
return;
146-
default:
147-
throw new Error("Expected simple or afactor, got: " + value);
148-
}
123+
const schedulerData = this.createScheduler()?.toString();
124+
if (!schedulerData || schedulerData.length === 0) return;
125+
126+
LogTo.Debug("Creating queue: " + queueName, true);
127+
await this.plugin.files.createIfNotExists(queueFile, schedulerData);
128+
await this.plugin.loadQueue(queueFile);
129+
}
130+
131+
showHideSchedulerSettings(value: "simple" | "afactor") {
132+
switch (value) {
133+
case "simple":
134+
this.intervalText.setDisabled(true);
135+
this.afactorText.setDisabled(true);
136+
this.intervalText.setValue("---");
137+
this.afactorText.setValue("---");
138+
return;
139+
case "afactor":
140+
this.intervalText.setDisabled(false);
141+
this.afactorText.setDisabled(false);
142+
this.intervalText.setValue("1");
143+
this.afactorText.setValue("2");
144+
return;
145+
default:
146+
throw new Error("Expected simple or afactor, got: " + value);
149147
}
148+
}
150149
}

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

+10-11
Original file line numberDiff line numberDiff line change
@@ -23,19 +23,15 @@ export class FileSuggest extends TextInputSuggest<TFile> {
2323
const files: TFile[] = [];
2424

2525
for (const file of abstractFiles) {
26-
if (!(file instanceof TFile))
27-
continue;
26+
if (!(file instanceof TFile)) continue;
2827

29-
if (!(this.plugin.files.isDescendantOf(file, this.folder())))
30-
continue;
31-
32-
if (file.extension !== "md")
33-
continue
28+
if (!this.plugin.files.isDescendantOf(file, this.folder())) continue;
29+
30+
if (file.extension !== "md") continue;
3431

3532
const relPath = path.relative(this.folder().path, file.path);
36-
if (relPath.contains(inputStr))
37-
files.push(file);
38-
}
33+
if (relPath.contains(inputStr)) files.push(file);
34+
}
3935

4036
return files;
4137
}
@@ -45,7 +41,10 @@ export class FileSuggest extends TextInputSuggest<TFile> {
4541
}
4642

4743
selectSuggestion(file: TFile): void {
48-
this.inputEl.value = path.relative(this.plugin.settings.queueFolderPath, file.path)
44+
this.inputEl.value = path.relative(
45+
this.plugin.settings.queueFolderPath,
46+
file.path
47+
);
4948
this.inputEl.trigger("input");
5049
this.close();
5150
}

Diff for: src/views/modals.ts

+13-5
Original file line numberDiff line numberDiff line change
@@ -40,8 +40,12 @@ abstract class ReviewModal extends ModalBase {
4040
// Queue
4141

4242
contentEl.appendText("Queue: ");
43-
this.inputQueueField = new TextComponent(contentEl)
44-
.setPlaceholder(path.relative(this.plugin.settings.queueFolderPath, this.plugin.queue.queuePath));
43+
this.inputQueueField = new TextComponent(contentEl).setPlaceholder(
44+
path.relative(
45+
this.plugin.settings.queueFolderPath,
46+
this.plugin.queue.queuePath
47+
)
48+
);
4549
let folderFunc = () =>
4650
this.plugin.app.vault.getAbstractFileByPath(
4751
this.plugin.settings.queueFolderPath
@@ -114,9 +118,13 @@ abstract class ReviewModal extends ModalBase {
114118
}
115119

116120
getQueuePath() {
117-
const queue = this.inputQueueField.getValue() === ""
118-
? path.relative(this.plugin.settings.queueFolderPath, this.plugin.queue.queuePath)
119-
: this.inputQueueField.getValue().withExtension(".md");
121+
const queue =
122+
this.inputQueueField.getValue() === ""
123+
? path.relative(
124+
this.plugin.settings.queueFolderPath,
125+
this.plugin.queue.queuePath
126+
)
127+
: this.inputQueueField.getValue().withExtension(".md");
120128

121129
return normalizePath(
122130
[this.plugin.settings.queueFolderPath, queue].join("/")

Diff for: src/views/queue-modal.ts

+7-5
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
import { normalizePath, FuzzySuggestModal } from "obsidian";
2-
import * as path from 'path';
2+
import * as path from "path";
33
import { LogTo } from "src/logger";
44
import IW from "../main";
55

@@ -18,17 +18,19 @@ export class QueueLoadModal extends FuzzySuggestModal<string> {
1818
}
1919

2020
getItems(): string[] {
21-
const queueFolderPath = normalizePath(this.plugin.settings.queueFolderPath)
22-
const defaultQueue = path.relative(queueFolderPath, this.plugin.getDefaultQueuePath());
21+
const queueFolderPath = normalizePath(this.plugin.settings.queueFolderPath);
22+
const defaultQueue = path.relative(
23+
queueFolderPath,
24+
this.plugin.getDefaultQueuePath()
25+
);
2326
const folder = this.plugin.files.getTFolder(queueFolderPath);
2427
if (folder) {
2528
let files = this.plugin.app.vault
2629
.getMarkdownFiles()
2730
.filter((file) => this.plugin.files.isDescendantOf(file, folder))
2831
.map((file) => path.relative(queueFolderPath, file.path));
2932

30-
if (!files.some((f) => f === defaultQueue))
31-
files.push(defaultQueue);
33+
if (!files.some((f) => f === defaultQueue)) files.push(defaultQueue);
3234
return files;
3335
}
3436

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

+10-7
Original file line numberDiff line numberDiff line change
@@ -123,7 +123,9 @@ export class IWSettingsTab extends PluginSettingTab {
123123
}
124124

125125
const validDates: string[] = inputDates
126-
.filter(([_, date]: [string, any]) => date != null && date.date)
126+
.filter(
127+
([_, date]: [string, any]) => date != null && date.date
128+
)
127129
.map(([s, _]: [string, Date]) => s);
128130

129131
if (inputDates.length !== validDates.length) {
@@ -134,12 +136,13 @@ export class IWSettingsTab extends PluginSettingTab {
134136
);
135137
}
136138

137-
const dateOptionsRecord: Record<string, string> = validDates
138-
.reduce((acc, x) =>
139-
{
140-
acc[x] = x;
141-
return acc;
142-
}, {} as Record<string, string>);
139+
const dateOptionsRecord: Record<
140+
string,
141+
string
142+
> = validDates.reduce((acc, x) => {
143+
acc[x] = x;
144+
return acc;
145+
}, {} as Record<string, string>);
143146

144147
LogTo.Debug(
145148
"Setting dropdown date options to " +

Diff for: src/views/status-bar.ts

+3-1
Original file line numberDiff line numberDiff line change
@@ -39,7 +39,9 @@ export class StatusBar {
3939

4040
updateCurrentQueue(queuePath: string) {
4141
const normalized = normalizePath(queuePath);
42-
const name = path.relative(this.plugin.settings.queueFolderPath, normalized).rtrim(".md")
42+
const name = path
43+
.relative(this.plugin.settings.queueFolderPath, normalized)
44+
.rtrim(".md");
4345
this.queueText.innerText =
4446
name && name.length > 0 ? "Queue: " + name : "Queue: None";
4547
}

0 commit comments

Comments
 (0)