humanai-web/src/App.tsx

73 lines
2.5 KiB
TypeScript
Raw Normal View History

import React, { useEffect } from 'react';
import Header from './components/Header';
import Hero from './components/Hero';
import About from './components/About';
import Offerings from './components/Offerings';
import WhyHumanAI from './components/WhyHumanAI';
import Process from './components/Process';
import Audience from './components/Audience';
import CTASection from './components/CTASection';
import Footer from './components/Footer';
import PrivacyPolicyPage from './components/PrivacyPolicyPage';
import PlatformPage from './components/PlatformPage';
import { useLang, stripLangPrefix } from './i18n';
import { usePathname } from './router';
function App() {
// Reactive, so the language switcher's pushState re-renders the tree instead
// of leaving a stale page under a changed URL.
const pathname = usePathname();
const lang = useLang();
// One route table for both languages: /en/privacy and /privacy both match
// '/privacy' here.
const route = stripLangPrefix(pathname);
// index.html ships lang="pl"; keep the document honest on the English routes
// (screen readers, translation prompts, search engines all read this).
useEffect(() => {
document.documentElement.lang = lang;
}, [lang]);
// The landing sections are client-rendered, so when a /#section URL arrives
// with the initial request — following "Oferta"/"Kontakt" from /privacy or
// /platforma — the browser resolves the fragment before the target exists and
// leaves the page at the top. Re-apply the scroll once the sections are
// mounted. In-page clicks never reach this: they are same-document fragment
// navigations that the browser handles natively (smoothly, via .scroll-smooth)
// without remounting App.
useEffect(() => {
if (route !== '/') return;
const id = window.location.hash.slice(1);
if (!id) return;
// Jump rather than smooth-scroll: this only runs on a fresh load, where
// animating the full page height would just be a slow detour.
document.getElementById(id)?.scrollIntoView({ behavior: 'auto' });
}, [route]);
if (route === '/privacy') {
return <PrivacyPolicyPage />;
}
if (route === '/platforma') {
return <PlatformPage />;
}
return (
<div className="min-h-screen bg-background selection:bg-primary selection:text-background">
<Header />
<main>
<Hero />
<About />
<Offerings />
<WhyHumanAI />
<Process />
<Audience />
<CTASection />
</main>
<Footer />
</div>
);
}
export default App;