Files
ComfyUI_frontend/src/stores/workspaceStateStore.ts
Chenlei Hu 966b1dd057 Extension API to add toast message (#491)
* Extension API to add toast message

* Update readme
2024-08-17 12:44:55 -04:00

46 lines
1.2 KiB
TypeScript

import { SidebarTabExtension, ToastManager } from '@/types/extensionTypes'
import { defineStore } from 'pinia'
import { useToastStore } from './toastStore'
interface WorkspaceState {
spinner: boolean
activeSidebarTab: string | null
sidebarTabs: SidebarTabExtension[]
}
export const useWorkspaceStore = defineStore('workspace', {
state: (): WorkspaceState => ({
spinner: false,
activeSidebarTab: null,
sidebarTabs: []
}),
getters: {
toast(): ToastManager {
return useToastStore()
}
},
actions: {
updateActiveSidebarTab(tabId: string) {
this.activeSidebarTab = tabId
},
registerSidebarTab(tab: SidebarTabExtension) {
this.sidebarTabs = [...this.sidebarTabs, tab]
},
unregisterSidebarTab(id: string) {
const index = this.sidebarTabs.findIndex((tab) => tab.id === id)
if (index !== -1) {
const tab = this.sidebarTabs[index]
if (tab.type === 'custom' && tab.destroy) {
tab.destroy()
}
const newSidebarTabs = [...this.sidebarTabs]
newSidebarTabs.splice(index, 1)
this.sidebarTabs = newSidebarTabs
}
},
getSidebarTabs() {
return [...this.sidebarTabs]
}
}
})