import { Navigate } from 'react-router-dom'; import { useEffect, useState } from 'react'; import { Loader2 } from 'lucide-react'; import Sidebar from './Sidebar'; import TopBar from './TopBar'; import { getRepoStatus } from '../../api/client'; import { useRepoStore } from '../../store/useRepoStore'; export default function PageWrapper({ title, subtitle, children, requireRepo = true, action }) { const { repoId, resetAll } = useRepoStore(); const [checkingRepo, setCheckingRepo] = useState(Boolean(requireRepo && repoId)); useEffect(() => { if (!requireRepo || !repoId) { setCheckingRepo(false); return undefined; } let cancelled = false; setCheckingRepo(true); getRepoStatus(repoId) .catch((error) => { if (!cancelled && error?.response?.status === 404) { resetAll(); } }) .finally(() => { if (!cancelled) setCheckingRepo(false); }); return () => { cancelled = true; }; }, [repoId, requireRepo, resetAll]); if (requireRepo && !repoId) { return ; } if (checkingRepo) { return (
Checking repository session
); } return (
{children}
); }