Skip to content

Commit

Permalink
fix(settings): allow to keep the old behavior for settings tab
Browse files Browse the repository at this point in the history
aka close the settings tab and reopen always on the github configuration tab
  • Loading branch information
Mara-Li committed Oct 19, 2023
1 parent 489b443 commit 815cb0f
Show file tree
Hide file tree
Showing 4 changed files with 37 additions and 4 deletions.
4 changes: 4 additions & 0 deletions src/i18n/locales/en.json
Original file line number Diff line number Diff line change
Expand Up @@ -455,6 +455,10 @@
"desc": "On mobile, it can be hard to debug the plugin. Enable this option to log every error in a Notice.",
"title": "Notice every error"
},
"saveTab": {
"desc": "Allows you to reopen the settings on the previously used tab",
"title": "Save tab"
},
"shareKey": {
"all": {
"desc": "Allow to share all file and ignore the share key state",
Expand Down
4 changes: 4 additions & 0 deletions src/i18n/locales/fr.json
Original file line number Diff line number Diff line change
Expand Up @@ -455,6 +455,10 @@
"desc": "Sur mobile, il peut être difficile de debug le module. Activer cette option pour notifier toutes les erreurs via une notification Obsidian.",
"title": "Notifier toutes les erreurs"
},
"saveTab": {
"desc": "Permet de rouvrir les paramètres sur l'onglet précédemment utilisé",
"title": "Sauvegarder l'onglet"
},
"shareKey": {
"all": {
"desc": "Autoriser le partage de tous les fichiers et ignorer l'état de la clé de partage",
Expand Down
32 changes: 28 additions & 4 deletions src/settings.ts
Original file line number Diff line number Diff line change
Expand Up @@ -40,6 +40,14 @@ export class GithubPublisherSettingsTab extends PluginSettingTab {
const { containerEl } = this;
containerEl.empty();
containerEl.addClass("github-publisher");
const defaultTabId = EnumbSettingsTabId.github;
let savedId = this.settings.tabsID ?? defaultTabId;
if (this.settings.plugin.saveTabId !== undefined && !this.settings.plugin.saveTabId) { //real false
this.settings.tabsID = defaultTabId;
savedId = defaultTabId;
this.plugin.saveSettings();
}

const PUBLISHER_TABS = {
"github-configuration": {
name: i18next.t("settings.github.title"),
Expand Down Expand Up @@ -110,7 +118,7 @@ export class GithubPublisherSettingsTab extends PluginSettingTab {
cls: "settings-tab-name",
text: tabInfo.name,
});
if (tabID === this.settings.tabsID ?? EnumbSettingsTabId.github)
if (tabID === savedId)
tabEl.addClass("settings-tab-active");

tabEl.addEventListener("click", async () => {
Expand All @@ -125,7 +133,7 @@ export class GithubPublisherSettingsTab extends PluginSettingTab {
this.settingsPage = containerEl.createEl("div", {
cls: "settings-tab-page",
});
this.renderSettingsPage(this.settings.tabsID ?? EnumbSettingsTabId.github);
this.renderSettingsPage(savedId);


}
Expand All @@ -135,8 +143,10 @@ export class GithubPublisherSettingsTab extends PluginSettingTab {
* @param {string} tabId - to know which tab to render
*/
async renderSettingsPage(tabId: string | EnumbSettingsTabId) {
this.settings.tabsID = tabId as EnumbSettingsTabId;
await this.plugin.saveSettings();
if (this.settings.plugin.saveTabId || this.settings.plugin.saveTabId === undefined) {
this.settings.tabsID = tabId as EnumbSettingsTabId;
await this.plugin.saveSettings();
}
this.settingsPage.empty();
switch (tabId) {
case "github-configuration":
Expand Down Expand Up @@ -1132,6 +1142,20 @@ export class GithubPublisherSettingsTab extends PluginSettingTab {
})
);

new Setting(this.settingsPage)
.setName(i18next.t("settings.plugin.saveTab.title"))
.setDesc(i18next.t("settings.plugin.saveTab.desc"))
.addToggle((toggle) =>
toggle
.setValue(pluginSettings.saveTabId ?? true)
.onChange(async (value) => {
pluginSettings.saveTabId = value;
this.settings.tabsID = value ? EnumbSettingsTabId.plugin : EnumbSettingsTabId.github;
await this.plugin.saveSettings();
})
);


this.settingsPage.createEl("h4", {text: i18next.t("settings.plugin.head.log")});

new Setting(this.settingsPage)
Expand Down
1 change: 1 addition & 0 deletions src/settings/interface.ts
Original file line number Diff line number Diff line change
Expand Up @@ -143,6 +143,7 @@ export interface GitHubPublisherSettings {
dev?: boolean;
displayModalRepoEditing: boolean;
migrated?: boolean;
saveTabId?: boolean;

}
}
Expand Down

0 comments on commit 815cb0f

Please sign in to comment.