Repository Public
1// Ossature : en-tête, navigation mobile, pied de page, palette, comparateur.23import { useEffect, useState } from "react";4import { Link, NavLink, Outlet, ScrollRestoration, useLocation, useNavigation, useNavigationType } from "react-router";5import { useIsFetching } from "@tanstack/react-query";6import { LayoutGroup } from "motion/react";7import { Heart, Menu, Moon, Scale, Search, Sun } from "lucide-react";8import { cn } from "@/lib/cn";9import { notifyMotion, SlideMark } from "@/lib/motion";10import { setTheme, useCompare, useFavorites, useTheme } from "@/lib/store";11import { getMotionPref, setMotionPref, type MotionPref } from "@/brand/engine";12import { IconBuilding, IconDoorOpen, IconHouse, IconNeighborhood } from "@/brand/icons";13import { LoukaLogo } from "@/brand/Symbol";14import { LoukaDoorTransition } from "@/brand/transition";15import { Kbd } from "@/ui/primitives";16import { Sheet } from "@/ui/Sheet";17import { Toaster } from "@/ui/toast";18import { CommandPalette } from "./CommandPalette";1920const NAV = [21 { to: "/recherche", label: "Explorer" },22 { to: "/villes", label: "Villes" },23 { to: "/gestionnaires", label: "Gestionnaires" },24 { to: "/stats", label: "Marché" },25];2627const MORE = [28 { to: "/recherche", label: "Explorer la carte" },29 { to: "/villes", label: "Villes" },30 { to: "/gestionnaires", label: "Gestionnaires immobiliers" },31 { to: "/stats", label: "Marché locatif" },32 { to: "/juste-valeur", label: "Juste valeur" },33 { to: "/scores", label: "Scores de quartier" },34 { to: "/comparer", label: "Comparateur" },35 { to: "/demenageurs", label: "Déménageurs" },36 { to: "/sources", label: "Sources" },37 { to: "/a-propos", label: "À propos" },38 { to: "/contact", label: "Contact" },39];4041const MOTION: { value: MotionPref; label: string }[] = [42 { value: "auto", label: "Automatique" },43 { value: "compact", label: "Discrètes" },44 { value: "none", label: "Aucune" },45];4647function ThemeToggle() {48 const theme = useTheme();49 return (50 <button51 type="button"52 onClick={() => {53 const root = document.documentElement;54 root.classList.add("lk-theming");55 setTheme(theme === "dark" ? "light" : "dark");56 window.setTimeout(() => root.classList.remove("lk-theming"), 280);57 }}58 aria-label={theme === "dark" ? "Passer au thème clair" : "Passer au thème sombre"}59 className="lk-press grid size-10 place-items-center rounded-full text-ink-2 transition-colors duration-150 hover:bg-surface-2 hover:text-ink"60 >61 <span key={theme} className="lk-spin-in grid">62 {theme === "dark" ? <Sun className="size-[18px]" /> : <Moon className="size-[18px]" />}63 </span>64 </button>65 );66}6768function Header({ onSearch, onMenu }: { onSearch: () => void; onMenu: () => void }) {69 const { pathname } = useLocation();70 const favCount = Object.keys(useFavorites()).length;71 const wide = pathname === "/recherche";72 const [scrolled, setScrolled] = useState(false);73 useEffect(() => {74 const on = () => setScrolled(window.scrollY > 12);75 on();76 window.addEventListener("scroll", on, { passive: true });77 return () => window.removeEventListener("scroll", on);78 }, []);79 return (80 <header className={cn("sticky top-0 z-50 border-b bg-bg transition-[box-shadow,border-color] duration-300", scrolled ? "border-line-2 shadow-[0_6px_20px_-14px_rgb(0_0_0/0.35)]" : "border-line")}>81 <div className={cn("flex h-16 items-center gap-1", wide ? "px-4 lg:px-6" : "container-x")}>82 <Link to="/" aria-label="Lou-Ka, accueil" className="lk-logo mr-5 shrink-0">83 <LoukaLogo size={30} className={cn("origin-left text-[1.5rem] transition-transform duration-300 ease-[cubic-bezier(0.2,0.7,0.2,1)]", scrolled && "scale-[0.94]")} />84 </Link>85 <LayoutGroup id="entete">86 <nav className="hidden items-center lg:flex" aria-label="Navigation principale">87 {NAV.map((n) => (88 <NavLink89 key={n.to}90 to={n.to}91 className={({ isActive }) =>92 cn(93 "relative px-3 py-2 text-[0.92rem] transition-colors duration-150",94 isActive ? "font-medium text-ink" : "text-ink-2 hover:text-ink",95 )96 }97 >98 {({ isActive }) => (99 <>100 {n.label}101 {isActive && <SlideMark id="nav-mark" className="absolute inset-x-3 -bottom-[13px] h-0.5 bg-accent" />}102 </>103 )}104 </NavLink>105 ))}106 </nav>107 </LayoutGroup>108 <div className="flex-1" />109 <button110 type="button"111 onClick={onSearch}112 className="hidden h-10 items-center gap-2.5 rounded-[10px] border border-line-2 bg-surface pl-3 pr-2 text-[0.88rem] text-ink-3 transition-colors duration-150 hover:border-ink-3 md:flex"113 >114 <Search className="size-4" />115 <span className="pr-8">Ville, quartier, gestionnaire</span>116 <Kbd>⌘K</Kbd>117 </button>118 <button119 type="button"120 onClick={onSearch}121 aria-label="Recherche rapide"122 className="grid size-10 place-items-center rounded-full text-ink-2 hover:bg-surface-2 hover:text-ink md:hidden"123 >124 <Search className="size-5" />125 </button>126 <Link127 to="/favoris"128 aria-label={`Favoris (${favCount})`}129 className="relative hidden size-10 place-items-center rounded-full text-ink-2 transition-colors duration-150 hover:bg-surface-2 hover:text-ink sm:grid"130 >131 <Heart className="size-[18px]" />132 {favCount > 0 && (133 <span className="num absolute right-0.5 top-0.5 grid h-4 min-w-4 place-items-center rounded-full bg-accent px-1 text-[0.6rem] font-semibold text-white">134 {favCount}135 </span>136 )}137 </Link>138 <ThemeToggle />139 <button140 type="button"141 onClick={onMenu}142 aria-label="Menu"143 className="grid size-10 place-items-center rounded-full text-ink-2 hover:bg-surface-2 hover:text-ink lg:hidden"144 >145 <Menu className="size-5" />146 </button>147 </div>148 </header>149 );150}151152function TabBar() {153 const favCount = Object.keys(useFavorites()).length;154 const tabs = [155 { to: "/", label: "Accueil", icon: IconHouse, end: true },156 { to: "/recherche", label: "Explorer", icon: IconDoorOpen },157 { to: "/favoris", label: "Favoris", icon: Heart, badge: favCount },158 { to: "/gestionnaires", label: "Gestion", icon: IconBuilding },159 { to: "/stats", label: "Marché", icon: IconNeighborhood },160 ];161 return (162 <nav aria-label="Navigation" className="fixed inset-x-0 bottom-0 z-50 border-t border-line bg-bg pb-[env(safe-area-inset-bottom)] lg:hidden">163 <LayoutGroup id="onglets">164 <ul className="mx-auto grid max-w-md grid-cols-5">165 {tabs.map(({ to, label, icon: Icon, end, badge }) => (166 <li key={to}>167 <NavLink168 to={to}169 end={end}170 className={({ isActive }) =>171 cn(172 "relative flex h-14 flex-col items-center justify-center gap-0.5 text-[0.66rem] transition-colors duration-150",173 isActive ? "font-medium text-ink" : "text-ink-3",174 )175 }176 >177 {({ isActive }) => (178 <>179 {isActive && <SlideMark id="tab-mark" className="absolute inset-x-6 top-0 h-0.5 bg-accent" />}180 <span className="relative">181 <Icon size={21} className="size-[21px]" strokeWidth={isActive ? 1.9 : 1.6} />182 {!!badge && (183 <span className="num absolute -right-2 -top-1 grid h-3.5 min-w-3.5 place-items-center rounded-full bg-accent px-1 text-[0.56rem] font-semibold text-white">184 {badge}185 </span>186 )}187 </span>188 {label}189 </>190 )}191 </NavLink>192 </li>193 ))}194 </ul>195 </LayoutGroup>196 </nav>197 );198}199200/** Barre fine en haut : seulement quand une attente réelle dépasse 300 ms. */201function TopProgress() {202 const navigating = useNavigation().state === "loading";203 const fetching = useIsFetching({ predicate: (q) => q.state.data === undefined }) > 0;204 const busy = navigating || fetching;205 const [show, setShow] = useState(false);206 useEffect(() => {207 if (!busy) {208 setShow(false);209 return;210 }211 const t = window.setTimeout(() => setShow(true), 300);212 return () => window.clearTimeout(t);213 }, [busy]);214 return show ? <div className="lk-progress" role="progressbar" aria-label="Chargement" /> : null;215}216217function CompareTray() {218 const items = useCompare();219 const { pathname } = useLocation();220 if (!items.length || pathname === "/comparer") return null;221 return (222 <div className="lk-rise fixed bottom-[calc(4.4rem+env(safe-area-inset-bottom))] right-4 z-40 lg:bottom-6 lg:right-6">223 <Link224 to="/comparer"225 className="flex h-11 items-center gap-2.5 rounded-[10px] bg-ink pl-3.5 pr-4 text-[0.88rem] font-medium text-bg shadow-float transition-transform duration-100 active:scale-[0.98]"226 >227 <Scale className="size-4" />228 Comparer229 <span key={items.length} className="num lk-heart-pop grid size-5 place-items-center rounded-full bg-bg/15 text-xs">{items.length}</span>230 </Link>231 </div>232 );233}234235function Footer() {236 const cols = [237 {238 title: "Chercher",239 links: [240 ["/recherche", "Carte des logements"],241 ["/recherche?deal=sous", "Bons prix"],242 ["/villes", "Toutes les villes"],243 ["/favoris", "Mes favoris"],244 ["/comparer", "Comparateur"],245 ],246 },247 {248 title: "Comprendre",249 links: [250 ["/stats", "Marché locatif"],251 ["/juste-valeur", "Juste valeur"],252 ["/scores", "Scores de quartier"],253 ["/sources", "Sources"],254 ],255 },256 {257 title: "Annuaires",258 links: [259 ["/gestionnaires", "Gestionnaires immobiliers"],260 ["/demenageurs", "Déménageurs"],261 ],262 },263 {264 title: "Lou-Ka",265 links: [266 ["/a-propos", "À propos"],267 ["/contact", "Contact"],268 ["/confidentialite", "Confidentialité"],269 ["/conditions", "Conditions d'utilisation"],270 ],271 },272 ] as const;273 return (274 <footer className="mt-24 border-t border-line pb-[calc(5rem+env(safe-area-inset-bottom))] lg:pb-0">275 <div className="container-x grid gap-10 py-14 lg:grid-cols-[1.2fr_2.8fr]">276 <div>277 <LoukaLogo size={30} className="text-[1.5rem]" />278 <p className="mt-4 max-w-xs text-[0.9rem] leading-relaxed text-ink-3">279 Les logements à louer au Québec, réunis au même endroit. Indépendant, sans compte, sans publicité ciblée.280 </p>281 </div>282 <div className="grid grid-cols-2 gap-8 sm:grid-cols-4">283 {cols.map((c) => (284 <div key={c.title}>285 <div className="eyebrow mb-3.5">{c.title}</div>286 <ul className="space-y-2.5">287 {c.links.map(([to, label]) => (288 <li key={to}>289 <Link to={to} className="text-[0.9rem] text-ink-2 transition-colors duration-150 hover:text-ink">290 {label}291 </Link>292 </li>293 ))}294 </ul>295 </div>296 ))}297 </div>298 </div>299 <div className="border-t border-line">300 <div className="container-x flex flex-wrap items-center justify-between gap-3 py-5 text-xs text-ink-3">301 <span>© {new Date().getFullYear()} Lou-Ka. Chaque annonce appartient à son auteur et renvoie vers sa source.</span>302 <a href="mailto:contact@spboucher.ai" className="hover:text-ink">303 contact@spboucher.ai304 </a>305 </div>306 </div>307 </footer>308 );309}310311function MotionSetting() {312 const [pref, setPref] = useState<MotionPref>(getMotionPref());313 const current = MOTION.some((m) => m.value === pref) ? pref : "auto";314 return (315 <div className="mt-4 border-t border-line pt-5">316 <div className="text-[0.92rem] font-medium">Animations d'ouverture</div>317 <p className="mt-1 text-[0.84rem] text-ink-3">La porte qui s'ouvre quand vous choisissez un logement.</p>318 <div role="radiogroup" aria-label="Animations d'ouverture" className="mt-3 inline-flex rounded-[10px] bg-surface-2 p-1">319 {MOTION.map((m) => (320 <button321 key={m.value}322 type="button"323 role="radio"324 aria-checked={current === m.value}325 onClick={() => {326 setMotionPref(m.value);327 setPref(m.value);328 notifyMotion();329 }}330 className={cn(331 "h-9 rounded-[7px] px-3.5 text-[0.84rem] transition-colors duration-150",332 current === m.value ? "bg-surface font-medium text-ink shadow-card" : "text-ink-3",333 )}334 >335 {m.label}336 </button>337 ))}338 </div>339 </div>340 );341}342343export function Shell() {344 const { pathname, state, key: locationKey } = useLocation();345 const doorArrival = !!(state as { door?: string } | null)?.door;346 // arrivée directe sur le site : le contenu s'affiche tout de suite, sans fondu347 const firstLoad = locationKey === "default";348 // retour arrière : fondu bref, sans glissement (on revient où l'on était)349 const back = useNavigationType() === "POP";350 const [palette, setPalette] = useState(false);351 const [menu, setMenu] = useState(false);352 const immersive = pathname === "/recherche";353354 useEffect(() => {355 const on = (e: KeyboardEvent) => {356 if ((e.metaKey || e.ctrlKey) && e.key.toLowerCase() === "k") {357 e.preventDefault();358 setPalette((p) => !p);359 }360 };361 window.addEventListener("keydown", on);362 return () => window.removeEventListener("keydown", on);363 }, []);364365 useEffect(() => setMenu(false), [pathname]);366367 return (368 <div className={cn("flex min-h-dvh flex-col", immersive && "h-dvh overflow-hidden")}>369 <a370 href="#contenu"371 className="sr-only focus:not-sr-only focus:fixed focus:left-4 focus:top-4 focus:z-[100] focus:rounded-[8px] focus:bg-ink focus:px-4 focus:py-2 focus:text-sm focus:font-medium focus:text-bg"372 >373 Aller au contenu374 </a>375 <TopProgress />376 <Header onSearch={() => setPalette(true)} onMenu={() => setMenu(true)} />377 <main id="contenu" className={cn("flex-1", immersive ? "min-h-0" : "min-h-[calc(100dvh-4rem)]")}>378 {/* fondu bref au changement de page, sauf quand la porte a fait la transition */}379 <div key={pathname} className={cn(immersive && "h-full", !doorArrival && !immersive && !firstLoad && (back ? "lk-page-back" : "lk-page-in"))}>380 <Outlet />381 </div>382 </main>383 {!immersive && <Footer />}384 <TabBar />385 <CompareTray />386 <CommandPalette open={palette} onClose={() => setPalette(false)} />387 <Sheet open={menu} onClose={() => setMenu(false)} title="Menu">388 <ul className="-mx-2">389 {MORE.map((m) => (390 <li key={m.to}>391 <Link to={m.to} className="block rounded-[8px] px-3 py-3 text-[1rem] text-ink hover:bg-surface-2">392 {m.label}393 </Link>394 </li>395 ))}396 </ul>397 <MotionSetting />398 </Sheet>399 <Toaster />400 <LoukaDoorTransition />401 <ScrollRestoration />402 </div>403 );404}405