fix(setting-tab): cleanup

This commit is contained in:
EloiMusk 2023-03-10 09:08:28 +01:00
parent 0839a84f0e
commit 21fe78bfd7
No known key found for this signature in database
GPG key ID: A59863E13934DD4F

View file

@ -139,17 +139,15 @@ export class SettingTab extends PluginSettingTab {
this.generateLevelAliasList(this.plugin.settings, levelAliasesList, [saveButton]); this.generateLevelAliasList(this.plugin.settings, levelAliasesList, [saveButton]);
containerEl.append(saveButton); containerEl.append(saveButton);
saveButton.addEventListener('click', () => { saveButton.addEventListener('click', async () => {
if (!this.isValid(levelAliasesList)) { if (!this.isValid(levelAliasesList)) {
return; return;
} }
this.setAliases(this.plugin.settings, levelAliasesList); this.setAliases(this.plugin.settings, levelAliasesList);
this.plugin.saveSettings().then(() => { await this.plugin.saveSettings();
this.plugin.loadSettings().then(() => { await this.plugin.loadSettings();
new Notice('Settings saved successfully!'); new Notice('Settings saved successfully!');
this.modified = false; this.modified = false;
});
});
}); });
} }
@ -196,7 +194,7 @@ export class SettingTab extends PluginSettingTab {
return Date.now().toString(36) + Math.random().toString(36); return Date.now().toString(36) + Math.random().toString(36);
} }
addPreset = (name: string, settings: PrioPluginSettings, presetList: HTMLOListElement) => { addPreset = async (name: string, settings: PrioPluginSettings, presetList: HTMLOListElement) => {
if (!name || !settings || !this.presetIsValid(name, settings.presets ?? [], this.plugin.settings.presets?.length ?? 0 - 1)) { if (!name || !settings || !this.presetIsValid(name, settings.presets ?? [], this.plugin.settings.presets?.length ?? 0 - 1)) {
return; return;
} }
@ -221,11 +219,10 @@ export class SettingTab extends PluginSettingTab {
}]; }];
} }
this.generatePresetList(this.plugin.settings.presets, presetList); this.generatePresetList(this.plugin.settings.presets, presetList);
this.plugin.saveSettings().then(() => { await this.plugin.saveSettings()
this.plugin.loadSettings().then(() => { await this.plugin.loadSettings()
new Notice('Preset applied successfully!'); new Notice('Preset applied successfully!');
});
});
this.display(); this.display();
} }
@ -421,19 +418,16 @@ class SaveConfirm extends Modal {
cls: ['btn', 'mod-danger'], cls: ['btn', 'mod-danger'],
}); });
saveButton.addEventListener('click', () => { saveButton.addEventListener('click', async () => {
this.settingsTab.plugin.saveSettings().then(() => { await this.settingsTab.plugin.saveSettings()
this.settingsTab.plugin.loadSettings().then(() => { await this.settingsTab.plugin.loadSettings()
new Notice('Settings saved successfully!'); new Notice('Settings saved successfully!');
});
});
this.close(); this.close();
}); });
discardButton.addEventListener('click', () => { discardButton.addEventListener('click', async () => {
this.settingsTab.plugin.loadSettings().then(() => { await this.settingsTab.plugin.loadSettings()
new Notice('Settings discarded successfully!'); new Notice('Settings discarded successfully!');
});
this.close(); this.close();
}); });
@ -500,8 +494,8 @@ class AddPresetModal extends Modal {
cls: ['btn'], cls: ['btn'],
}); });
addButton.addEventListener('click', () => { addButton.addEventListener('click', async () => {
this.settingsTab.addPreset(presetName, this.settingsTab.plugin.settings, this.presetsList); await this.settingsTab.addPreset(presetName, this.settingsTab.plugin.settings, this.presetsList);
this.close(); this.close();
}); });