SPB Git

Repository Public

Home.tsx 3.2 KB 64 lines tsx

1import {2  CountUp, Link, fmtBytes, fmtDateTime, fmtInt, fmtNum, fmtRel, isoDate, useDocumentTitle, useFetch, useSince,3} from '@spweb/shared-ui';4import { useT } from '@spweb/shared-ui/i18n/search';5import { Mark } from './Logo';6import { go } from './motion';7import { Omnibox } from './Omnibox';8import { RegionControl } from './region';9import { emptyQuery, pageUrl, type Stats } from './types';1011/** One page centred on the search bar; under it, a quiet strip of the real, live index figures. */12export function Home() {13  const { t, lang } = useT();14  // Real figures, re-read every ten seconds while the tab is visible. The page never waits for them.15  const stats = useFetch<Stats>('/v1/stats', 10000);16  const grown = useSince(stats.data?.documents);17  useDocumentTitle(t('meta.home'));18  const s = stats.data;19  const int = (v: number) => fmtInt(v, lang);20  return (21    <div className="home">22      <section className="wrap home-stage" aria-labelledby="home-h">23        <p className="home-logo"><Mark size={56} /><span className="wordmark">SPSearch</span></p>24        <h1 id="home-h" className="home-pos">{t('home.pos')}</h1>25        <Omnibox initial="" hero autoFocus onSearch={(q) => go(pageUrl(emptyQuery(q)))} />26        <div className="home-region"><RegionControl align="center" /></div>27        <div className="home-strip" aria-busy={stats.loading}>28          {s ? (29            <>30              <dl className="strip">31                <div><dt>{t('home.docs')}</dt><dd><CountUp value={s.documents} format={int} /></dd></div>32                <div><dt>{t('home.domains')}</dt><dd><CountUp value={s.domains} format={int} /></dd></div>33                <div><dt>{t('home.size')}</dt><dd>{fmtBytes(s.index_bytes, lang)}</dd></div>34                {s.updated_at != null && (35                  <div>36                    <dt>{t('home.updated')}</dt>37                    <dd><time dateTime={isoDate(s.updated_at)} title={fmtDateTime(s.updated_at, lang)}>{fmtRel(s.updated_at, lang)}</time></dd>38                  </div>39                )}40              </dl>41              <p className="home-coverage">42                {s.documents > 0 && s.domains > 0 && <span>{t('home.coverage', { avg: fmtNum(s.documents / s.domains, lang) })}</span>}43                {grown !== null && grown > 0 && (44                  <span className="home-since">{grown === 1 ? t('home.since1') : t('home.since', { n: int(grown) })}</span>45                )}46              </p>47            </>48          ) : stats.error ? (49            <p className="home-coverage">{t('home.statsFail')} <button type="button" className="linklike" onClick={stats.reload}>{t('retry')}</button></p>50          ) : null}51        </div>52      </section>53      <nav className="wrap home-links" aria-label={t('nav.about')}>54        <ul>55          <li><Link href="/about"><strong>{t('home.c1.t')}</strong><span>{t('home.c1.b')}</span></Link></li>56          <li><Link href="/privacy"><strong>{t('home.c2.t')}</strong><span>{t('home.c2.b')}</span></Link></li>57          <li><Link href="/about#levels"><strong>{t('home.c3.t')}</strong><span>{t('home.c3.b')}</span></Link></li>58          <li><a href="https://index.spboucher.ai/"><strong>{t('home.index.link')}</strong><span>{t('home.index.title')}</span></a></li>59        </ul>60      </nav>61    </div>62  );63}64
Files main
Menu

Theme