feat(ui): sync data from mock + port legend/next-trip/route map

Data:
- sync DB (routes/stations/route_stops/route_provinces/schedules) from
  web-at-transit-mock/resource/data: route 999 -> bangkok group, 1011 name,
  15 stations w/ coordinates, 33 schedules; drop stale stations
- add geojson-web route polylines (frontend/public/data) + lib/geojson.ts;
  route detail now draws the real route path

UI:
- home: legend (คำอธิบายสีการ์ด) + next-trip chip (เที่ยวถัดไป HH:MM /
  ดูตาราง / ยังไม่มีตาราง) computed from schedules
- route detail: drop the debug 'เมตาดาตา' JSON dump + empty ภาพประกอบ
- globals.css: legend styles
This commit is contained in:
phattaranun.a committed 2026-10-10 19:00:54 +07:00
1 parent 37711a0a8a
commit 490e6c7d71
33 files changed
+158 -49

No files matched your search

+79 -22
View File
@@ -1,5 +1,5 @@
import Link from "next/link";
import { api, type RouteListItem } from "@/lib/api";
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";
@@ -19,20 +19,49 @@ const ZONE_DESCS: Record<string, string> = {
municipal: "เส้นทางภายในเขตเทศบาล",
};
// Display order: bangkok → interprovincial → in_province → municipal
const ZONE_ORDER = ["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 แทนเลขสาย" },
];
// Cycle chip colors within a zone for visual rhythm
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] = await Promise.allSettled([
const [groupsRes, routesRes, schedRes] = await Promise.allSettled([
api.routeGroups(),
api.routes(),
api.schedules({}),
]);
const groups = groupsRes.status === "fulfilled" ? groupsRes.value.items : [];
const routes = routesRes.status === "fulfilled" ? routesRes.value.items : [];
const schedules: Schedule[] = schedRes.status === "fulfilled" ? schedRes.value.items : [];
// route_id -> all departure times (ทุกทิศทาง/จุดจอด)
const timesByRoute = new Map<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);
}
// Group routes by code
const byCode = new Map<string, RouteListItem[]>();
@@ -109,6 +138,19 @@ export default async function HomePage() {
<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;
@@ -122,23 +164,38 @@ export default async function HomePage() {
</p>
</div>
<div className="grid">
{items.map((r, i) => (
<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>
<span className={`chip ${CHIP_CYCLE[i % CHIP_CYCLE.length]}`}>
<Icon name="check" size={12} className="icon" /> ดูตาราง
</span>
</div>
</Link>
))}
{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>
);