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AAiBzB,IAAI,CAACE,EAAE,CACxBuB,EAAiBC,aAAa,EAGhCvC,EAASsC,EAAiBzB,IAAI,CAACE,EAAE,CAAEC,EAAAA,EAAgBA,CAACC,GAAG,EAG7D,GACCC,KAAK,CAACC,IACLC,QAAQC,KAAK,CAAC,kCAAmCF,EACnD,GACCqB,OAAO,CAAC,KACPxD,EAAY,GACd,EACJ,EAAG,CAACiB,EAAYD,EAAUN,EAAkB,EAExCd,GAAcG,GACT,UAAC0D,EAAAA,CAAWA,CAAAA,CAAAA,GAKnB,uB,UACE,UAACC,MAAAA,CACCC,MAAO,CACLC,SAAU,QACVC,KAAM,MACNC,IAAK,KACP,E,SAEA,UAACC,EAAAA,EAAIA,CAAAA,CACHC,YAAa,CACXC,KAAM,EACR,EACAC,MAAO,UAACC,EAAAA,CAAqBA,CAAAA,CAAAA,GAC7BC,SAAQ,GACRC,eAAgB,CACdV,MAAO,CACLW,MAAO,IACPC,UAAW,wBACXC,aAAc,MACdC,UAAW,yBACXC,gBAAiB,+CACjBC,QAAS,WACX,CACF,E,SAEA,UAACjB,MAAAA,CAAAA,E,KAGL,UAACpE,EAAAA,CAAAA,G,EAGP,C","sources":["webpack://@affine/web/../core/src/pages/index.tsx"],"sourcesContent":["import { Menu } from '@affine/component/ui/menu';\nimport { apis } from '@affine/electron-api';\nimport { WorkspaceFlavour } from '@affine/env/workspace';\nimport {\n useLiveData,\n useService,\n WorkspacesService,\n} from '@toeverything/infra';\nimport {\n lazy,\n useCallback,\n useEffect,\n useLayoutEffect,\n useRef,\n useState,\n} from 'react';\nimport { type LoaderFunction, useSearchParams } from 'react-router-dom';\n\nimport {\n buildShowcaseWorkspace,\n createFirstAppData,\n} from '../bootstrap/first-app-data';\nimport { AppFallback } from '../components/affine/app-container';\nimport { UserWithWorkspaceList } from '../components/pure/workspace-slider-bar/user-with-workspace-list';\nimport { useNavigateHelper } from '../hooks/use-navigate-helper';\nimport { AuthService } from '../modules/cloud';\nimport { WorkspaceSubPath } from '../shared';\n\nconst AllWorkspaceModals = lazy(() =>\n import('../providers/modal-provider').then(({ AllWorkspaceModals }) => ({\n default: AllWorkspaceModals,\n }))\n);\n\nexport const loader: LoaderFunction = async () => {\n return null;\n};\n\nexport const Component = () => {\n // navigating and creating may be slow, to avoid flickering, we show workspace fallback\n const [navigating, setNavigating] = useState(true);\n const [creating, setCreating] = useState(false);\n const authService = useService(AuthService);\n const loggedIn = useLiveData(\n authService.session.status$.map(s => s === 'authenticated')\n );\n\n const workspacesService = useService(WorkspacesService);\n const list = useLiveData(workspacesService.list.workspaces$);\n const listIsLoading = useLiveData(workspacesService.list.isLoading$);\n\n const { openPage, jumpToPage } = useNavigateHelper();\n const [searchParams] = useSearchParams();\n\n const createOnceRef = useRef(false);\n\n const createCloudWorkspace = useCallback(() => {\n if (createOnceRef.current) return;\n createOnceRef.current = true;\n buildShowcaseWorkspace(\n workspacesService,\n WorkspaceFlavour.AFFINE_CLOUD,\n 'AFFiNE Cloud'\n )\n .then(({ meta, defaultDocId }) => {\n if (defaultDocId) {\n jumpToPage(meta.id, defaultDocId);\n } else {\n openPage(meta.id, WorkspaceSubPath.ALL);\n }\n })\n .catch(err => console.error('Failed to create cloud workspace', err));\n }, [jumpToPage, openPage, workspacesService]);\n\n useLayoutEffect(() => {\n if (!navigating) {\n return;\n }\n\n if (listIsLoading) {\n return;\n }\n\n // check is user logged in && has cloud workspace\n if (searchParams.get('initCloud') === 'true') {\n if (loggedIn) {\n if (list.every(w => w.flavour !== WorkspaceFlavour.AFFINE_CLOUD)) {\n createCloudWorkspace();\n return;\n }\n\n // open first cloud workspace\n const openWorkspace =\n list.find(w => w.flavour === WorkspaceFlavour.AFFINE_CLOUD) ??\n list[0];\n openPage(openWorkspace.id, WorkspaceSubPath.ALL);\n } else {\n return;\n }\n } else {\n if (list.length === 0) {\n setNavigating(false);\n return;\n }\n // open last workspace\n const lastId = localStorage.getItem('last_workspace_id');\n\n const openWorkspace = list.find(w => w.id === lastId) ?? list[0];\n openPage(openWorkspace.id, WorkspaceSubPath.ALL);\n }\n }, [\n createCloudWorkspace,\n list,\n openPage,\n searchParams,\n listIsLoading,\n loggedIn,\n navigating,\n ]);\n\n useEffect(() => {\n apis?.ui.pingAppLayoutReady().catch(console.error);\n }, []);\n\n useEffect(() => {\n setCreating(true);\n createFirstAppData(workspacesService)\n .then(createdWorkspace => {\n if (createdWorkspace) {\n if (createdWorkspace.defaultPageId) {\n jumpToPage(\n createdWorkspace.meta.id,\n createdWorkspace.defaultPageId\n );\n } else {\n openPage(createdWorkspace.meta.id, WorkspaceSubPath.ALL);\n }\n }\n })\n .catch(err => {\n console.error('Failed to create first app data', err);\n })\n .finally(() => {\n setCreating(false);\n });\n }, [jumpToPage, openPage, workspacesService]);\n\n if (navigating || creating) {\n return ;\n }\n\n // TODO(@eyhn): We need a no workspace page\n return (\n <>\n \n }\n noPortal\n contentOptions={{\n style: {\n width: 300,\n transform: 'translate(-50%, -50%)',\n borderRadius: '8px',\n boxShadow: 'var(--affine-shadow-2)',\n backgroundColor: 'var(--affine-background-overlay-panel-color)',\n padding: '16px 12px',\n },\n }}\n >\n
\n \n \n \n \n );\n};\n"],"names":["AllWorkspaceModals","lazy","then","default","loader","Component","navigating","setNavigating","useState","creating","setCreating","authService","useService","AuthService","loggedIn","useLiveData","session","status$","map","s","workspacesService","WorkspacesService","list","workspaces$","listIsLoading","isLoading$","openPage","jumpToPage","useNavigateHelper","searchParams","useSearchParams","createOnceRef","useRef","createCloudWorkspace","useCallback","current","buildShowcaseWorkspace","WorkspaceFlavour","AFFINE_CLOUD","meta","defaultDocId","id","WorkspaceSubPath","ALL","catch","err","console","error","useLayoutEffect","get","every","w","flavour","openWorkspace","find","length","lastId","localStorage","getItem","useEffect","apis","ui","pingAppLayoutReady","createFirstAppData","createdWorkspace","defaultPageId","finally","AppFallback","div","style","position","left","top","Menu","rootOptions","open","items","UserWithWorkspaceList","noPortal","contentOptions","width","transform","borderRadius","boxShadow","backgroundColor","padding"],"sourceRoot":""}