feat(ui): port route/stop/check pages to match mock + tidy layout
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)
This commit is contained in:
1 parent
b022a85178
commit
0c3936df69
24 files changed
+1084
-303
No files matched your search
@@ -6,40 +6,55 @@ import { Icon, type IconName } from "@/components/Icons";
|
||||
|
||||
const TONES = ["sky", "purple", "pink", "mint", "amber"] as const;
|
||||
const TYPE_TONE: Record<string, (typeof TONES)[number]> = {
|
||||
terminal: "purple",
|
||||
station: "sky",
|
||||
pickup: "amber",
|
||||
main_terminal: "purple",
|
||||
local_stop: "sky",
|
||||
market: "pink",
|
||||
landmark: "mint",
|
||||
private_stop: "amber",
|
||||
other: "mint",
|
||||
};
|
||||
const TYPE_ICON: Record<string, IconName> = {
|
||||
terminal: "bus-front",
|
||||
station: "map-pin",
|
||||
pickup: "bus",
|
||||
main_terminal: "bus-front",
|
||||
local_stop: "map-pin",
|
||||
market: "store",
|
||||
landmark: "map-pin",
|
||||
private_stop: "bus",
|
||||
other: "map-pin",
|
||||
};
|
||||
const TYPE_LABEL: Record<string, string> = {
|
||||
terminal: "สถานีขนส่ง",
|
||||
station: "ป้ายหลัก",
|
||||
pickup: "จุดรับส่ง",
|
||||
main_terminal: "สถานีขนส่ง",
|
||||
local_stop: "ป้ายหลัก",
|
||||
market: "ตลาด/ชุมชน",
|
||||
landmark: "จุดสังเกต",
|
||||
private_stop: "จุดรับส่ง",
|
||||
other: "อื่น ๆ",
|
||||
};
|
||||
|
||||
export default async function StopsPage() {
|
||||
const { items } = await api.stops().catch(() => ({ items: [] }));
|
||||
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" />
|
||||
@@ -60,80 +75,73 @@ export default async function StopsPage() {
|
||||
</div>
|
||||
</section>
|
||||
|
||||
{points.length > 0 && (
|
||||
<div className="map-wrap map-wrap--soft">
|
||||
<LazyMapView points={points} />
|
||||
</div>
|
||||
)}
|
||||
<div className="container">
|
||||
{points.length > 0 && !q && (
|
||||
<div className="map-wrap map-wrap--soft">
|
||||
<LazyMapView points={points} />
|
||||
</div>
|
||||
)}
|
||||
|
||||
<div className="toolbar">
|
||||
<div className="toolbar__search">
|
||||
<Icon name="search" size={16} className="icon" />
|
||||
<input placeholder="ค้นหาชื่อป้าย หรือจังหวัด…" disabled />
|
||||
<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>
|
||||
<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>
|
||||
|
||||
<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;
|
||||
return (
|
||||
stopHref ? (
|
||||
<Link
|
||||
key={s.id}
|
||||
href={stopHref}
|
||||
className={`tile tile--${tone}`}
|
||||
>
|
||||
<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>
|
||||
)}
|
||||
{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>
|
||||
<span className="tile__arrow" aria-hidden>→</span>
|
||||
</Link>
|
||||
) : (
|
||||
<div key={s.id} className={`tile tile--${tone} tile--disabled`}>
|
||||
<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 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>
|
||||
<span className="tile__arrow" aria-hidden>→</span>
|
||||
</div>
|
||||
)
|
||||
);
|
||||
})}
|
||||
);
|
||||
})}
|
||||
</div>
|
||||
)}
|
||||
</div>
|
||||
</main>
|
||||
);
|
||||
}
|
||||
|
||||
Reference in new issue
Block a user