diff --git a/docs/UI-PORT.md b/docs/UI-PORT.md index f6c87fa..26b239c 100644 --- a/docs/UI-PORT.md +++ b/docs/UI-PORT.md @@ -84,7 +84,21 @@ npm run dev # http://localhost:3000 ``` - เปิดทุก route: `/`, `/stops`, `/stops/:code`, `/routes`, `/routes/:id`, `/check`, - `/check/:id`, `/blog`, `/blog/:id`, `/about`, `/credits` + `/check/:id`, `/blog`, `/blog/:id`, `/about`, `/credits`, `/stats` - เทียบภาพกับ mock ที่ viewport เดียวกัน (1280×900) — diff ที่วัดได้ 0.7–2.3% (ที่เหลือมาจาก marquee animation / ตัวเลขผู้เข้าชม) - ตรวจว่าไม่มี horizontal scroll และปุ่ม/ลิงก์กดได้จริง + +## รอบล่าสุด — motion, สถิติ, auto-update (พอร์ตจาก mock) + +| ของใน mock | ใน repo นี้ | หมายเหตุ | +|---|---|---| +| `ui/motion.js` (enter · reveal · loading bar) | `src/lib/ui/motion.ts` + `components/MotionBoot.tsx` + CSS ใน `src/styles/_shared.css` | MotionBoot เรียก `Motion.enter(#view)` ทุกครั้งที่ pathname เปลี่ยน (แทน router เดิม) · reveal ใช้ `IntersectionObserver` + sweep (กันค้างตอนกระโดดข้ามหน้า/แท็บถูกซ่อน) | +| `ui/analytics.js` + `#/stats` | `src/lib/ui/analytics.ts` + `app/stats/page.tsx` + `components/views/StatsView.tsx` + `styles/pages/stats.css` | เก็บใน localStorage `at_stats_v1` · ไม่มีคุกกี้/IP/UA · `cleanTerm()` ตัดอีเมล/เบอร์/เลขยาว · debounce 900ms · opt-out + DNT/GPC · ค่าเริ่มต้นไม่ส่งออกเน็ต (จะส่งก็ต่อเมื่อตั้ง `window.AT_ANALYTICS = {endpoint, siteId}`) | +| ปุ่มติดตั้งแอปลอยมุมขวาล่าง | **เอาออก** — `PwaBoot` เหลือ SW + version check | Chrome/Edge ยังมีไอคอนติดตั้งของเบราว์เซอร์เอง | +| ตัวเลขผู้เข้าชม 12,834 ใน footer | **เอาออก** — ลบ `lib/ui/visitors.ts` + CSS `.mu-visitor/.mu-vreset` + คีย์ `visitors.*` | backend มี `/api/visits` (record_visit/visits_summary) แต่ frontend ยังไม่เรียก — ถ้าจะทำสถิติรวมศูนย์ ให้ต่อที่ `lib/api.ts` | +| bump + `version.json` + toast อัปเดต | `PwaBoot` เทียบ `/version.json` กับ `` (อ่านตอน build) → toast + reload ครั้งเดียว/เวอร์ชัน | ต้อง bump `public/version.json` + `public/sw.js` VERSION แล้ว rebuild | + +**ยังไม่พอร์ต (ตั้งใจ):** หน้ารวมศูนย์สถิติจาก backend — backend มีตาราง `visit_daily_stats` +และ API `/visits/summary` แล้ว แต่ยังไม่มี UI/การเรียก; ถ้าจะทำต้องตัดสินใจเรื่อง visitor id +เชิงความเป็นส่วนตัวก่อน (mock ใช้ local-only เพื่อไม่ต้องมี id ถาวร) diff --git a/frontend/public/locales/en.json b/frontend/public/locales/en.json index 60893e8..9bb4623 100644 --- a/frontend/public/locales/en.json +++ b/frontend/public/locales/en.json @@ -131,10 +131,10 @@ "stops.noOffset": "No travel time from the first stop yet", "stops.noBusLine": "No bus line listed", "stops.modeCode": "Search by stop code", - "stops.modeNear": "Near me", + "stops.modeNear": "Near me", "stops.nearCta": "Use my location", "stops.nearHint": "We ask your device for a location, then rank stops by real distance from their coordinates.", -"stops.modePlace": "Search by place name", + "stops.modePlace": "Search by place name", "stops.codePh": "3+000", "stops.codeHint": "Type 4 digits and the + sign is added automatically (e.g. 3000 → 3+000)", "stops.codeHintBox": "Type digits in the boxes — empty boxes are filled with 0 automatically. For 4-digit codes such as 8+591, enter 08+591", @@ -267,5 +267,43 @@ "check.noMoreToday": "No departures left today", "check.stopsCount": "stops", "check.toStopDetail": "View stop detail", - "common.routes": "routes" + "common.routes": "routes", + "nav.stats": "Stats", + "update.applying": "New version — updating…", + "stats.title": "Search statistics on this device", + "stats.lead": "Only counts and search terms are kept — no cookies, no user id, no IP, and nothing leaves this device", + "stats.kpi.views": "Page views", + "stats.kpi.searches": "Searches", + "stats.kpi.terms": "Unique terms", + "stats.kpi.noResult": "No results", + "stats.chart.title": "Last 14 days", + "stats.chart.lead": "Solid bar = page views · light bar = searches", + "stats.terms.title": "Top search terms", + "stats.terms.lead": "Terms are sanitised — emails, phone numbers and long digit runs are stripped before saving", + "stats.terms.empty": "No searches on this device yet — try the stop search page, then come back", + "stats.views.title": "Most opened pages", + "stats.views.lead": "Counts route and stop detail pages only (not tied to any user)", + "stats.views.empty": "No data yet — open a route or stop detail once", + "stats.views.stopPrefix": "Stop {code}", + "stats.views.routePrefix": "Route {n}", + "stats.noresult.title": "Searched, nothing found", + "stats.noresult.lead": "A signal that data is missing — these terms should exist if they are real routes", + "stats.privacy.title": "Privacy", + "stats.privacy.collect": "Stored: page-view counts · sanitised search terms · no-result counts · last-used time", + "stats.privacy.reject": "Not stored: IP · User-Agent · location · cookies · device id · cross-site history", + "stats.privacy.local": "Data lives in this browser's localStorage only — clear it anytime", + "stats.privacy.optoutTitle": "Turn off stats on this device", + "stats.privacy.optoutLead": "Switching this on stops recording immediately (existing numbers stay visible). Do Not Track / GPC are respected anyway.", + "stats.privacy.off": "Stats turned off — nothing new is recorded", + "stats.privacy.on": "Stats turned on", + "stats.btn.export": "Download data (JSON)", + "stats.btn.clear": "Clear data on this device", + "stats.clear.confirm": "Clear all stats on this device? This cannot be undone.", + "stats.clear.done": "Data cleared", + "stats.export.done": "File downloaded", + "stats.since": "Collecting since", + "stats.col.term": "Term", + "stats.col.count": "Hits", + "stats.col.last": "Last", + "stats.col.target": "Page" } diff --git a/frontend/public/locales/th.json b/frontend/public/locales/th.json index 70f825d..5eded9b 100644 --- a/frontend/public/locales/th.json +++ b/frontend/public/locales/th.json @@ -131,10 +131,10 @@ "stops.noOffset": "ยังไม่ระบุเวลาเดินทางจากจุดแรก", "stops.noBusLine": "ยังไม่ระบุสายรถ", "stops.modeCode": "ค้นหาด้วยรหัสป้าย", - "stops.modeNear": "ป้ายใกล้ฉัน", + "stops.modeNear": "ป้ายใกล้ฉัน", "stops.nearCta": "ขอพิกัดและหาป้ายใกล้ฉัน", "stops.nearHint": "ระบบจะขอตำแหน่งจากเครื่อง แล้วคำนวณระยะจากพิกัดป้าย/ศาลารถ เรียงจากใกล้ไปไกล", -"stops.modePlace": "ค้นหาด้วยชื่อสถานที่", + "stops.modePlace": "ค้นหาด้วยชื่อสถานที่", "stops.codePh": "3+000", "stops.codeHint": "พิมพ์ตัวเลข 4 หลัก ระบบจะเติมเครื่องหมาย + ให้อัตโนมัติ (เช่น 3000 → 3+000)", "stops.codeHintBox": "พิมพ์ตัวเลขในช่อง ระบบจะเติม 0 ให้อัตโนมัติเมื่อเว้นว่าง และถ้าเจอรหัส 4 หลัก เช่น 8+591 ให้กรอก 08+591", @@ -267,5 +267,43 @@ "check.noMoreToday": "ไม่มีรถเหลือในวันนี้แล้ว", "check.stopsCount": "จุดจอด", "check.toStopDetail": "ไปหน้ารายละเอียดจุดจอด", - "common.routes": "เส้นทาง" + "common.routes": "เส้นทาง", + "nav.stats": "สถิติ", + "update.applying": "มีเวอร์ชันใหม่ — กำลังอัปเดต…", + "stats.title": "สถิติการค้นหาในเครื่องนี้", + "stats.lead": "เก็บเฉพาะจำนวนครั้งและคำที่ค้น — ไม่มีคุกกี้ ไม่มีรหัสผู้ใช้ ไม่เก็บ IP และไม่ส่งออกนอกเครื่อง", + "stats.kpi.views": "ครั้งที่เปิดหน้า", + "stats.kpi.searches": "ครั้งที่ค้นหา", + "stats.kpi.terms": "คำค้นต่างกัน", + "stats.kpi.noResult": "ค้นแล้วไม่พบ", + "stats.chart.title": "14 วันล่าสุด", + "stats.chart.lead": "แท่งเข้ม = เปิดหน้า · แท่งอ่อน = ค้นหา", + "stats.terms.title": "คำที่ค้นมากที่สุด", + "stats.terms.lead": "คำถูกทำให้ปลอดภัยแล้ว — ตัดอีเมล เบอร์โทร และเลขยาวออกก่อนบันทึก", + "stats.terms.empty": "ยังไม่มีคำค้นในเครื่องนี้ — ลองค้นหาป้ายที่หน้า “ป้ายหยุดรถ” แล้วกลับมาดู", + "stats.views.title": "หน้าที่ถูกเปิดบ่อย", + "stats.views.lead": "นับเฉพาะรายละเอียดสายรถและรายละเอียดป้าย (ไม่ผูกกับผู้ใช้)", + "stats.views.empty": "ยังไม่มีข้อมูล — เปิดรายละเอียดสายหรือป้ายสักครั้ง", + "stats.views.stopPrefix": "ป้าย {code}", + "stats.views.routePrefix": "สาย {n}", + "stats.noresult.title": "ค้นแล้วไม่พบ", + "stats.noresult.lead": "สัญญาณว่าข้อมูลยังขาด — คำเหล่านี้ควรมีในระบบถ้าเป็นเส้นทางจริง", + "stats.privacy.title": "ความเป็นส่วนตัว", + "stats.privacy.collect": "เก็บ: จำนวนเปิดหน้า · คำที่ค้น (ตัดข้อมูลส่วนตัวออก) · จำนวนครั้งที่ค้นไม่พบ · เวลาล่าสุด", + "stats.privacy.reject": "ไม่เก็บ: IP · User-Agent · ตำแหน่ง · คุกกี้ · รหัสเครื่อง · ประวัติข้ามเว็บ", + "stats.privacy.local": "ข้อมูลอยู่ใน localStorage ของเบราว์เซอร์นี้เท่านั้น — ล้างได้ทุกเมื่อ", + "stats.privacy.optoutTitle": "ปิดการเก็บสถิติในเครื่องนี้", + "stats.privacy.optoutLead": "เปิดสวิตช์นี้ = หยุดบันทึกทันที (ยังดูตัวเลขเดิมได้) · ระบบเคารพ Do Not Track / GPC อยู่แล้ว", + "stats.privacy.off": "ปิดการเก็บสถิติแล้ว — ไม่มีการบันทึกใหม่", + "stats.privacy.on": "เปิดการเก็บสถิติแล้ว", + "stats.btn.export": "ดาวน์โหลดข้อมูล (JSON)", + "stats.btn.clear": "ล้างข้อมูลในเครื่อง", + "stats.clear.confirm": "ล้างสถิติทั้งหมดในเครื่องนี้? การลบย้อนกลับไม่ได้", + "stats.clear.done": "ล้างข้อมูลเรียบร้อย", + "stats.export.done": "ดาวน์โหลดไฟล์แล้ว", + "stats.since": "เริ่มเก็บเมื่อ", + "stats.col.term": "คำค้น", + "stats.col.count": "ครั้ง", + "stats.col.last": "ล่าสุด", + "stats.col.target": "หน้า" } diff --git a/frontend/public/sw.js b/frontend/public/sw.js index edbffc3..69440b6 100644 --- a/frontend/public/sw.js +++ b/frontend/public/sw.js @@ -15,7 +15,7 @@ - SW ใหม่ → skipWaiting + clients.claim + แจ้งหน้าเว็บ ============================================================ */ -const VERSION = "2026.10.24.2"; /* bump เมื่อแก้ UI เพื่อบังคับให้ cache เก่าถูกทิ้ง */ +const VERSION = "2026.10.24.3"; /* bump เมื่อแก้ UI เพื่อบังคับให้ cache เก่าถูกทิ้ง */ const CACHE = `atroute-${VERSION}`; const OFFLINE_URL = "/offline.html"; const VERSION_URL = "/version.json"; diff --git a/frontend/public/version.json b/frontend/public/version.json index 88f3c99..358417e 100644 --- a/frontend/public/version.json +++ b/frontend/public/version.json @@ -1,6 +1,6 @@ { "app": "Atroute", - "version": "2026.10.24.2", - "builtAt": "2026-10-24T00:33:20", + "version": "2026.10.24.3", + "builtAt": "2026-11-04T00:51:02", "pwa": true } diff --git a/frontend/src/app/layout.tsx b/frontend/src/app/layout.tsx index b1118c6..f65e9e2 100644 --- a/frontend/src/app/layout.tsx +++ b/frontend/src/app/layout.tsx @@ -18,6 +18,7 @@ const APP_VERSION = readAppVersion(); import IconSprite from "@/components/IconSprite"; import PwaBoot from "@/components/PwaBoot"; import SiteBoot from "@/components/SiteBoot"; +import MotionBoot from "@/components/MotionBoot"; import SiteFooter from "@/components/SiteFooter"; import SiteHeader from "@/components/SiteHeader"; @@ -144,6 +145,7 @@ export default function RootLayout({ children }: { children: React.ReactNode })