Route detail: - breadcrumb + route-select dropdown (เปลี่ยนสายในหน้าเดียว) - vehicle card (รถ + caption + QR + ติดต่อโทร/LINE รวมการ์ดเดียว) - summary เพิ่ม 'รอบถัดไป' (คำนวณจาก schedules) - km list (จุดจอดตามเส้นทาง กม.) Stop detail: - stop-hero (title/meta pills/metric grid 4 + live clock เที่ยวถัดไป) - route expander (สายที่ผ่าน + เวลาต่อสาย) + map aside + chips - breadcrumb Stop list: - search form จริง (server-side ?q=) + breadcrumb - fix TYPE_LABEL/TONE/ICON ให้ตรง station_type จริง (main_terminal/local_stop/market/private_stop) Check page (ใหม่ /check): เช็กเวลาเดินรถ + selector + 4 สถิติ + ตารางทุกจุดจอด Header CTA -> /check Assets: caption<id>.json + qrcode/* จาก mock (lib/captions.ts)
148 lines
5.9 KiB
TypeScript
148 lines
5.9 KiB
TypeScript
import Link from "next/link";
|
|
import { api } from "@/lib/api";
|
|
import LazyMapView from "@/components/LazyMapView";
|
|
import { VisitTracker } from "@/lib/visit-tracker";
|
|
import { Icon, type IconName } from "@/components/Icons";
|
|
|
|
const TONES = ["sky", "purple", "pink", "mint", "amber"] as const;
|
|
const TYPE_TONE: Record<string, (typeof TONES)[number]> = {
|
|
main_terminal: "purple",
|
|
local_stop: "sky",
|
|
market: "pink",
|
|
private_stop: "amber",
|
|
other: "mint",
|
|
};
|
|
const TYPE_ICON: Record<string, IconName> = {
|
|
main_terminal: "bus-front",
|
|
local_stop: "map-pin",
|
|
market: "store",
|
|
private_stop: "bus",
|
|
other: "map-pin",
|
|
};
|
|
const TYPE_LABEL: Record<string, string> = {
|
|
main_terminal: "สถานีขนส่ง",
|
|
local_stop: "ป้ายหลัก",
|
|
market: "ตลาด/ชุมชน",
|
|
private_stop: "จุดรับส่ง",
|
|
other: "อื่น ๆ",
|
|
};
|
|
|
|
export default async function StopsPage({
|
|
searchParams,
|
|
}: {
|
|
searchParams: Promise<{ q?: string }>;
|
|
}) {
|
|
const sp = await searchParams;
|
|
const q = sp.q ?? "";
|
|
const { items } = await api.stops(q ? { q } : {}).catch(() => ({ items: [] }));
|
|
|
|
const points = items
|
|
.filter((s) => s.lat != null && s.lng != null)
|
|
.map((s) => ({ id: s.id, lat: s.lat as number, lng: s.lng as number, label: s.name_th, code: s.code }));
|
|
|
|
const typeCounts = items.reduce<Record<string, number>>((acc, s) => {
|
|
acc[s.station_type] = (acc[s.station_type] ?? 0) + 1;
|
|
return acc;
|
|
}, {});
|
|
|
|
return (
|
|
<main className="page">
|
|
<VisitTracker path="/stops" />
|
|
|
|
<div className="container">
|
|
<p className="breadcrumb">
|
|
<Link href="/">หน้าแรก</Link> / <span>ป้ายหยุดรถ</span>
|
|
</p>
|
|
</div>
|
|
|
|
<section className="page-hero">
|
|
<div className="page-hero__blob page-hero__blob--a" />
|
|
<div className="page-hero__blob page-hero__blob--b" />
|
|
<div className="page-hero__blob page-hero__blob--c" />
|
|
<div className="page-hero__inner">
|
|
<span className="page-hero__badge"><Icon name="map-pin" size={13} className="icon" /> STOP DIRECTORY</span>
|
|
<h1 className="page-hero__title">
|
|
จุดจอด<span className="page-hero__title-grad">ทั่วประเทศ</span>
|
|
</h1>
|
|
<p className="page-hero__subtitle">
|
|
ค้นหาป้าย / สถานีขนส่ง พร้อมแผนที่และเส้นทางที่ผ่าน
|
|
</p>
|
|
<div className="page-hero__stats">
|
|
<span className="page-hero__stat"><b>{items.length}</b> จุดจอด</span>
|
|
<span className="page-hero__stat"><b>{points.length}</b> มีพิกัด</span>
|
|
<span className="page-hero__stat"><b>{Object.keys(typeCounts).length}</b> ประเภท</span>
|
|
</div>
|
|
</div>
|
|
</section>
|
|
|
|
<div className="container">
|
|
{points.length > 0 && !q && (
|
|
<div className="map-wrap map-wrap--soft">
|
|
<LazyMapView points={points} />
|
|
</div>
|
|
)}
|
|
|
|
<div className="toolbar">
|
|
<form className="toolbar__search" action="/stops" method="get" role="search">
|
|
<Icon name="search" size={16} className="icon" />
|
|
<input name="q" placeholder="ค้นหาชื่อป้าย หรือจังหวัด…" defaultValue={q} />
|
|
{q && (
|
|
<Link className="toolbar__clear" href="/stops" aria-label="ล้างคำค้นหา">✕</Link>
|
|
)}
|
|
<button type="submit" className="toolbar__submit">ค้นหา</button>
|
|
</form>
|
|
<div className="toolbar__chips">
|
|
{Object.entries(typeCounts).map(([t, n]) => (
|
|
<span key={t} className={`chip-soft chip-soft--${TYPE_TONE[t] ?? "sky"}`}>
|
|
<Icon name={TYPE_ICON[t] ?? "map-pin"} size={13} className="icon" /> {TYPE_LABEL[t] ?? t} · {n}
|
|
</span>
|
|
))}
|
|
</div>
|
|
</div>
|
|
|
|
{items.length === 0 ? (
|
|
<p className="muted">ไม่พบป้ายที่ตรงกับ “{q}”</p>
|
|
) : (
|
|
<div className="tile-grid">
|
|
{items.map((s, i) => {
|
|
const tone = TYPE_TONE[s.station_type] ?? TONES[i % TONES.length];
|
|
const icon = TYPE_ICON[s.station_type] ?? "map-pin";
|
|
const place = [s.city_th, s.province_th].filter(Boolean).join(" · ");
|
|
const stopHref = s.code ? `/stops/${encodeURIComponent(s.code)}` : null;
|
|
const body = (
|
|
<>
|
|
<div className={`tile__badge tile__badge--${tone}`}>
|
|
<Icon name={icon} size={26} />
|
|
</div>
|
|
<div className="tile__body">
|
|
<p className="tile__title">{s.name_th}</p>
|
|
<p className="tile__meta">{place || "—"}</p>
|
|
<div className="tile__chips">
|
|
<span className={`chip-soft chip-soft--${tone}`}>
|
|
{TYPE_LABEL[s.station_type] ?? s.station_type}
|
|
</span>
|
|
{s.lat != null && s.lng != null && (
|
|
<span className="chip-soft chip-soft--mint"><Icon name="map-pin" size={13} className="icon" /> บนแผนที่</span>
|
|
)}
|
|
</div>
|
|
</div>
|
|
<span className="tile__arrow" aria-hidden>→</span>
|
|
</>
|
|
);
|
|
return stopHref ? (
|
|
<Link key={s.id} href={stopHref} className={`tile tile--${tone}`}>
|
|
{body}
|
|
</Link>
|
|
) : (
|
|
<div key={s.id} className={`tile tile--${tone} tile--disabled`}>
|
|
{body}
|
|
</div>
|
|
);
|
|
})}
|
|
</div>
|
|
)}
|
|
</div>
|
|
</main>
|
|
);
|
|
}
|