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
@@ -1,12 +1,26 @@
|
||||
import Link from "next/link";
|
||||
import { notFound } from "next/navigation";
|
||||
import { api, isApiNotFoundError, resolveFileUrl, type Schedule, type StopDetail } from "@/lib/api";
|
||||
import { api, isApiNotFoundError, type Schedule, type StopDetail } from "@/lib/api";
|
||||
import LazyMapView from "@/components/LazyMapView";
|
||||
import { LiveClock } from "@/components/LiveClock";
|
||||
import { VisitTracker } from "@/lib/visit-tracker";
|
||||
import { stopPhoto } from "@/lib/images";
|
||||
import { Icon } from "@/components/Icons";
|
||||
|
||||
const TONES = ["sky", "purple", "pink", "mint", "amber"] as const;
|
||||
const TYPE_LABEL: Record<string, string> = {
|
||||
main_terminal: "สถานีขนส่ง",
|
||||
local_stop: "ป้ายหลัก",
|
||||
market: "ตลาด/ชุมชน",
|
||||
private_stop: "จุดรับส่ง",
|
||||
other: "อื่น ๆ",
|
||||
};
|
||||
|
||||
const GROUP_TONE: Record<string, string> = {
|
||||
bangkok: "sky",
|
||||
interprovincial: "purple",
|
||||
in_province: "pink",
|
||||
municipal: "mint",
|
||||
};
|
||||
|
||||
type StopDetailsPageProps = {
|
||||
searchParams: Promise<{ code?: string }>;
|
||||
@@ -23,9 +37,7 @@ export default async function StopDetailsPage({ searchParams }: StopDetailsPageP
|
||||
stop = await api.stop(code);
|
||||
({ items: schedules } = await api.schedules({ stop_code: stop.code }));
|
||||
} catch (error) {
|
||||
if (isApiNotFoundError(error)) {
|
||||
notFound();
|
||||
}
|
||||
if (isApiNotFoundError(error)) notFound();
|
||||
stop = null;
|
||||
schedules = [];
|
||||
}
|
||||
@@ -42,100 +54,145 @@ export default async function StopDetailsPage({ searchParams }: StopDetailsPageP
|
||||
</main>
|
||||
);
|
||||
}
|
||||
const place = [stop.city_th, stop.province_th].filter(Boolean).join(" / ") || "—";
|
||||
|
||||
const place = [stop.city_th, stop.province_th].filter(Boolean).join(" · ") || "—";
|
||||
const hasMap = stop.lat != null && stop.lng != null;
|
||||
const mapPoints = hasMap
|
||||
? [{ id: stop.id, lat: stop.lat as number, lng: stop.lng as number, label: stop.name_th, code: stop.code }]
|
||||
: [];
|
||||
|
||||
// รูปป้ายจาก design (.image/stops/<code>.jpg) — สำคัญกว่า backend images
|
||||
const designPhoto = stopPhoto(stop.code);
|
||||
const typeLabel = TYPE_LABEL[stop.station_type] ?? stop.station_type;
|
||||
const routes = stop.routes ?? [];
|
||||
|
||||
// route_id -> เวลาออกทั้งหมดที่ป้ายนี้
|
||||
const timesByRoute = new Map<string, string[]>();
|
||||
for (const s of schedules) {
|
||||
const l = timesByRoute.get(s.route_id) ?? [];
|
||||
l.push(...s.departure_times);
|
||||
timesByRoute.set(s.route_id, l);
|
||||
}
|
||||
const allTimes = schedules.flatMap((s) => s.departure_times);
|
||||
|
||||
return (
|
||||
<main className="page">
|
||||
<VisitTracker path={`/stops/details?code=${stop.code}`} />
|
||||
<section className="hero">
|
||||
<span className="pill">{stop.station_type}</span>
|
||||
<h1 style={{ marginTop: 10 }}>{stop.name_th}</h1>
|
||||
<p className="muted"><Icon name="map-pin" size={14} className="icon" /> {place}{hasMap ? ` · ${stop.lat?.toFixed(4)}, ${stop.lng?.toFixed(4)}` : ""}</p>
|
||||
</section>
|
||||
<div className="stop-detail__split">
|
||||
{designPhoto ? (
|
||||
<div className="stop-detail__gallery">
|
||||
<img className="stop-detail__hero-img" src={designPhoto} alt={stop.name_th} />
|
||||
|
||||
<div className="container">
|
||||
<p className="breadcrumb">
|
||||
<Link href="/">หน้าแรก</Link> / <Link href="/stops">ป้ายหยุดรถ</Link> /{" "}
|
||||
<span>{stop.name_th}</span>
|
||||
</p>
|
||||
</div>
|
||||
|
||||
<div className="container">
|
||||
<section className="stop-hero">
|
||||
<div className="stop-hero__main">
|
||||
<h1 className="stop-hero__title">
|
||||
<Icon name="map-pin" size={24} className="icon" /> {stop.name_th}
|
||||
</h1>
|
||||
<p className="stop-hero__sub">
|
||||
<Icon name="map-pin" size={14} className="icon" /> {place}
|
||||
{hasMap ? ` · ${stop.lat?.toFixed(4)}, ${stop.lng?.toFixed(4)}` : ""}
|
||||
</p>
|
||||
<div className="stop-hero__meta">
|
||||
<span className="meta-pill purple">{typeLabel}</span>
|
||||
{stop.province_th && <span className="meta-pill sky">{stop.province_th}</span>}
|
||||
{hasMap && <span className="meta-pill mint">มีพิกัดบนแผนที่</span>}
|
||||
</div>
|
||||
<div className="stop-hero__metrics">
|
||||
<div className="stop-metric">
|
||||
<p className="stop-metric__label">สายที่ผ่าน</p>
|
||||
<p className="stop-metric__value">{routes.length}</p>
|
||||
</div>
|
||||
<div className="stop-metric">
|
||||
<p className="stop-metric__label">ประเภทป้าย</p>
|
||||
<p className="stop-metric__value">{typeLabel}</p>
|
||||
</div>
|
||||
<div className="stop-metric">
|
||||
<p className="stop-metric__label">จังหวัด</p>
|
||||
<p className="stop-metric__value">{stop.province_th ?? "—"}</p>
|
||||
</div>
|
||||
<div className="stop-metric">
|
||||
<p className="stop-metric__label">รอบเวลา</p>
|
||||
<p className="stop-metric__value">{allTimes.length}</p>
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
) : stop.images.length > 0 ? (
|
||||
<div className="stop-detail__gallery">
|
||||
<img
|
||||
className="stop-detail__hero-img"
|
||||
src={resolveFileUrl(stop.images[0].url_path)}
|
||||
alt={(stop.images[0].meta as { alt_th?: string } | undefined)?.alt_th ?? stop.name_th}
|
||||
/>
|
||||
{stop.images.length > 1 && (
|
||||
<div className="stop-detail__thumbs">
|
||||
{stop.images.slice(1, 5).map((img) => (
|
||||
<img key={img.id} src={resolveFileUrl(img.url_path)} alt={stop.name_th} />
|
||||
))}
|
||||
<div className="stop-hero__side">
|
||||
{designPhoto ? (
|
||||
<img className="stop-hero__photo" src={designPhoto} alt={stop.name_th} />
|
||||
) : (
|
||||
<div className="stop-hero__photo stop-hero__photo--empty">
|
||||
<Icon name="camera" size={28} className="icon" /> ยังไม่มีรูปป้ายนี้
|
||||
</div>
|
||||
)}
|
||||
<LiveClock times={allTimes} />
|
||||
</div>
|
||||
) : (
|
||||
<div className="stop-detail__gallery stop-detail__gallery--empty">
|
||||
<div className="stop-detail__placeholder"><Icon name="camera" size={20} className="icon" /> ยังไม่มีรูปป้ายนี้</div>
|
||||
</section>
|
||||
|
||||
<div className="stop-layout">
|
||||
<div className="stop-panel">
|
||||
<h2 className="section-title">สายรถที่ผ่านจุดนี้</h2>
|
||||
{routes.length === 0 ? (
|
||||
<p className="muted">ยังไม่มีข้อมูลสายที่ผ่าน</p>
|
||||
) : (
|
||||
<ul className="route-expander-list">
|
||||
{routes.map((r) => {
|
||||
const times = timesByRoute.get(r.route_id) ?? [];
|
||||
const tone = GROUP_TONE[r.route_group_code] ?? "purple";
|
||||
return (
|
||||
<li key={r.route_id}>
|
||||
<details className="route-expander">
|
||||
<summary>
|
||||
<span className={`route-expander__id ${tone}`}>{r.route_id}</span>
|
||||
<span className="route-expander__name">{r.name_th}</span>
|
||||
<span className="route-expander__count">{times.length} รอบ</span>
|
||||
</summary>
|
||||
<div className="route-expander__body">
|
||||
<Link href={`/routes/${encodeURIComponent(r.route_id)}`} className="route-expander__link">
|
||||
ดูรายละเอียดสาย {r.route_id} →
|
||||
</Link>
|
||||
{times.length === 0 ? (
|
||||
<p className="muted">ยังไม่มีรอบเวลา</p>
|
||||
) : (
|
||||
<div className="route-expander__times">
|
||||
{times.map((t, j) => (
|
||||
<span key={j} className="time-chip"><Icon name="clock" size={12} className="icon" /> {t}</span>
|
||||
))}
|
||||
</div>
|
||||
)}
|
||||
</div>
|
||||
</details>
|
||||
</li>
|
||||
);
|
||||
})}
|
||||
</ul>
|
||||
)}
|
||||
</div>
|
||||
)}
|
||||
{hasMap ? (
|
||||
<div className="stop-detail__map">
|
||||
<LazyMapView points={mapPoints} />
|
||||
</div>
|
||||
) : (
|
||||
<div className="stop-detail__map stop-detail__map--empty">
|
||||
<div className="stop-detail__placeholder"><Icon name="map" size={20} className="icon" /> ยังไม่มีพิกัดของป้ายนี้</div>
|
||||
</div>
|
||||
)}
|
||||
</div>
|
||||
<h2 className="section-title">ตารางเวลาที่จุดนี้</h2>
|
||||
{schedules.length === 0 ? (
|
||||
<p className="muted">ยังไม่มีข้อมูล</p>
|
||||
) : (
|
||||
<div className="schedule-list">
|
||||
{schedules.map((s, i) => {
|
||||
const tone = TONES[i % TONES.length];
|
||||
return (
|
||||
<article key={s.id} className={`schedule-card schedule-card--${tone}`}>
|
||||
<div className="schedule-card__rail" />
|
||||
<div className="schedule-card__head">
|
||||
<Link
|
||||
href={`/routes/${encodeURIComponent(s.route_id)}`}
|
||||
className={`schedule-card__route ${tone}`}
|
||||
>
|
||||
<span className="schedule-card__route-label">เส้นทาง</span>
|
||||
<span className="schedule-card__route-id">{s.route_id}</span>
|
||||
</Link>
|
||||
<div className="schedule-card__meta">
|
||||
<span className="schedule-card__direction">
|
||||
<Icon name="globe" size={13} className="icon" />
|
||||
{s.direction_note || "ไม่ระบุทิศทาง"}
|
||||
</span>
|
||||
{s.schedule_note && (
|
||||
<span className="schedule-card__note"><Icon name="message-circle" size={13} className="icon" /> {s.schedule_note}</span>
|
||||
)}
|
||||
</div>
|
||||
</div>
|
||||
<div className="schedule-card__times">
|
||||
{s.departure_times.length === 0 ? (
|
||||
<span className="schedule-card__empty">— ยังไม่มีรอบ —</span>
|
||||
) : (
|
||||
s.departure_times.map((t, j) => (
|
||||
<span key={j} className="schedule-card__time"><Icon name="clock" size={13} className="icon" /> {t}</span>
|
||||
))
|
||||
)}
|
||||
</div>
|
||||
</article>
|
||||
);
|
||||
})}
|
||||
|
||||
<aside className="stop-panel">
|
||||
<h2 className="section-title">แผนที่และข้อมูลป้าย</h2>
|
||||
{hasMap ? (
|
||||
<div className="map-wrap map-wrap--soft">
|
||||
<LazyMapView points={mapPoints} />
|
||||
</div>
|
||||
) : (
|
||||
<div className="stop-panel__empty"><Icon name="map" size={20} className="icon" /> ยังไม่มีพิกัดของป้ายนี้</div>
|
||||
)}
|
||||
<div className="stop-chips">
|
||||
{routes.map((r) => (
|
||||
<Link
|
||||
key={r.route_id}
|
||||
href={`/routes/${encodeURIComponent(r.route_id)}`}
|
||||
className={`chip-soft chip-soft--${GROUP_TONE[r.route_group_code] ?? "sky"}`}
|
||||
>
|
||||
{r.route_id} · {r.vehicle_type}
|
||||
</Link>
|
||||
))}
|
||||
</div>
|
||||
</aside>
|
||||
</div>
|
||||
)}
|
||||
</div>
|
||||
</main>
|
||||
);
|
||||
}
|
||||
@@ -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