Recent requests/workspaces. Closes #1

This commit is contained in:
Gregory Schier
2023-10-28 18:46:54 -07:00
parent ac036ff814
commit 68fbb1a3ff
5 changed files with 101 additions and 8 deletions

View File

@@ -2,15 +2,23 @@ import { Navigate } from 'react-router-dom';
import { useAppRoutes } from '../hooks/useAppRoutes';
import { useWorkspaces } from '../hooks/useWorkspaces';
import { Heading } from './core/Heading';
import { useRecentWorkspaces } from '../hooks/useRecentWorkspaces';
export default function Workspaces() {
const routes = useAppRoutes();
const recentWorkspaceIds = useRecentWorkspaces();
const workspaces = useWorkspaces();
const workspace = workspaces[0];
if (workspace === undefined) {
const loading = workspaces.length === 0 && recentWorkspaceIds.length === 0;
if (loading) {
return null;
}
const workspaceId = recentWorkspaceIds[0] ?? workspaces[0]?.id ?? null;
if (workspaceId === null) {
return <Heading>There are no workspaces</Heading>;
}
return <Navigate to={routes.paths.workspace({ workspaceId: workspace.id })} />;
return <Navigate to={routes.paths.workspace({ workspaceId })} />;
}