feat(ui): province→station selector, filter, share, visitor, lang, nav+pages

- HomeClient (client): จังหวัด→สถานี cascade selector (default อ่างทอง),
  กรองเส้นทางตามจังหวัด/สถานี, โชว์โซนว่างเป็น N/A card, ปุ่มแชร์ลิงก์สั้น
- page.tsx: fetch provinces/stops/routeStops + searchParams (p/s) for share link
- Header: nav 6 เมนู + สลับภาษา ไทย/EN (localStorage)
- Footer: ตัวนับผู้เข้าชม (visitsSummary) + เมนู 6 รายการ
- หน้าใหม่ /about /blog /credits (เนื้อหา+รูปจาก mock about-data/blog-data)
- globals.css: selector/share/empty-card/about/blog/credit styles
This commit is contained in:
phattaranun.a committed 2026-10-10 19:38:32 +07:00
1 parent 490e6c7d71
commit b022a85178
27 files changed
+1481 -199

No files matched your search

+36 -185
View File
@@ -1,208 +1,59 @@
import Link from "next/link";
import { api, type RouteListItem, type Schedule } from "@/lib/api";
import { VisitTracker } from "@/lib/visit-tracker";
import { HERO_MAP, PARTNERS } from "@/lib/images";
import { Icon } from "@/components/Icons";
import HomeClient from "@/components/HomeClient";
// Map route_group_code to visual tone
const ZONE_TONES: Record<string, "sky" | "purple" | "pink" | "mint"> = {
bangkok: "sky",
interprovincial: "purple",
in_province: "pink",
municipal: "mint",
};
export default async function HomePage({
searchParams,
}: {
searchParams: Promise<{ p?: string; s?: string }>;
}) {
const sp = await searchParams;
const ZONE_DESCS: Record<string, string> = {
bangkok: "เส้นทางเชื่อมต่อกรุงเทพมหานคร",
interprovincial: "เส้นทางเชื่อมต่อจังหวัดใกล้เคียง",
in_province: "เส้นทางภายในจังหวัดอ่างทอง",
municipal: "เส้นทางภายในเขตเทศบาล",
};
// Display order: municipal → bangkok → interprovincial → in_province
const ZONE_ORDER = ["municipal", "bangkok", "interprovincial", "in_province"];
// Legend rows (คำอธิบายสีการ์ดตามหมวดเส้นทาง)
const LEGEND = [
{ tone: "sky", label: "หมวดเส้นทางเข้ากรุงเทพฯ — การ์ดสีน้ำเงิน" },
{ tone: "purple", label: "หมวดเส้นทางระหว่างจังหวัด — การ์ดสีม่วง" },
{ tone: "pink", label: "หมวดเส้นทางภายในจังหวัด — การ์ดสีชมพู" },
{ tone: "mint", label: "หมวดเส้นทางภายในเทศบาล — การ์ดสีเขียวมินต์" },
{ tone: "gray", label: "ยังไม่มีข้อมูล — การ์ดสีเทา แสดง N/A แทนเลขสาย" },
];
const CHIP_CYCLE = ["purple", "sky", "pink", "mint"] as const;
/** เที่ยวถัดไปของสาย = เที่ยวแรกที่ยังไม่ผ่าน */
function nextTrip(times: string[]): string | null {
const now = new Date();
const cur = now.getHours() * 60 + now.getMinutes();
for (const t of [...times].sort()) {
const [h, m] = t.split(":").map(Number);
if (h * 60 + m >= cur) return t;
}
return null;
}
export default async function HomePage() {
const [groupsRes, routesRes, schedRes] = await Promise.allSettled([
const [groupsRes, routesRes, schedRes, provRes, stopsRes] = await Promise.allSettled([
api.routeGroups(),
api.routes(),
api.schedules({}),
api.provinces(),
api.stops(),
]);
const groups = groupsRes.status === "fulfilled" ? groupsRes.value.items : [];
const routes = routesRes.status === "fulfilled" ? routesRes.value.items : [];
const routes: RouteListItem[] = routesRes.status === "fulfilled" ? routesRes.value.items : [];
const schedules: Schedule[] = schedRes.status === "fulfilled" ? schedRes.value.items : [];
const provinces = provRes.status === "fulfilled" ? provRes.value.items : [];
const stops = stopsRes.status === "fulfilled" ? stopsRes.value.items : [];
// route_id -> all departure times (ทุกทิศทาง/จุดจอด)
const timesByRoute = new Map<string, string[]>();
// route_id -> all departure times
const timesByRoute: Record<string, string[]> = {};
for (const s of schedules) {
const list = timesByRoute.get(s.route_id) ?? [];
list.push(...s.departure_times);
timesByRoute.set(s.route_id, list);
(timesByRoute[s.route_id] ??= []).push(...s.departure_times);
}
// Group routes by code
const byCode = new Map<string, RouteListItem[]>();
for (const r of routes) {
const list = byCode.get(r.route_group_code) ?? [];
list.push(r);
byCode.set(r.route_group_code, list);
}
// route_id -> station ids (for station-level filtering)
const routeStations: Record<string, number[]> = {};
await Promise.all(
routes.map(async (r) => {
const { items } = await api.routeStops(r.route_id).catch(() => ({ items: [] }));
routeStations[r.route_id] = items.map((x) => x.station_id);
}),
);
const orderedGroups = [...groups].sort((a, b) => {
const ai = ZONE_ORDER.indexOf(a.code);
const bi = ZONE_ORDER.indexOf(b.code);
return (ai === -1 ? 99 : ai) - (bi === -1 ? 99 : bi);
});
// Duplicate partner tiles for a seamless marquee loop
const marqueePartners = [...PARTNERS, ...PARTNERS];
const initialProvinceId = sp.p ? Number(sp.p) || undefined : undefined;
const initialStationCode = sp.s ?? undefined;
return (
<>
<VisitTracker path="/" />
<section className="hero">
{/* แผนที่เครือข่าย (จาก design: .image/network/overview-map.png) */}
<img className="hero__map" src={HERO_MAP} alt="" aria-hidden="true" />
<div className="hero__blob one" aria-hidden />
<div className="hero__blob two" aria-hidden />
<div className="hero__blob three" aria-hidden />
<div className="container hero__inner">
<span className="hero__badge">ยินดีต้อนรับ</span>
<h1>
สถานีขนส่งผู้โดยสารภายใน
<br />
<span className="hero__grad">จังหวัดอ่างทอง</span>
</h1>
<p className="hero__lead">
ดูสายรถ, ค้นหาป้าย และเปิดตัวอย่างเส้นทางได้ทันทีจากหน้าแรก
</p>
<div className="hero__actions">
<Link className="pill-link pill-link--primary" href="/routes">
ดูรายละเอียดสายรถ
</Link>
<Link className="pill-link pill-link--secondary" href="/stops">
ค้นหาป้ายหยุดรถ
</Link>
{routes[0] && (
<Link
className="pill-link pill-link--accent"
href={`/routes/${encodeURIComponent(routes[0].route_id)}`}
>
ดูตัวอย่างสายรถ
</Link>
)}
</div>
</div>
</section>
{/* ผู้สนับสนุน & พาร์ทเนอร์ (marquee — จาก design) */}
<section className="sponsor-section" aria-label="ผู้สนับสนุนและพาร์ทเนอร์">
<div className="sponsor-section__head">
<h4>ผู้สนับสนุน &amp; พาร์ทเนอร์</h4>
<p>ร่วมเป็นผู้สนับสนุนเราได้ เมื่อซื้อของออนไลน์ หรือซื้อตั๋วรถทัวร์ เครื่องบิน ออนไลน์</p>
</div>
<div className="marquee">
<div className="marquee__track">
{marqueePartners.map((p, i) => (
<span key={`${p.id}-${i}`} className="marquee__tile" aria-label={p.label}>
<img src={p.src} alt={p.label} decoding="async" loading="lazy" />
</span>
))}
</div>
</div>
</section>
<main className="main">
<div className="container">
{/* Legend — คำอธิบายสีการ์ดตามหมวดเส้นทาง (จาก design) */}
<section className="legend" aria-label="คำอธิบายสีการ์ดตามหมวดเส้นทาง">
<h2 className="legend__title">คำอธิบายสีการ์ดตามหมวดเส้นทาง</h2>
<ul className="legend__list">
{LEGEND.map((l) => (
<li key={l.tone}>
<span className={`legend__sw legend__sw--${l.tone}`} aria-hidden />
{l.label}
</li>
))}
</ul>
</section>
{orderedGroups.map((g) => {
const items = byCode.get(g.code) ?? [];
if (items.length === 0) return null;
const tone = ZONE_TONES[g.code] ?? "purple";
return (
<section key={g.id} className="zone">
<div className="zone__head">
<span className={`zone__tag ${tone}`}>{g.label_th}</span>
<p className="zone__desc">
{ZONE_DESCS[g.code] ?? ""} · {items.length} เส้นทาง
</p>
</div>
<div className="grid">
{items.map((r, i) => {
const times = timesByRoute.get(r.route_id) ?? [];
const next = nextTrip(times);
const chipTone = CHIP_CYCLE[i % CHIP_CYCLE.length];
return (
<Link
key={r.route_id}
href={`/routes/${encodeURIComponent(r.route_id)}`}
className="card"
>
<div className={`card__head ${tone}`}>
<p className="card__num">{r.route_id}</p>
</div>
<div className="card__body">
<p className="card__name">{r.name_th}</p>
{next ? (
<span className={`chip ${chipTone}`}>
<Icon name="clock" size={12} className="icon" /> เที่ยวถัดไป {next}
</span>
) : times.length > 0 ? (
<span className={`chip ${chipTone}`}>
<Icon name="check" size={12} className="icon" /> ดูตาราง
</span>
) : (
<span className="chip gray">
<Icon name="hourglass" size={12} className="icon" /> ยังไม่มีตาราง
</span>
)}
</div>
</Link>
);
})}
</div>
</section>
);
})}
</div>
</main>
<HomeClient
groups={groups}
routes={routes}
timesByRoute={timesByRoute}
provinces={provinces}
stops={stops}
routeStations={routeStations}
initialProvinceId={initialProvinceId}
initialStationCode={initialStationCode}
/>
</>
);
}