Skip to content

Commit bf0c4ef

Browse files
committed
refactor: ♻️ consistent method chaining
1 parent 418243d commit bf0c4ef

File tree

1 file changed

+44
-49
lines changed

1 file changed

+44
-49
lines changed

src/ui/SettingsTab.ts

Lines changed: 44 additions & 49 deletions
Original file line numberDiff line numberDiff line change
@@ -24,8 +24,7 @@ export class BratSettingsTab extends PluginSettingTab {
2424
'If enabled beta plugins will be automatically enabled after installtion by default. Note: you can toggle this on and off for each plugin in the "Add Plugin" form.',
2525
)
2626
.addToggle((cb: ToggleComponent) => {
27-
cb.setValue(this.plugin.settings.enableAfterInstall);
28-
cb.onChange(async (value: boolean) => {
27+
cb.setValue(this.plugin.settings.enableAfterInstall).onChange(async (value: boolean) => {
2928
this.plugin.settings.enableAfterInstall = value;
3029
await this.plugin.saveSettings();
3130
});
@@ -37,8 +36,7 @@ export class BratSettingsTab extends PluginSettingTab {
3736
"If enabled all beta plugins will be checked for updates each time Obsidian starts. Note: this does not update frozen version plugins.",
3837
)
3938
.addToggle((cb: ToggleComponent) => {
40-
cb.setValue(this.plugin.settings.updateAtStartup);
41-
cb.onChange(async (value: boolean) => {
39+
cb.setValue(this.plugin.settings.updateAtStartup).onChange(async (value: boolean) => {
4240
this.plugin.settings.updateAtStartup = value;
4341
await this.plugin.saveSettings();
4442
});
@@ -48,8 +46,7 @@ export class BratSettingsTab extends PluginSettingTab {
4846
.setName("Auto-update themes at startup")
4947
.setDesc("If enabled all beta themes will be checked for updates each time Obsidian starts.")
5048
.addToggle((cb: ToggleComponent) => {
51-
cb.setValue(this.plugin.settings.updateThemesAtStartup);
52-
cb.onChange(async (value: boolean) => {
49+
cb.setValue(this.plugin.settings.updateThemesAtStartup).onChange(async (value: boolean) => {
5350
this.plugin.settings.updateThemesAtStartup = value;
5451
await this.plugin.saveSettings();
5552
});
@@ -72,8 +69,7 @@ export class BratSettingsTab extends PluginSettingTab {
7269
});
7370

7471
new Setting(containerEl).addButton((cb: ButtonComponent) => {
75-
cb.setButtonText("Add beta plugin");
76-
cb.onClick(() => {
72+
cb.setButtonText("Add beta plugin").onClick(() => {
7773
this.plugin.betaPlugins.displayAddNewPluginModal(true, true);
7874
});
7975
});
@@ -93,66 +89,68 @@ export class BratSettingsTab extends PluginSettingTab {
9389
btn
9490
.setIcon("sync")
9591
.setTooltip("Check and update plugin")
96-
.setClass("mod-cta")
9792
.onClick(async () => {
98-
const updated = await this.plugin.betaPlugins.updatePlugin(p, false, true, false, bp?.token);
93+
await this.plugin.betaPlugins.updatePlugin(p, false, true, false, bp?.token);
9994
});
10095
});
10196
}
10297

10398
// Container for the edit and removal buttons
10499
pluginSettingContainer
105100
.addButton((btn: ButtonComponent) => {
106-
btn.setIcon("edit");
107-
btn.setTooltip("Change version");
108-
btn.onClick(() => {
109-
this.plugin.betaPlugins.displayAddNewPluginModal(true, true, p, bp?.version, bp?.token);
110-
this.plugin.app.setting.updatePluginSection();
111-
});
101+
btn
102+
.setIcon("edit")
103+
.setTooltip("Change version")
104+
.onClick(() => {
105+
this.plugin.betaPlugins.displayAddNewPluginModal(true, true, p, bp?.version, bp?.token);
106+
this.plugin.app.setting.updatePluginSection();
107+
});
112108
})
113109
.addButton((btn: ButtonComponent) => {
114-
btn.setIcon("cross");
115-
btn.setTooltip("Remove this beta plugin");
116-
btn.setWarning();
117-
btn.onClick(() => {
118-
if (btn.buttonEl.textContent === "") btn.setButtonText("Click once more to confirm removal");
119-
else {
120-
const { buttonEl } = btn;
121-
const { parentElement } = buttonEl;
122-
if (parentElement?.parentElement) {
123-
parentElement.parentElement.remove();
124-
this.plugin.betaPlugins.deletePlugin(p);
110+
btn
111+
.setIcon("cross")
112+
.setTooltip("Remove this beta plugin")
113+
.setWarning()
114+
.onClick(() => {
115+
if (btn.buttonEl.textContent === "") {
116+
btn.setButtonText("Click once more to confirm removal");
117+
} else {
118+
const { buttonEl } = btn;
119+
const { parentElement } = buttonEl;
120+
if (parentElement?.parentElement) {
121+
parentElement.parentElement.remove();
122+
this.plugin.betaPlugins.deletePlugin(p);
123+
}
125124
}
126-
}
127-
});
125+
});
128126
});
129127
}
130128

131129
new Setting(containerEl).setName("Beta themes list").setHeading();
132130

133131
new Setting(containerEl).addButton((cb: ButtonComponent) => {
134-
cb.setButtonText("Add beta theme");
135-
cb.onClick(() => {
132+
cb.setButtonText("Add beta theme").onClick(() => {
136133
this.plugin.app.setting.close();
137134
new AddNewTheme(this.plugin).open();
138135
});
139136
});
140137

141138
for (const bp of this.plugin.settings.themesList) {
142139
new Setting(containerEl).setName(createLink(bp.repo)).addButton((btn: ButtonComponent) => {
143-
btn.setIcon("cross");
144-
btn.setTooltip("Delete this beta theme");
145-
btn.onClick(() => {
146-
if (btn.buttonEl.textContent === "") btn.setButtonText("Click once more to confirm removal");
147-
else {
148-
const { buttonEl } = btn;
149-
const { parentElement } = buttonEl;
150-
if (parentElement?.parentElement) {
151-
parentElement.parentElement.remove();
152-
themeDelete(this.plugin, bp.repo);
140+
btn
141+
.setIcon("cross")
142+
.setTooltip("Delete this beta theme")
143+
.onClick(() => {
144+
if (btn.buttonEl.textContent === "") btn.setButtonText("Click once more to confirm removal");
145+
else {
146+
const { buttonEl } = btn;
147+
const { parentElement } = buttonEl;
148+
if (parentElement?.parentElement) {
149+
parentElement.parentElement.remove();
150+
themeDelete(this.plugin, bp.repo);
151+
}
153152
}
154-
}
155-
});
153+
});
156154
});
157155
}
158156

@@ -173,8 +171,7 @@ export class BratSettingsTab extends PluginSettingTab {
173171
.setName("Enable logging")
174172
.setDesc("Plugin updates will be logged to a file in the log file.")
175173
.addToggle((cb: ToggleComponent) => {
176-
cb.setValue(this.plugin.settings.loggingEnabled);
177-
cb.onChange(async (value: boolean) => {
174+
cb.setValue(this.plugin.settings.loggingEnabled).onChange(async (value: boolean) => {
178175
this.plugin.settings.loggingEnabled = value;
179176
await this.plugin.saveSettings();
180177
});
@@ -196,8 +193,7 @@ export class BratSettingsTab extends PluginSettingTab {
196193
.setName("Enable verbose logging")
197194
.setDesc("Get a lot more information in the log.")
198195
.addToggle((cb: ToggleComponent) => {
199-
cb.setValue(this.plugin.settings.loggingVerboseEnabled);
200-
cb.onChange(async (value: boolean) => {
196+
cb.setValue(this.plugin.settings.loggingVerboseEnabled).onChange(async (value: boolean) => {
201197
this.plugin.settings.loggingVerboseEnabled = value;
202198
await this.plugin.saveSettings();
203199
});
@@ -207,8 +203,7 @@ export class BratSettingsTab extends PluginSettingTab {
207203
.setName("Debugging mode")
208204
.setDesc("Atomic Bomb level console logging. Can be used for troubleshoting and development.")
209205
.addToggle((cb: ToggleComponent) => {
210-
cb.setValue(this.plugin.settings.debuggingMode);
211-
cb.onChange(async (value: boolean) => {
206+
cb.setValue(this.plugin.settings.debuggingMode).onChange(async (value: boolean) => {
212207
this.plugin.settings.debuggingMode = value;
213208
await this.plugin.saveSettings();
214209
});

0 commit comments

Comments
 (0)