/** * The app: reads the index, then shows the view the route names. */ import { useEffect } from 'preact/hooks'; import type { StoreIndex } from '../format/store.ts'; import { Footer, Header } from './components/layout.tsx'; import { Empty, Failure, Loading } from './components/states.tsx'; import { useResource } from './hooks/use-resource.ts'; import { replaceRoute, useRoute } from './hooks/use-route.ts'; import { brandingOf, loadBranding, loadIndex, MissingFileError } from './lib/data.ts'; import type { Route } from './lib/route.ts'; import { redirectOf } from './lib/route.ts'; import { CaseView } from './views/case.tsx'; import { Compare } from './views/compare.tsx'; import { NotFound } from './views/not-found.tsx'; import { Results } from './views/results.tsx'; import { RunView } from './views/run.tsx'; import { Runs } from './views/runs.tsx'; import { TrialView } from './views/trial.tsx'; /** * The app. * * @returns The page. */ export function App() { const { route, hash } = useRoute(); const resource = useResource('index', loadIndex); const index = resource.state === 'ready' ? resource.value : undefined; const loaded = useResource('branding', loadBranding); const branding = loaded.state === 'ready' ? loaded.value : brandingOf(undefined); useEffect(() => { document.title = branding.title; }, [branding.title]); // An address of an earlier dashboard goes to where its view lives now. const redirect = redirectOf(hash); useEffect(() => { if (redirect !== undefined) replaceRoute(redirect); }, [redirect]); // A new view starts at the top; a filter change keeps the place. const path = hash.split('?')[0]; useEffect(() => { if (path !== undefined) scrollTo(0, 0); }, [path]); return ( <>
{resource.state === 'loading' ? : null} {resource.state === 'error' ? : null} {index === undefined || redirect !== undefined ? null : ( )}