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

+19
View File
@@ -938,4 +938,23 @@ img { max-width: 100%; display: block; }
vertical-align: -0.15em; flex: none;
}
/* ---------- Legend (คำอธิบายสีการ์ดตามหมวดเส้นทาง) ---------- */
.legend {
background: #fff; border: 1px solid var(--line); border-radius: 14px;
padding: 16px 18px; margin-bottom: 26px; box-shadow: var(--shadow-sm);
}
.legend__title { margin: 0 0 12px; font-size: .95rem; font-weight: 800; color: var(--ink); }
.legend__list {
list-style: none; margin: 0; padding: 0; display: grid;
grid-template-columns: repeat(auto-fit, minmax(240px, 1fr)); gap: 10px 18px;
}
.legend__list li { display: flex; align-items: center; gap: 9px; font-size: .86rem; color: var(--ink-muted); }
.legend__sw { width: 26px; height: 16px; border-radius: 4px; flex: none; border: 1px solid rgba(20, 40, 90, .12); }
.legend__sw--sky { background: var(--grad-sky); }
.legend__sw--purple { background: var(--grad-purple); }
.legend__sw--pink { background: var(--grad-pink); }
.legend__sw--mint { background: var(--grad-mint); }
.legend__sw--gray { background: #e4e7eb; }
.chip.gray { background: #e8eaed; color: #5b636e; }
+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>
);
+5 -27
View File
@@ -1,9 +1,10 @@
import Link from "next/link";
import { notFound } from "next/navigation";
import { api, isApiNotFoundError, resolveFileUrl, type RouteDetail, type RouteStop, type StopListItem, type Schedule } from "@/lib/api";
import { api, isApiNotFoundError, type RouteDetail, type RouteStop, type StopListItem, type Schedule } from "@/lib/api";
import LazyMapView from "@/components/LazyMapView";
import { VisitTracker } from "@/lib/visit-tracker";
import { routePhoto } from "@/lib/images";
import { routePath } from "@/lib/geojson";
import { Icon } from "@/components/Icons";
const TONES = ["sky", "purple", "pink", "mint", "amber"] as const;
@@ -75,7 +76,9 @@ export default async function RouteDetailPage({
})
.filter((x): x is NonNullable<typeof x> => x !== null);
const path: [number, number][] = mapPoints.map((p) => [p.lat, p.lng]);
const stopPath: [number, number][] = mapPoints.map((p) => [p.lat, p.lng]);
// เส้นทางจริงจาก design (geojson-web/<id>.geojson) ถ้ามี — ไม่งั้นใช้เส้นตรงเชื่อมจุดจอด
const path: [number, number][] = routePath(route.route_id) ?? stopPath;
const provinceSet = new Set(
stops.map((s) => s.province_th).filter((x): x is string => !!x),
);
@@ -121,23 +124,6 @@ export default async function RouteDetailPage({
← กลับสายทั้งหมด
</Link>
</div>
{/* ภาพประกอบ */}
{route.images && route.images.length > 0 && (
<section>
<h2 className="section-title">ภาพประกอบ</h2>
<div className="grid">
{route.images.map((img) => (
<figure key={img.id} className="card" style={{ padding: 8 }}>
<img
src={resolveFileUrl(img.url_path)}
alt={String((img.meta as any)?.alt_th || route.name_th)}
style={{ width: "100%", borderRadius: 12, display: "block" }}
/>
</figure>
))}
</div>
</section>
)}
{/* ติดต่อ */}
<section>
@@ -154,14 +140,6 @@ export default async function RouteDetailPage({
<p className="muted">ไม่พบเบอร์ติดต่อ</p>
)}
</section>
{/* เมตาดาตา */}
<section>
<h2 className="section-title">เมตาดาตา</h2>
<pre className="card" style={{ overflow: "auto", padding: 16 }}>
{JSON.stringify(route.metadata, null, 2)}
</pre>
</section>
</section>
{photo && (