Line data Source code
1 : import { storeToRefs } from 'pinia'
2 :
3 : import { useTeamWorkspaceStore } from '@/platform/workspace/stores/teamWorkspaceStore'
4 :
5 2 : export function useWorkspaceSwitch() {
6 2 : const workspaceStore = useTeamWorkspaceStore()
7 2 : const { activeWorkspace } = storeToRefs(workspaceStore)
8 :
9 2 : async function switchWorkspace(workspaceId: string): Promise<boolean> {
10 2 : if (activeWorkspace.value?.id === workspaceId) {
11 0 : return true
12 : }
13 :
14 2 : try {
15 2 : await workspaceStore.switchWorkspace(workspaceId)
16 2 : return true
17 : } catch {
18 0 : return false
19 : }
20 : }
21 :
22 2 : return {
23 : switchWorkspace
24 : }
25 : }
|