Skip to content

Commit

Permalink
chore: update tab profiles when a tab is deleted
Browse files Browse the repository at this point in the history
  • Loading branch information
jessebofill committed Jan 8, 2024
1 parent 5b4a775 commit 6584b03
Show file tree
Hide file tree
Showing 2 changed files with 29 additions and 13 deletions.
34 changes: 21 additions & 13 deletions src/state/TabMasterManager.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -441,6 +441,8 @@ export class TabMasterManager {
}
}
this.tabsMap.delete(tabId);
this.tabProfileManager?.onDeleteTab(tabId);
if (!this.tabProfileManager) LogController.error('Attempted to delete a tab before TabProfileManager has been initialized.', 'This should not be possible.');
this.updateAndSave();
}

Expand Down Expand Up @@ -487,12 +489,9 @@ export class TabMasterManager {
}

/**
* Loads the user's tabs from the backend.
* Other async load calls that don't need to be waited for when starting the plugin
*/
loadTabs = async () => {
this.initReactions();
const settings = await PythonInterop.getTabs();
//* We don't need to wait for these, since if we get the store ones, we don't care about them
asyncLoadOther() {
PythonInterop.getTags().then((res: TagResponse[] | Error) => {
if (res instanceof Error) {
LogController.log("TabMaster couldn't load tags settings");
Expand Down Expand Up @@ -523,21 +522,30 @@ export class TabMasterManager {
}
}
});
PythonInterop.getTabProfiles().then((res: TabProfileDictionary | Error) => {
if (res instanceof Error) {
LogController.log("TabMaster couldn't load tab profiles");
LogController.error(res.message);
} else {
this.tabProfileManager = new TabProfileManager(res);
}
});
}

/**
* Loads the user's tabs from the backend.
*/
loadTabs = async () => {
this.initReactions();
const settings = await PythonInterop.getTabs();
const profiles = await PythonInterop.getTabProfiles();

this.asyncLoadOther();

if (settings instanceof Error) {
LogController.log("TabMaster couldn't load tab settings");
LogController.error(settings.message);
return;
}
if (profiles instanceof Error) {
LogController.log("TabMaster couldn't load tab profiles");
LogController.error(profiles.message);
return;
}

this.tabProfileManager = new TabProfileManager(profiles);
TabErrorController.validateSettingsOnLoad((Object.keys(settings).length > 0) ? settings : defaultTabsSettings, this, this.finishLoadingTabs.bind(this));
};

Expand Down
8 changes: 8 additions & 0 deletions src/state/TabProfileManager.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -36,6 +36,14 @@ export class TabProfileManager {
tabMasterManager.reorderTabs(this.tabProfiles[tabProfileName]);
}

onDeleteTab(deletedId: string) {
Object.values(this.tabProfiles).forEach(tabs => {
const deletedIndex = tabs.findIndex(tabId => tabId === deletedId);
if (deletedIndex > -1) tabs.splice(deletedIndex, 1);
});
this.save();
}

/**
* Saves all changes made to the tab profiles.
*/
Expand Down

0 comments on commit 6584b03

Please sign in to comment.