Sidebar tab API for extensions (#215)

* Add extensionManager to manage tabs

* Fix null bug

* nit
This commit is contained in:
Chenlei Hu
2024-07-24 21:31:59 -04:00
committed by GitHub
parent ebdd7b8e40
commit 19c70d95d3
9 changed files with 181 additions and 61 deletions

View File

@@ -0,0 +1,32 @@
import { defineStore } from "pinia";
interface WorkspaceState {
activeSidebarTab: string | null;
sidebarTabsOrder: string[]; // Array of tab IDs in order
}
export const useWorkspaceStore = defineStore("workspace", {
state: (): WorkspaceState => ({
activeSidebarTab: null,
sidebarTabsOrder: [],
}),
actions: {
updateActiveSidebarTab(tabId: string) {
this.activeSidebarTab = tabId;
},
updateSidebarOrder(newOrder: string[]) {
this.sidebarTabsOrder = newOrder;
},
serialize() {
return JSON.stringify({
activeSidebarTab: this.activeSidebarTab,
sidebarTabsOrder: this.sidebarTabsOrder,
});
},
deserialize(state: string) {
const parsedState = JSON.parse(state);
this.sidebarTabsOrder = parsedState.sidebarTabsOrder;
this.activeSidebarTab = parsedState.activeSidebarTab;
},
},
});