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
209 lines
9.4 KiB
TypeScript
209 lines
9.4 KiB
TypeScript
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";
|
|
|
|
// 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",
|
|
};
|
|
|
|
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([
|
|
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[]>();
|
|
for (const r of routes) {
|
|
const list = byCode.get(r.route_group_code) ?? [];
|
|
list.push(r);
|
|
byCode.set(r.route_group_code, list);
|
|
}
|
|
|
|
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];
|
|
|
|
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>ผู้สนับสนุน & พาร์ทเนอร์</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>
|
|
|
|
</>
|
|
);
|
|
}
|