Repository Public
1import { NotFound, Shell, useLocation } from '@spweb/shared-ui';2import { chunk } from './chunk';3import { useT } from '@spweb/shared-ui/i18n/search';4import { Home } from './Home';5import { Mark } from './Logo';67// Editorial pages and their long texts are a separate chunk: the home and results pages never download them.8const About = chunk(() => import('./Pages').then((m) => m.About));9const Privacy = chunk(() => import('./Pages').then((m) => m.Privacy));10const ApiDoc = chunk(() => import('./Pages').then((m) => m.ApiDoc));11// The results page is its own chunk too. It is requested at once when the address is /search, and12// warmed during idle time on the home page, so the first search does not wait for it.13const Results = chunk(() => import('./Results').then((m) => m.Results));14if (window.location.pathname.replace(/\/+$/, '') === '/search') Results.preload();15else {16 const idle = (window as { requestIdleCallback?: (f: () => void) => number }).requestIdleCallback;17 if (idle) idle(() => Results.preload());18 else window.setTimeout(() => Results.preload(), 1200);19}2021function route(pathname: string) {22 switch (pathname.replace(/\/+$/, '') || '/') {23 case '/': return <Home />;24 case '/search': return <Results />;25 case '/about': return <About />;26 case '/privacy': return <Privacy />;27 case '/api': return <ApiDoc />;28 default: return <NotFound />;29 }30}3132export function App() {33 const { t } = useT();34 const { pathname } = useLocation();35 return (36 <Shell37 site="search"38 mark={(size) => <Mark size={size} />}39 brandLabel={t('brand.label')}40 tag={t('tag')}41 nav={[42 { href: '/about', label: t('nav.about') },43 { href: '/privacy', label: t('nav.privacy') },44 { href: '/api', label: t('nav.api') },45 ]}46 footer={<p>{t('foot.note')}</p>}47 >48 {route(pathname)}49 </Shell>50 );51}52