Files
web-at-transit/frontend/src/components/MotionBoot.tsx
T
Bkk1234 4b5a4d33d3 sync from mock: motion, privacy-first search stats, auto-update UX
- frontend/src/lib/ui/motion.ts + components/MotionBoot.tsx: page-enter and
  scroll reveal per pathname change (ported from mock motion.js); IntersectionObserver
  plus sweep fallback for jump-scroll/hidden tabs, maps never transformed
- frontend/src/lib/ui/analytics.ts: cookie-less local-first search analytics
  (localStorage at_stats_v1, DNT/GPC + opt-out, term sanitiser, 900ms debounce,
  caps 300 terms / 200 views / 120 days); optional Umami endpoint via AT_ANALYTICS
- /stats page (StatsView + styles/pages/stats.css): KPIs, 14-day chart, top terms,
  top route/stop pages, no-result terms, JSON export, clear, opt-out
- hooks: stops search apply(), stop detail route filter
- remove footer visitor counter (lib/ui/visitors.ts, .mu-visitor/.mu-vreset, i18n keys)
- remove floating install-app button; PwaBoot keeps SW + guarded version toast
  (sessionStorage guard, silent reload when tab hidden)
- i18n th/en: nav.stats, update.applying, stats.* (public + src/data locales)
- version.json + sw VERSION -> 2026.10.24.3; docs/UI-PORT.md section for this round
2026-11-04 00:53:37 +07:00

47 lines
1.7 KiB
TypeScript

"use client";
import { useEffect } from "react";
import { usePathname } from "next/navigation";
import { ensureRuntime } from "@/lib/runtime";
/**
* MotionBoot — อนิเมชันเข้าหน้า + สถิติการเปิดหน้า (ต่อจาก mock's router)
*
* mock: router.js เรียก `Motion.enter(viewEl)` หลัง inject partial ทุกครั้ง
* Next: App Router เปลี่ยน pathname → เรียกเองตรงนี้ (ผลลัพธ์เดียวกัน)
*
* ทำ 3 อย่างต่อการเปลี่ยนหน้า
* 1. Analytics.pageview(pathname) → นับครั้งเปิดหน้าแบบไม่ระบุตัวตน
* 2. Motion.enter(#view) → หน้าใหม่ค่อย ๆ โผล่ + เริ่ม scan reveal
* 3. Motion.scan() → เก็บการ์ดที่ hydrate ทีหลัง (MutationObserver ช่วยอีกแรง)
*/
export default function MotionBoot() {
const pathname = usePathname();
useEffect(() => {
let cancelled = false;
(async () => {
await ensureRuntime();
if (cancelled) return;
const w = window as unknown as {
Analytics?: { pageview?: (p: string) => void };
Motion?: { enter?: (el: Element | null) => void; scan?: () => void };
};
w.Analytics?.pageview?.(pathname || "/");
const view = document.getElementById("view");
w.Motion?.enter?.(view);
w.Motion?.scan?.();
})();
return () => {
cancelled = true;
};
}, [pathname]);
return null;
}