Skip to content

Commit

Permalink
fix(core): wait for workspace list loading state
Browse files Browse the repository at this point in the history
  • Loading branch information
CatsJuice committed Apr 12, 2024
1 parent 5890565 commit 862267d
Showing 1 changed file with 17 additions and 3 deletions.
20 changes: 17 additions & 3 deletions packages/frontend/core/src/pages/index.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -41,7 +41,9 @@ export const Component = () => {
const { status } = useSession();
const workspaceManager = useService(WorkspaceManager);

const list = useLiveData(useService(WorkspaceListService).workspaceList$);
const workspaceListService = useService(WorkspaceListService);
const list = useLiveData(workspaceListService.workspaceList$);
const workspaceListStatus = useLiveData(workspaceListService.status$);

const { openPage } = useNavigateHelper();
const [searchParams] = useSearchParams();
Expand All @@ -62,9 +64,10 @@ export const Component = () => {
}, [openPage, workspaceManager]);

useLayoutEffect(() => {
if (list.length === 0) {
if (workspaceListStatus.loading) {
return;
}

// check is user logged in && has cloud workspace
if (
searchParams.get('initCloud') === 'true' &&
Expand All @@ -77,13 +80,24 @@ export const Component = () => {
}
}

if (list.length === 0) {
return;
}

// open last workspace
const lastId = localStorage.getItem('last_workspace_id');

const openWorkspace = list.find(w => w.id === lastId) ?? list[0];
openPage(openWorkspace.id, WorkspaceSubPath.ALL);
setNavigating(true);
}, [createCloudWorkspace, list, openPage, searchParams, status]);
}, [
createCloudWorkspace,
list,
openPage,
searchParams,
status,
workspaceListStatus.loading,
]);

useEffect(() => {
setCreating(true);
Expand Down

0 comments on commit 862267d

Please sign in to comment.