MCPcopy
hub / github.com/simstudioai/sim / WorkspacePage

Function WorkspacePage

apps/sim/app/workspace/page.tsx:15–80  ·  view source on GitHub ↗
()

Source from the content-addressed store, hash-verified

13const logger = createLogger('WorkspacePage')
14
15export default function WorkspacePage() {
16 const router = useRouter()
17 const { data: session, isPending: isSessionPending } = useSession()
18 const isAuthenticated = !isSessionPending && !!session?.user
19 const hasRedirectedRef = useRef(false)
20
21 const { data, isLoading: isWorkspacesLoading } = useWorkspacesWithMetadata(isAuthenticated)
22
23 useEffect(() => {
24 if (isSessionPending || hasRedirectedRef.current) return
25
26 if (!session?.user) {
27 logger.info('User not authenticated, redirecting to login')
28 router.replace('/login')
29 return
30 }
31
32 if (isWorkspacesLoading || !data) return
33
34 hasRedirectedRef.current = true
35
36 const urlParams = new URLSearchParams(window.location.search)
37 const redirectWorkflowId = urlParams.get('redirect_workflow')
38
39 const { workspaces, lastActiveWorkspaceId, creationPolicy } = data
40
41 if (workspaces.length === 0) {
42 handleNoWorkspaces(router, creationPolicy)
43 return
44 }
45
46 const localRecentId = WorkspaceRecencyStorage.getMostRecent()
47 const findWorkspace = (id: string | null) =>
48 id ? workspaces.find((w) => w.id === id) : undefined
49
50 const targetWorkspace =
51 findWorkspace(localRecentId) ?? findWorkspace(lastActiveWorkspaceId) ?? workspaces[0]
52
53 if (redirectWorkflowId) {
54 handleWorkflowRedirect(redirectWorkflowId, targetWorkspace.id, router)
55 return
56 }
57
58 logger.info(`Redirecting to workspace: ${targetWorkspace.id}`)
59 router.replace(`/workspace/${targetWorkspace.id}/home`)
60 }, [session, isSessionPending, isWorkspacesLoading, data, router])
61
62 if (isSessionPending || isWorkspacesLoading) {
63 return (
64 <div className='flex h-screen w-full items-center justify-center'>
65 <div
66 className='size-[18px] animate-spin rounded-full'
67 style={{
68 background:
69 'conic-gradient(from 0deg, hsl(var(--muted-foreground)) 0deg 120deg, transparent 120deg 180deg, hsl(var(--muted-foreground)) 180deg 300deg, transparent 300deg 360deg)',
70 mask: 'radial-gradient(farthest-side, transparent calc(100% - 1.5px), black calc(100% - 1.5px))',
71 WebkitMask:
72 'radial-gradient(farthest-side, transparent calc(100% - 1.5px), black calc(100% - 1.5px))',

Callers

nothing calls this directly

Calls 9

useSessionFunction · 0.90
handleNoWorkspacesFunction · 0.85
findWorkspaceFunction · 0.85
handleWorkflowRedirectFunction · 0.85
infoMethod · 0.80
getMostRecentMethod · 0.80
replaceMethod · 0.65
getMethod · 0.65

Tested by

no test coverage detected