feat(ui): full i18n (th/en) + highway stop search + real km list
i18n: - LangProvider (client context) + cookie/lang localStorage sync - locales/th.json + en.json จาก design (269 keys) - แปล header/nav/footer/home/route/stop/check ผ่าน t() - server pages อ่าน cookie lang (SSR แปลตรง) + client context Stop search (หน้า /stops): - code search 5 หลัก (kilometer '36+020' → pad5 '36020') + numpad - place search (ชื่อสถานที่) + suggest - near-me (geolocation → ป้ายทางหลวงใกล้สุด 8 อัน, haversine) - data: busstop_list.json (154 ป้ายทางหลวง) Route detail: km list ใช้ระยะจริงจาก stop-km.json (แทน stop_sequence) Note: 'nearby ใกล้เคียงป้าย' ไม่ทำ — stations.json ไม่มี landmarks data
This commit is contained in:
1 parent
0c3936df69
commit
1526c5b6d0
18 files changed
+3146
-141
No files matched your search
@@ -3,6 +3,8 @@ import { api, type RouteListItem, type Schedule, type RouteStop, type RouteDetai
|
||||
import { RouteSelect } from "@/components/RouteSelect";
|
||||
import { VisitTracker } from "@/lib/visit-tracker";
|
||||
import { Icon } from "@/components/Icons";
|
||||
import { headers } from "next/headers";
|
||||
import { t, langFromCookie } from "@/lib/i18n";
|
||||
|
||||
const TONES = ["sky", "purple", "pink", "mint", "amber"] as const;
|
||||
|
||||
@@ -23,6 +25,9 @@ type CheckPageProps = {
|
||||
|
||||
export default async function CheckPage({ searchParams }: CheckPageProps) {
|
||||
const sp = await searchParams;
|
||||
const h = await headers();
|
||||
const lang = langFromCookie(h.get("cookie"));
|
||||
const T = (k: string, v?: Record<string, string | number>) => t(k, lang, v);
|
||||
|
||||
const { items: allRoutes } = await api.routes().catch(() => ({ items: [] as RouteListItem[] }));
|
||||
const routeId =
|
||||
@@ -68,14 +73,14 @@ export default async function CheckPage({ searchParams }: CheckPageProps) {
|
||||
<div className="hero__blob three" aria-hidden />
|
||||
<div className="container hero__inner">
|
||||
<span className="hero__badge">
|
||||
<Icon name="clock" size={14} className="icon" /> เช็กเวลาเดินรถ
|
||||
<Icon name="clock" size={14} className="icon" /> {T("cta.check")}
|
||||
</span>
|
||||
<h1>
|
||||
ตารางเวลาเดินรถ
|
||||
{T("check.title")}
|
||||
<br />
|
||||
<span className="hero__grad">{route?.name_th ?? "เลือกสายรถด้านล่าง"}</span>
|
||||
<span className="hero__grad">{route?.name_th ?? (lang === "en" ? "Select a route below" : "เลือกสายรถด้านล่าง")}</span>
|
||||
</h1>
|
||||
<p className="hero__lead">เลือกสายรถ แล้วดูรอบรถทุกจุดจอดในหน้าเดียว</p>
|
||||
<p className="hero__lead">{T("check.lead")}</p>
|
||||
|
||||
{allRoutes.length > 0 && (
|
||||
<div className="check-selector">
|
||||
@@ -92,16 +97,16 @@ export default async function CheckPage({ searchParams }: CheckPageProps) {
|
||||
<div className="container">
|
||||
{/* สรุปเส้นทาง */}
|
||||
<div className="check-stats">
|
||||
<div className="check-stat"><b>{stops.length}</b><span>จุดจอดหลัก</span></div>
|
||||
<div className="check-stat"><b>{provinceSet.size}</b><span>จังหวัดที่ผ่าน</span></div>
|
||||
<div className="check-stat"><b>{allTimes.length}</b><span>รอบต่อวัน</span></div>
|
||||
<div className="check-stat"><b>{next ?? "—"}</b><span>{next ? "รอบถัดไป" : "ไม่มีรอบวันนี้"}</span></div>
|
||||
<div className="check-stat"><b>{stops.length}</b><span>{T("check.kpiStops")}</span></div>
|
||||
<div className="check-stat"><b>{provinceSet.size}</b><span>{T("check.kpiProvince")}</span></div>
|
||||
<div className="check-stat"><b>{allTimes.length}</b><span>{T("check.kpiTrips")}</span></div>
|
||||
<div className="check-stat"><b>{next ?? "—"}</b><span>{next ? T("check.kpiNext") : (lang === "en" ? "No trips today" : "ไม่มีรอบวันนี้")}</span></div>
|
||||
</div>
|
||||
|
||||
{/* ตารางเวลาทุกจุดจอด */}
|
||||
<section className="check-schedule">
|
||||
<h2 className="section-title">
|
||||
ตารางเวลาเดินรถทุกจุดจอด {route ? `— สาย ${route.route_id}` : ""}
|
||||
{T("check.scheduleAll")} {route ? `— ${lang === "en" ? "Route" : "สาย"} ${route.route_id}` : ""}
|
||||
</h2>
|
||||
{schedules.length === 0 ? (
|
||||
<p className="muted">ยังไม่มีข้อมูลตารางเวลาสำหรับสายนี้</p>
|
||||
|
||||
@@ -1275,4 +1275,68 @@ a.contact-item:hover { transform: translateY(-2px); box-shadow: 0 8px 18px rgba(
|
||||
}
|
||||
.toolbar__search .toolbar__clear:hover { background: #e7e1f4; }
|
||||
|
||||
/* ---------- Stop search (รหัส 5 หลัก + ชื่อสถานที่ + ป้ายใกล้ฉัน) ---------- */
|
||||
.stop-search {
|
||||
background: #fff; border: 1px solid var(--line); border-radius: 16px;
|
||||
padding: 16px 18px; margin: 0 0 18px; box-shadow: 0 8px 20px rgba(63, 43, 94, .06);
|
||||
}
|
||||
.stop-search__tabs { display: flex; gap: 8px; margin-bottom: 14px; }
|
||||
.stop-search__tab {
|
||||
display: inline-flex; align-items: center; gap: 6px; padding: 8px 14px;
|
||||
border-radius: 999px; border: 1px solid #e6dff5; background: #f7f4fd;
|
||||
color: #6b5b8a; font: inherit; font-size: .85rem; font-weight: 700; cursor: pointer;
|
||||
}
|
||||
.stop-search__tab.on { background: var(--grad-cta); color: #fff; border-color: transparent; }
|
||||
.stop-search__panel { display: flex; flex-direction: column; gap: 12px; }
|
||||
.code-boxes { display: flex; gap: 8px; justify-content: center; }
|
||||
.code-cell {
|
||||
width: 46px; height: 54px; display: flex; align-items: center; justify-content: center;
|
||||
border-radius: 10px; border: 1px solid #d9d2ea; background: #faf9ff;
|
||||
font-size: 1.3rem; font-weight: 800; color: var(--ink); font-variant-numeric: tabular-nums;
|
||||
}
|
||||
.code-cell.filled { border-color: #a78bfa; background: #f5eeff; }
|
||||
.numpad { display: grid; grid-template-columns: repeat(5, 1fr); gap: 8px; max-width: 360px; margin: 0 auto; }
|
||||
.numpad button {
|
||||
height: 46px; border-radius: 10px; border: 1px solid #e6dff5; background: #fff;
|
||||
font: inherit; font-size: 1.05rem; font-weight: 700; color: var(--ink); cursor: pointer;
|
||||
}
|
||||
.numpad button:hover { background: #f5eeff; }
|
||||
.stop-search__actions { display: flex; gap: 8px; justify-content: center; flex-wrap: wrap; }
|
||||
.mu-btn.ghost {
|
||||
display: inline-flex; align-items: center; gap: 6px; padding: 8px 14px;
|
||||
border-radius: 999px; border: 1px solid #e6dff5; background: #fff; color: #6b5b8a;
|
||||
font: inherit; font-size: .85rem; font-weight: 700; cursor: pointer;
|
||||
}
|
||||
.stop-search__field { display: flex; align-items: center; gap: 8px; border: 1px solid #d9d2ea; border-radius: 12px; padding: 10px 12px; }
|
||||
.stop-search__field .icon { color: #8b5cf6; flex: none; }
|
||||
.stop-search__field input { flex: 1; border: none; outline: none; font: inherit; font-size: .95rem; color: var(--ink); }
|
||||
.stop-search__suggest { list-style: none; margin: 8px 0 0; padding: 0; border: 1px solid #e6dff5; border-radius: 12px; overflow: hidden; }
|
||||
.stop-search__suggest li { border-bottom: 1px solid #f0ecf8; }
|
||||
.stop-search__suggest li:last-child { border-bottom: 0; }
|
||||
.stop-search__suggest button {
|
||||
display: flex; align-items: center; gap: 10px; width: 100%; padding: 10px 12px;
|
||||
background: #fff; border: 0; font: inherit; text-align: left; cursor: pointer;
|
||||
}
|
||||
.stop-search__suggest button:hover { background: #f7f4fd; }
|
||||
.stop-search__suggest .km { flex: none; font-weight: 800; color: #7a4cc0; font-variant-numeric: tabular-nums; }
|
||||
.stop-search__suggest .name { flex: 1; color: var(--ink); font-weight: 600; }
|
||||
.stop-search__suggest .meta { flex: none; color: var(--muted); font-size: .8rem; }
|
||||
.stop-search__err { margin: 8px 0 0; color: #c0392b; font-size: .85rem; }
|
||||
|
||||
.busstop-result {
|
||||
margin-top: 14px; padding: 14px 16px; border: 1px solid #e7e0f6; border-radius: 14px;
|
||||
background: linear-gradient(135deg, #faf7ff, #fdf2f8); box-shadow: 0 6px 14px rgba(122, 76, 192, .08);
|
||||
}
|
||||
.busstop-result__head { display: flex; align-items: center; gap: 10px; flex-wrap: wrap; }
|
||||
.busstop-result__km {
|
||||
flex: none; background: linear-gradient(135deg, #7a4cc0, #b07ce0); color: #fff;
|
||||
padding: 4px 10px; border-radius: 8px; font-weight: 800; font-variant-numeric: tabular-nums;
|
||||
}
|
||||
.busstop-result__name { flex: 1; color: var(--ink); font-weight: 700; }
|
||||
.busstop-result__dist { flex: none; color: #7a4cc0; font-weight: 700; font-size: .85rem; }
|
||||
.busstop-result__meta { margin: 6px 0 0; color: var(--muted); font-size: .85rem; }
|
||||
.busstop-result__chips { display: flex; flex-wrap: wrap; gap: 6px; margin-top: 8px; }
|
||||
.stop-search__nearby { margin-top: 14px; }
|
||||
.stop-search__nearby h3 { margin: 0 0 10px; font-size: .95rem; color: var(--ink); }
|
||||
|
||||
|
||||
@@ -1,7 +1,10 @@
|
||||
import "./globals.css";
|
||||
import type { Metadata, Viewport } from "next";
|
||||
import { headers } from "next/headers";
|
||||
import { Header } from "@/components/Header";
|
||||
import { Footer } from "@/components/Footer";
|
||||
import { LangProvider } from "@/components/LangProvider";
|
||||
import { langFromCookie } from "@/lib/i18n";
|
||||
|
||||
export const metadata: Metadata = {
|
||||
title: "Atroute — สถานีขนส่งผู้โดยสารจังหวัดอ่างทอง",
|
||||
@@ -17,9 +20,12 @@ export const viewport: Viewport = {
|
||||
themeColor: "#7a4cc0",
|
||||
};
|
||||
|
||||
export default function RootLayout({ children }: { children: React.ReactNode }) {
|
||||
export default async function RootLayout({ children }: { children: React.ReactNode }) {
|
||||
const h = await headers();
|
||||
const lang = langFromCookie(h.get("cookie"));
|
||||
|
||||
return (
|
||||
<html lang="th">
|
||||
<html lang={lang}>
|
||||
<head>
|
||||
{/* K2D (offline, local woff2 — ตรงกับ design) + Noto/Prompt fallback (CDN) */}
|
||||
<link rel="stylesheet" href="/fonts/k2d.css" />
|
||||
@@ -29,9 +35,11 @@ export default function RootLayout({ children }: { children: React.ReactNode })
|
||||
/>
|
||||
</head>
|
||||
<body>
|
||||
<Header />
|
||||
{children}
|
||||
<Footer />
|
||||
<LangProvider initial={lang}>
|
||||
<Header />
|
||||
{children}
|
||||
<Footer />
|
||||
</LangProvider>
|
||||
</body>
|
||||
</html>
|
||||
);
|
||||
|
||||
@@ -15,7 +15,10 @@ import { VisitTracker } from "@/lib/visit-tracker";
|
||||
import { routePhoto } from "@/lib/images";
|
||||
import { routePath } from "@/lib/geojson";
|
||||
import { captionFor } from "@/lib/captions";
|
||||
import { kmFor } from "@/lib/stop-km";
|
||||
import { Icon } from "@/components/Icons";
|
||||
import { headers } from "next/headers";
|
||||
import { t, langFromCookie } from "@/lib/i18n";
|
||||
|
||||
const TONES = ["sky", "purple", "pink", "mint", "amber"] as const;
|
||||
|
||||
@@ -38,6 +41,9 @@ function nextTrip(schedules: Schedule[]): string | null {
|
||||
|
||||
export default async function RouteDetailPage({ params }: RouteDetailPageProps) {
|
||||
const { routeId } = await params;
|
||||
const h = await headers();
|
||||
const lang = langFromCookie(h.get("cookie"));
|
||||
const T = (k: string, v?: Record<string, string | number>) => t(k, lang, v);
|
||||
|
||||
let route: RouteDetail | null = null;
|
||||
let stops: RouteStop[] = [];
|
||||
@@ -179,7 +185,7 @@ export default async function RouteDetailPage({ params }: RouteDetailPageProps)
|
||||
<img className="vehicle-card__img" src={photo} alt={`รถของสาย ${route.route_id}`} />
|
||||
)}
|
||||
<div className="vehicle-card__meta">
|
||||
<p className="vehicle-card__label">รถประจำสาย</p>
|
||||
<p className="vehicle-card__label">{T("route.vehicle")}</p>
|
||||
{cap?.vehicle_title && <h2>{cap.vehicle_title}</h2>}
|
||||
{cap?.vehicle_desc && <p>{cap.vehicle_desc}</p>}
|
||||
{!cap?.vehicle_title && !cap?.vehicle_desc && (
|
||||
@@ -212,7 +218,7 @@ export default async function RouteDetailPage({ params }: RouteDetailPageProps)
|
||||
{/* แผนที่เส้นทาง + จุดจอดตามเส้นทาง */}
|
||||
<section className="route-map-section">
|
||||
<div className="route-map-section__head">
|
||||
<h2 className="section-title">เส้นทางเดินรถ</h2>
|
||||
<h2 className="section-title">{T("route.mapTitle")}</h2>
|
||||
<span className="route-map-section__legend">
|
||||
<span><i className="dot dot--start" /> ต้นทาง</span>
|
||||
<span><i className="dot dot--mid" /> จุดผ่าน</span>
|
||||
@@ -229,15 +235,18 @@ export default async function RouteDetailPage({ params }: RouteDetailPageProps)
|
||||
|
||||
{stops.length > 0 && (
|
||||
<div className="km-wrap">
|
||||
<h3 className="km-wrap__title">จุดจอดตามเส้นทาง (กม. จากต้นทาง)</h3>
|
||||
<h3 className="km-wrap__title">{T("map.alongRoute")}</h3>
|
||||
<ol className="km-list">
|
||||
{stops.map((s) => (
|
||||
<li key={s.station_id}>
|
||||
<span className="km-list__num">{s.stop_sequence}</span>
|
||||
<span className="km-list__name">{s.name_th}</span>
|
||||
{s.city_th && <span className="km-list__loc">{s.city_th}</span>}
|
||||
</li>
|
||||
))}
|
||||
{stops.map((s) => {
|
||||
const km = kmFor(route.route_id, s.station_id);
|
||||
return (
|
||||
<li key={s.station_id}>
|
||||
<span className="km-list__num">{km != null ? km.toFixed(1) : s.stop_sequence}</span>
|
||||
<span className="km-list__name">{s.name_th}</span>
|
||||
<span className="km-list__loc">{km != null ? "กม." : s.city_th ?? ""}</span>
|
||||
</li>
|
||||
);
|
||||
})}
|
||||
</ol>
|
||||
</div>
|
||||
)}
|
||||
@@ -245,7 +254,7 @@ export default async function RouteDetailPage({ params }: RouteDetailPageProps)
|
||||
|
||||
{/* จุดจอดตามลำดับ (รายละเอียด) */}
|
||||
<section>
|
||||
<h2 className="section-title">จุดจอดตามลำดับ ({stops.length})</h2>
|
||||
<h2 className="section-title">{T("route.stopsTitle")} ({stops.length})</h2>
|
||||
<ol className="stop-timeline">
|
||||
{stops.map((s, i) => {
|
||||
const tone = TONES[i % TONES.length];
|
||||
@@ -292,7 +301,7 @@ export default async function RouteDetailPage({ params }: RouteDetailPageProps)
|
||||
|
||||
{/* ตารางเวลา */}
|
||||
<section>
|
||||
<h2 className="section-title">ตารางเวลา ({schedules.length})</h2>
|
||||
<h2 className="section-title">{T("route.scheduleTitle")} ({schedules.length})</h2>
|
||||
{schedules.length === 0 ? (
|
||||
<p className="muted">ยังไม่มีข้อมูลตารางเวลา</p>
|
||||
) : (
|
||||
|
||||
@@ -6,6 +6,8 @@ import { LiveClock } from "@/components/LiveClock";
|
||||
import { VisitTracker } from "@/lib/visit-tracker";
|
||||
import { stopPhoto } from "@/lib/images";
|
||||
import { Icon } from "@/components/Icons";
|
||||
import { headers } from "next/headers";
|
||||
import { t, langFromCookie } from "@/lib/i18n";
|
||||
|
||||
const TYPE_LABEL: Record<string, string> = {
|
||||
main_terminal: "สถานีขนส่ง",
|
||||
@@ -30,6 +32,10 @@ export default async function StopDetailsPage({ searchParams }: StopDetailsPageP
|
||||
const { code } = await searchParams;
|
||||
if (!code) notFound();
|
||||
|
||||
const h = await headers();
|
||||
const lang = langFromCookie(h.get("cookie"));
|
||||
const T = (k: string, v?: Record<string, string | number>) => t(k, lang, v);
|
||||
|
||||
let stop: StopDetail | null = null;
|
||||
let schedules: Schedule[] = [];
|
||||
|
||||
@@ -132,7 +138,7 @@ export default async function StopDetailsPage({ searchParams }: StopDetailsPageP
|
||||
|
||||
<div className="stop-layout">
|
||||
<div className="stop-panel">
|
||||
<h2 className="section-title">สายรถที่ผ่านจุดนี้</h2>
|
||||
<h2 className="section-title">{T("stop.routes")}</h2>
|
||||
{routes.length === 0 ? (
|
||||
<p className="muted">ยังไม่มีข้อมูลสายที่ผ่าน</p>
|
||||
) : (
|
||||
@@ -171,7 +177,7 @@ export default async function StopDetailsPage({ searchParams }: StopDetailsPageP
|
||||
</div>
|
||||
|
||||
<aside className="stop-panel">
|
||||
<h2 className="section-title">แผนที่และข้อมูลป้าย</h2>
|
||||
<h2 className="section-title">{T("stop.mapInfo")}</h2>
|
||||
{hasMap ? (
|
||||
<div className="map-wrap map-wrap--soft">
|
||||
<LazyMapView points={mapPoints} />
|
||||
|
||||
@@ -3,6 +3,7 @@ import { api } from "@/lib/api";
|
||||
import LazyMapView from "@/components/LazyMapView";
|
||||
import { VisitTracker } from "@/lib/visit-tracker";
|
||||
import { Icon, type IconName } from "@/components/Icons";
|
||||
import { StopSearch } from "@/components/StopSearch";
|
||||
|
||||
const TONES = ["sky", "purple", "pink", "mint", "amber"] as const;
|
||||
const TYPE_TONE: Record<string, (typeof TONES)[number]> = {
|
||||
@@ -82,6 +83,9 @@ export default async function StopsPage({
|
||||
</div>
|
||||
)}
|
||||
|
||||
{/* ค้นหาป้ายทางหลวง: รหัส 5 หลัก + ชื่อสถานที่ + ป้ายใกล้ฉัน */}
|
||||
<StopSearch />
|
||||
|
||||
<div className="toolbar">
|
||||
<form className="toolbar__search" action="/stops" method="get" role="search">
|
||||
<Icon name="search" size={16} className="icon" />
|
||||
|
||||
Reference in new issue
Block a user