All files / src/routes __root.tsx

12.5% Statements 1/8
100% Branches 0/0
0% Functions 0/4
12.5% Lines 1/8

Press n or j to go to the next uncovered block, b, p or k for the previous block.

1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71                            1x                                                                                                                
import { useEffect, type ReactNode } from 'react'
import { HeadContent, Scripts, createRootRoute } from '@tanstack/react-router'
import CssBaseline from '@mui/material/CssBaseline'
import { ThemeProvider } from '@mui/material/styles'
import nunitoCss from '@fontsource-variable/nunito/wght.css?url'
import { m } from '#/paraglide/messages.js'
import { getLocale } from '#/paraglide/runtime.js'
import { ErrorView } from '#/components/ErrorView'
import { NotFoundView } from '#/components/NotFoundView'
import { installClientLogging } from '#/lib/client-log'
import { registerServiceWorker } from '#/lib/service-worker'
import { colors } from '#/theme/tokens'
import { themeFor } from '#/theme/theme'
 
export const Route = createRootRoute({
  head: () => ({
    meta: [
      { charSet: 'utf-8' },
      {
        name: 'viewport',
        content: 'width=device-width, initial-scale=1, viewport-fit=cover',
      },
      { name: 'theme-color', content: colors.cream },
      // The name under the icon on an iPhone's home screen.
      { name: 'apple-mobile-web-app-title', content: 'Kotivalo' },
      { title: 'Kotivalo' },
    ],
    links: [
      // Nunito is self-hosted (bundled from npm), so no request goes to Google.
      { rel: 'stylesheet', href: nunitoCss },
      // Installable app (public/; icons from scripts/generate-icons.ts).
      { rel: 'manifest', href: '/manifest.webmanifest' },
      { rel: 'icon', href: '/favicon.svg', type: 'image/svg+xml' },
      { rel: 'apple-touch-icon', href: '/icons/apple-touch-icon.png' },
    ],
  }),
  shellComponent: RootDocument,
  errorComponent: ErrorView,
  // Every address that matches no page (spec: "Showing that a page was not
  // found").
  notFoundComponent: () => (
    <NotFoundView
      title={m.not_found_title()}
      text={m.not_found_text()}
      backLabel={m.not_found_home()}
    />
  ),
})
 
function RootDocument({ children }: { children: ReactNode }) {
  const locale = getLocale()
  useEffect(() => {
    installClientLogging()
    registerServiceWorker()
  }, [])
  return (
    <html lang={locale}>
      <head>
        <HeadContent />
      </head>
      <body>
        <ThemeProvider theme={themeFor(locale)}>
          <CssBaseline />
          {children}
        </ThemeProvider>
        <Scripts />
      </body>
    </html>
  )
}