import React, { useEffect, useState } from 'react'; import Homepage, { Footer, Header } from './Homepage'; import Download from './Download'; import Help from './Help'; import Compare from './Compare.tsx'; import { compare } from './compare.js'; import Legal from './Legal'; import Research from './Research'; import NotFound from './NotFound'; const routes = { '/': 'Inkspring · Craft and schedule social posts on your Mac', '/help': 'Help · Inkspring', '/compare': compare.title, '/download': 'Download and install Inkspring for Mac', '/privacy': 'Privacy · Inkspring', '/app-notices': 'App notices · Inkspring', '/research': 'Research · Inkspring', }; function routePath(pathname: string) { return pathname.replace(/\/$/, '') || '/'; } export function App({ pathname = '/' }: { pathname?: string }) { const [path, setPath] = useState(() => routePath(pathname)); useEffect(() => { const restore = () => setPath(routePath(location.pathname)); const navigate = (event: MouseEvent) => { if (event.defaultPrevented || event.button !== 0 || event.metaKey || event.ctrlKey || event.shiftKey || event.altKey || !(event.target instanceof Element)) return; const link = event.target.closest('a[href]'); if (!link || link.hasAttribute('download') || (link.target && link.target !== '_self')) return; const url = new URL(link.href); const destination = routePath(url.pathname); if (url.origin !== location.origin || url.search || !Object.hasOwn(routes, destination) || destination === routePath(location.pathname)) return; event.preventDefault(); // Let the current page's click handlers finish before changing the URL. queueMicrotask(() => { history.pushState(null, '', url); setPath(destination); window.scrollTo({ top: 0, behavior: 'instant' }); }); }; window.addEventListener('popstate', restore); window.addEventListener('click', navigate); return () => { window.removeEventListener('popstate', restore); window.removeEventListener('click', navigate); }; }, []); useEffect(() => { document.title = routes[path as keyof typeof routes] ?? 'Page not found · Inkspring'; const fragment = location.hash.slice(1); if (fragment) { try { document.getElementById(decodeURIComponent(fragment))?.scrollIntoView({ behavior: 'instant' }); } catch { /* Ignore an invalid encoded fragment. */ } } }, [path]); return
{path === '/' ? : path === '/help' ? : path === '/compare' ? : path === '/download' ? : path === '/research' ? : path === '/privacy' || path === '/app-notices' ? : }
; }