- rebuild the public site on the Next.js App Router with static export, per-section SEO pages, metadata, sitemap, robots and a generated OG image - add full-screen scroll-snap regions, staged scroll reveals, a hash-free tab navigation with a sliding indicator and region-by-region menu scrolling - replace the theme text toggle with animated sun/moon icons - restructure the CRM API into config, middleware, models, routes, services and utils layers - redesign the CRM shell with a single surface, tab rail, full-width blurred DataTable, record dialogs and mask-based icons - update Docker/Nginx publishing, Makefile targets, shared UI polish and docs
254 lines
8.4 KiB
TypeScript
254 lines
8.4 KiB
TypeScript
"use client";
|
|
|
|
import Link from "next/link";
|
|
import { usePathname, useRouter } from "next/navigation";
|
|
import {
|
|
useCallback,
|
|
useEffect,
|
|
useLayoutEffect,
|
|
useRef,
|
|
useState,
|
|
type MouseEvent,
|
|
} from "react";
|
|
import { cn } from "@cohaise/ui";
|
|
import { useLanguage } from "../contexts/LanguageContext";
|
|
import {
|
|
scrollToSection,
|
|
setPendingSection,
|
|
takePendingSection,
|
|
} from "../lib/gsap";
|
|
import { ThemeToggle } from "./ThemeToggle";
|
|
|
|
const links = [
|
|
{ id: "services", path: "/services", key: "nav.services" },
|
|
{ id: "demos", path: "/demos", key: "nav.demos" },
|
|
{ id: "stack", path: "/stack", key: "nav.stack" },
|
|
{ id: "about", path: "/about", key: "nav.about" },
|
|
{ id: "contact", path: "/contact", key: "nav.contact" },
|
|
] as const;
|
|
|
|
type SectionId = (typeof links)[number]["id"];
|
|
type NavLink = (typeof links)[number];
|
|
|
|
const normalize = (path: string): string =>
|
|
path !== "/" ? path.replace(/\/+$/, "") : path;
|
|
|
|
/*
|
|
Durée pendant laquelle le suivi du scroll est suspendu après un clic : le
|
|
temps que GSAP atteigne la région sans que l'indicateur ne revienne en
|
|
arrière. Une fois le défilement fini, l'onglet cliqué reste donc actif
|
|
(utile pour « À propos », qui partage la région de « Stack »).
|
|
*/
|
|
const NAV_LOCK = 1400;
|
|
|
|
interface Indicator {
|
|
left: number;
|
|
width: number;
|
|
}
|
|
|
|
export const Header = () => {
|
|
const { t, lang, setLang } = useLanguage();
|
|
const pathname = usePathname();
|
|
const router = useRouter();
|
|
const current = normalize(pathname);
|
|
|
|
const navRef = useRef<HTMLDivElement>(null);
|
|
const tabRefs = useRef(new Map<SectionId, HTMLAnchorElement>());
|
|
const lockUntil = useRef(0);
|
|
const [active, setActive] = useState<SectionId | null>(null);
|
|
const [indicator, setIndicator] = useState<Indicator | null>(null);
|
|
|
|
/** Région qui occupe la bande centrale du viewport. */
|
|
const regionAt = useCallback((): SectionId | null => {
|
|
const marker = window.innerHeight * 0.45;
|
|
let found: SectionId | null = null;
|
|
|
|
for (const link of links) {
|
|
const element = document.getElementById(link.id);
|
|
if (!element) continue;
|
|
const rect = element.getBoundingClientRect();
|
|
if (rect.top <= marker && rect.bottom > marker) found = link.id;
|
|
}
|
|
|
|
return found;
|
|
}, []);
|
|
|
|
/** Aligne la pastille glissante sur l'onglet actif. */
|
|
const measure = useCallback(() => {
|
|
const nav = navRef.current;
|
|
const tab = active ? tabRefs.current.get(active) : undefined;
|
|
if (!nav || !tab) {
|
|
setIndicator(null);
|
|
return;
|
|
}
|
|
|
|
const navRect = nav.getBoundingClientRect();
|
|
const tabRect = tab.getBoundingClientRect();
|
|
setIndicator({ left: tabRect.left - navRect.left, width: tabRect.width });
|
|
}, [active]);
|
|
|
|
useLayoutEffect(() => {
|
|
measure();
|
|
}, [measure, lang]);
|
|
|
|
useEffect(() => {
|
|
const nav = navRef.current;
|
|
if (!nav) return;
|
|
|
|
const observer = new ResizeObserver(measure);
|
|
observer.observe(nav);
|
|
|
|
// Les libellés changent de largeur quand la police arrive.
|
|
document.fonts?.ready.then(measure).catch(() => {});
|
|
|
|
return () => observer.disconnect();
|
|
}, [measure]);
|
|
|
|
/*
|
|
Sur l'accueil, l'onglet actif suit la région visible. Depuis une page SEO
|
|
autonome, il suit le chemin courant ; au retour, la région mémorisée est
|
|
rejointe sans passer par un `#`.
|
|
*/
|
|
useEffect(() => {
|
|
if (current !== "/") {
|
|
const match = links.find((link) => link.path === current);
|
|
setActive(match?.id ?? null);
|
|
return;
|
|
}
|
|
|
|
let frame = 0;
|
|
const pending = takePendingSection();
|
|
const target = pending
|
|
? links.find((link) => link.id === pending)
|
|
: undefined;
|
|
|
|
if (target) {
|
|
setActive(target.id);
|
|
lockUntil.current = Date.now() + NAV_LOCK;
|
|
// Deux frames : laisser Next monter la page d'accueil et poser les régions.
|
|
frame = requestAnimationFrame(() => {
|
|
frame = requestAnimationFrame(() => {
|
|
const duration = scrollToSection(`#${target.id}`);
|
|
lockUntil.current = Date.now() + Math.max(NAV_LOCK, duration + 400);
|
|
});
|
|
});
|
|
} else {
|
|
setActive(regionAt());
|
|
}
|
|
|
|
const onScroll = () => {
|
|
if (Date.now() < lockUntil.current) return;
|
|
setActive(regionAt());
|
|
};
|
|
|
|
window.addEventListener("scroll", onScroll, { passive: true });
|
|
window.addEventListener("resize", onScroll);
|
|
|
|
return () => {
|
|
cancelAnimationFrame(frame);
|
|
window.removeEventListener("scroll", onScroll);
|
|
window.removeEventListener("resize", onScroll);
|
|
};
|
|
}, [current, regionAt]);
|
|
|
|
const goTo = (event: MouseEvent<HTMLAnchorElement>, link: NavLink) => {
|
|
if (current !== "/") {
|
|
event.preventDefault();
|
|
setPendingSection(link.id);
|
|
router.push("/");
|
|
return;
|
|
}
|
|
|
|
event.preventDefault();
|
|
lockUntil.current = Date.now() + NAV_LOCK;
|
|
setActive(link.id);
|
|
const duration = scrollToSection(`#${link.id}`);
|
|
lockUntil.current = Date.now() + Math.max(NAV_LOCK, duration + 400);
|
|
};
|
|
|
|
const goHome = (event: MouseEvent<HTMLAnchorElement>) => {
|
|
if (current !== "/") return;
|
|
event.preventDefault();
|
|
lockUntil.current = Date.now() + NAV_LOCK;
|
|
setActive(null);
|
|
const duration = scrollToSection("#top");
|
|
lockUntil.current = Date.now() + Math.max(NAV_LOCK, duration + 400);
|
|
};
|
|
|
|
return (
|
|
<header className="sticky top-0 z-40 border-b border-border/60 bg-background/70 backdrop-blur-xl">
|
|
<div className="mx-auto flex h-16 max-w-6xl items-center gap-4 px-4 sm:px-6">
|
|
<Link href="/" onClick={goHome} className="flex items-center gap-2.5">
|
|
<img
|
|
src="/images/cohaise.webp"
|
|
alt=""
|
|
width={28}
|
|
height={28}
|
|
className="size-7 object-contain"
|
|
aria-hidden="true"
|
|
/>
|
|
<span className="font-logo text-sm font-bold tracking-logo text-foreground">
|
|
{t("brand.name")}
|
|
</span>
|
|
</Link>
|
|
|
|
<nav className="ml-auto hidden md:flex" aria-label="Navigation">
|
|
<div
|
|
ref={navRef}
|
|
className="relative flex items-center gap-0.5 rounded-full border border-border/70 bg-surface/50 p-1 backdrop-blur-md"
|
|
>
|
|
{/* Pastille unique qui glisse d'un onglet à l'autre. */}
|
|
<span
|
|
aria-hidden="true"
|
|
className={cn(
|
|
"pointer-events-none absolute bottom-1 left-0 top-1 z-0 rounded-full bg-accent/15 ring-1 ring-accent/30 transition-[transform,width,opacity] duration-500 ease-out-soft",
|
|
indicator ? "opacity-100" : "opacity-0",
|
|
)}
|
|
style={{
|
|
width: indicator?.width ?? 0,
|
|
transform: `translateX(${indicator?.left ?? 0}px)`,
|
|
}}
|
|
/>
|
|
|
|
{links.map((link) => {
|
|
const isActive = active === link.id;
|
|
return (
|
|
<Link
|
|
key={link.id}
|
|
ref={(node) => {
|
|
if (node) tabRefs.current.set(link.id, node);
|
|
else tabRefs.current.delete(link.id);
|
|
}}
|
|
href={link.path}
|
|
onClick={(event) => goTo(event, link)}
|
|
aria-current={isActive ? "page" : undefined}
|
|
className={cn(
|
|
"relative z-10 flex h-8 items-center rounded-full px-3.5 font-display text-[0.6875rem] font-semibold uppercase tracking-label transition-colors duration-fast",
|
|
isActive
|
|
? "text-accent"
|
|
: "text-muted-foreground hover:text-foreground",
|
|
)}
|
|
>
|
|
{t(link.key)}
|
|
</Link>
|
|
);
|
|
})}
|
|
</div>
|
|
</nav>
|
|
|
|
<div className="flex items-center gap-2 md:ml-6">
|
|
<button
|
|
type="button"
|
|
onClick={() => setLang(lang === "fr" ? "en" : "fr")}
|
|
className="inline-flex h-8 items-center justify-center rounded-full border border-border/70 bg-surface/40 px-2.5 font-display text-[0.625rem] font-semibold uppercase tracking-label text-muted-foreground transition-colors hover:border-accent/50 hover:text-foreground focus-visible:ring-2 focus-visible:ring-ring focus-visible:ring-offset-2 focus-visible:ring-offset-background focus-visible:outline-none"
|
|
aria-label={lang === "fr" ? "Switch to English" : "Passer en français"}
|
|
>
|
|
{lang === "fr" ? "EN" : "FR"}
|
|
</button>
|
|
<ThemeToggle />
|
|
</div>
|
|
</div>
|
|
</header>
|
|
);
|
|
};
|