diff --git a/frontend/src/app/check/page.tsx b/frontend/src/app/check/page.tsx new file mode 100644 index 0000000..402b355 --- /dev/null +++ b/frontend/src/app/check/page.tsx @@ -0,0 +1,145 @@ +import Link from "next/link"; +import { api, type RouteListItem, type Schedule, type RouteStop, type RouteDetail } from "@/lib/api"; +import { RouteSelect } from "@/components/RouteSelect"; +import { VisitTracker } from "@/lib/visit-tracker"; +import { Icon } from "@/components/Icons"; + +const TONES = ["sky", "purple", "pink", "mint", "amber"] as const; + +function nextTrip(times: string[]): string | null { + if (times.length === 0) return 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; +} + +type CheckPageProps = { + searchParams: Promise<{ route?: string }>; +}; + +export default async function CheckPage({ searchParams }: CheckPageProps) { + const sp = await searchParams; + + const { items: allRoutes } = await api.routes().catch(() => ({ items: [] as RouteListItem[] })); + const routeId = + sp.route && allRoutes.some((r) => r.route_id === sp.route) + ? sp.route + : allRoutes[0]?.route_id; + + let route: RouteDetail | null = null; + let schedules: Schedule[] = []; + let stops: RouteStop[] = []; + + if (routeId) { + try { + [route, { items: schedules }, { items: stops }] = await Promise.all([ + api.route(routeId), + api.schedules({ route_id: routeId }), + api.routeStops(routeId), + ]); + } catch { + route = null; + schedules = []; + stops = []; + } + } + + const allTimes = schedules.flatMap((s) => s.departure_times); + const next = nextTrip(allTimes); + const provinceSet = new Set(stops.map((s) => s.province_th).filter((x): x is string => !!x)); + + return ( +
+ + +
+

+ หน้าแรก / เช็กเวลาเดินรถ +

+
+ +
+
+
+
+
+ + เช็กเวลาเดินรถ + +

+ ตารางเวลาเดินรถ +
+ {route?.name_th ?? "เลือกสายรถด้านล่าง"} +

+

เลือกสายรถ แล้วดูรอบรถทุกจุดจอดในหน้าเดียว

+ + {allRoutes.length > 0 && ( +
+ ({ route_id: r.route_id, name_th: r.name_th }))} + current={routeId ?? ""} + to={(id) => `/check?route=${encodeURIComponent(id)}`} + /> +
+ )} +
+
+ +
+ {/* สรุปเส้นทาง */} +
+
{stops.length}จุดจอดหลัก
+
{provinceSet.size}จังหวัดที่ผ่าน
+
{allTimes.length}รอบต่อวัน
+
{next ?? "—"}{next ? "รอบถัดไป" : "ไม่มีรอบวันนี้"}
+
+ + {/* ตารางเวลาทุกจุดจอด */} +
+

+ ตารางเวลาเดินรถทุกจุดจอด {route ? `— สาย ${route.route_id}` : ""} +

+ {schedules.length === 0 ? ( +

ยังไม่มีข้อมูลตารางเวลาสำหรับสายนี้

+ ) : ( +
+ {schedules.map((s, i) => { + const tone = TONES[i % TONES.length]; + return ( +
+ +
+
+ {s.station_name_th} + จุดต้นทาง +
+
+ {s.direction_note || "ทุกทิศทาง"} + {s.schedule_note && {s.schedule_note}} +
+
+ {s.departure_times.length === 0 ? ( + — ยังไม่มีรอบ — + ) : ( +
+ {s.departure_times.map((t, j) => ( + + {t} + + ))} +
+ )} +
+ ); + })} +
+ )} +
+
+
+ ); +} diff --git a/frontend/src/app/globals.css b/frontend/src/app/globals.css index 821a592..d89b27b 100644 --- a/frontend/src/app/globals.css +++ b/frontend/src/app/globals.css @@ -1074,4 +1074,205 @@ img { max-width: 100%; display: block; } font-size: .85rem; color: #4a5573; line-height: 1.6; } +/* ---------- Breadcrumb ---------- */ +.breadcrumb { color: var(--muted); font-size: .85rem; margin: 18px 0 4px; } +.breadcrumb a { color: #7a4cc0; font-weight: 600; text-decoration: none; } +.breadcrumb a:hover { text-decoration: underline; } +.breadcrumb span { color: var(--ink-muted); } + +/* ---------- Route selector (toolbar) ---------- */ +.route-select-wrap { flex: 1; min-width: 260px; } +.route-select-wrap__label { + display: flex; align-items: center; gap: 6px; margin: 0 0 6px 4px; + font-size: .8rem; font-weight: 700; color: var(--muted); +} +.route-select-wrap__label svg { color: #8b5cf6; flex: none; } +.select-box--toolbar { max-width: 480px; } + +/* ---------- Vehicle card (รถ + ติดต่อ + QR) ---------- */ +.vehicle-card { + display: grid; grid-template-columns: 1.3fr 1fr; + background: #fff; border: 1px solid var(--line); border-radius: 18px; + overflow: hidden; box-shadow: 0 4px 14px rgba(20, 40, 90, .06); + margin-bottom: 26px; +} +.vehicle-card__img { grid-column: 1; width: 100%; height: 100%; min-height: 240px; object-fit: cover; display: block; } +.vehicle-card__meta { grid-column: 2; padding: 24px; display: flex; flex-direction: column; justify-content: center; gap: 8px; } +.vehicle-card__label { margin: 0; font-size: .78rem; font-weight: 700; color: #7a4cc0; text-transform: uppercase; letter-spacing: .05em; } +.vehicle-card__meta h2 { margin: 0; font-size: 1.25rem; color: var(--ink); } +.vehicle-card__meta p { margin: 0; color: var(--muted); font-size: .95rem; line-height: 1.6; } +.vehicle-card__contact { + grid-column: 1 / -1; display: flex; flex-wrap: wrap; gap: 10px; + padding: 14px 18px; border-top: 1px solid var(--line); background: #faf9ff; +} +.contact-item { + flex: 1; min-width: 220px; display: flex; align-items: center; gap: 12px; + padding: 12px 14px; border-radius: 12px; background: #fff; border: 1px solid #eee; + text-decoration: none; color: inherit; transition: transform .15s ease, box-shadow .15s ease; +} +a.contact-item:hover { transform: translateY(-2px); box-shadow: 0 8px 18px rgba(20, 40, 90, .08); } +.contact-item .ic-wrap { + width: 42px; height: 42px; flex: none; display: flex; align-items: center; justify-content: center; + border-radius: 12px; background: linear-gradient(135deg, #7a4cc0, #b07ce0); color: #fff; +} +.contact-item .ic-wrap.tone-green { background: linear-gradient(135deg, #1f8765, #51c39c); } +.contact-item .txt { flex: 1; min-width: 0; } +.contact-item .txt strong { display: block; color: var(--ink); font-size: .98rem; margin-bottom: 2px; } +.contact-item .txt span { display: block; color: var(--muted); font-size: .86rem; } +.contact-item--qr { flex: 0 1 260px; cursor: zoom-in; } +.qr-img { + width: 56px; height: 56px; flex: none; object-fit: contain; + border-radius: 8px; padding: 4px; border: 1px solid #eee; background: #fff; +} +@media (max-width: 640px) { + .vehicle-card { grid-template-columns: 1fr; } + .vehicle-card__img { grid-column: 1; min-height: 200px; } + .vehicle-card__meta { grid-column: 1; padding: 18px; } + .vehicle-card__contact { grid-column: 1; flex-direction: column; } + .contact-item { min-width: 0; } +} + +/* ---------- KM list (จุดจอดตามเส้นทาง) ---------- */ +.km-wrap { margin-top: 18px; background: #fff; border: 1px solid var(--line); border-radius: 14px; padding: 14px 16px; } +.km-wrap__title { margin: 0 0 12px; font-size: .92rem; color: var(--ink); font-weight: 700; } +.km-list { list-style: none; margin: 0; padding: 0; display: grid; gap: 6px; } +.km-list li { display: flex; align-items: center; gap: 10px; font-size: .9rem; color: var(--ink-muted); } +.km-list__num { + flex: none; width: 26px; height: 26px; border-radius: 50%; background: #f1e9ff; + color: #7a4cc0; font-size: .78rem; font-weight: 700; display: flex; align-items: center; justify-content: center; +} +.km-list__name { font-weight: 600; color: var(--ink); } +.km-list__loc { margin-left: auto; font-size: .78rem; color: var(--muted); } + +/* ---------- Stop detail ---------- */ +.stop-hero { + display: grid; grid-template-columns: 1.2fr .8fr; gap: 16px; + background: linear-gradient(135deg, #f8f4ff 0%, #f2f6ff 45%, #eefaf5 100%); + border: 1px solid var(--line); border-radius: 22px; + box-shadow: 0 16px 34px rgba(122, 76, 192, .12); + padding: 18px; margin-bottom: 18px; +} +.stop-hero__title { margin: 0; font-size: 1.7rem; color: var(--ink); line-height: 1.2; display: flex; align-items: center; gap: 8px; overflow-wrap: anywhere; } +.stop-hero__title .icon { color: #7a4cc0; flex: none; } +.stop-hero__sub { margin: 8px 0 0; color: var(--muted); font-size: .9rem; } +.stop-hero__meta { display: flex; flex-wrap: wrap; gap: 8px; margin: 12px 0 0; } +.meta-pill { + background: linear-gradient(135deg, #fff, #f7f9ff); border: 1px solid var(--line); + color: #5b3b71; padding: 6px 14px; border-radius: 999px; font-size: .85rem; font-weight: 600; +} +.meta-pill.purple { background: linear-gradient(135deg, #f5eeff, #fce7f3); color: #7a4cc0; } +.meta-pill.sky { background: linear-gradient(135deg, #ebf5ff, #eff6ff); color: #3071b8; } +.meta-pill.mint { background: linear-gradient(135deg, #eafaf4, #ecfeff); color: #1f8765; } +.stop-hero__metrics { display: grid; grid-template-columns: repeat(2, 1fr); gap: 8px; margin-top: 14px; } +.stop-metric { + border: 1px solid var(--line); border-radius: 12px; padding: 10px; background: #fff; + box-shadow: 0 6px 14px rgba(122, 76, 192, .08); min-width: 0; +} +.stop-metric:nth-child(1) { background: linear-gradient(135deg, #f5efff, #fdf2f8); } +.stop-metric:nth-child(2) { background: linear-gradient(135deg, #ecfeff, #eef6ff); } +.stop-metric:nth-child(3) { background: linear-gradient(135deg, #fff1f2, #fff7ed); } +.stop-metric:nth-child(4) { background: linear-gradient(135deg, #ecfdf5, #f0fdfa); } +.stop-metric__label { margin: 0; color: var(--muted); font-size: .74rem; font-weight: 700; text-transform: uppercase; letter-spacing: .03em; } +.stop-metric__value { margin: 4px 0 0; color: var(--ink); font-size: 1.05rem; font-weight: 800; line-height: 1.2; overflow-wrap: anywhere; } +.stop-hero__side { display: flex; flex-direction: column; gap: 12px; } +.stop-hero__photo { width: 100%; height: 220px; object-fit: cover; border-radius: 16px; display: block; box-shadow: 0 10px 24px rgba(63, 43, 94, .16); } +.stop-hero__photo--empty { + display: flex; align-items: center; justify-content: center; gap: 8px; + color: var(--muted); background: #f7f4fd; border: 1px dashed #d9d2ea; +} + +/* live clock */ +.live-clock-card { + display: flex; align-items: center; justify-content: space-between; gap: 14px; + padding: 12px 14px; border: 1px solid rgba(240, 191, 224, .9); border-radius: 14px; + background: linear-gradient(135deg, #ffe8f4 0%, #f5f0ff 50%, #e8f7ff 100%); + box-shadow: 0 8px 20px rgba(122, 76, 192, .10); +} +.live-clock-title { margin: 0; color: var(--muted); font-size: .78rem; font-weight: 700; letter-spacing: .04em; text-transform: uppercase; } +.live-clock-time { margin: 2px 0 0; font-size: 1.65rem; line-height: 1; color: var(--ink); font-weight: 800; font-variant-numeric: tabular-nums; } +.live-clock-note { + margin: 0; padding: 6px 10px; border-radius: 999px; background: linear-gradient(135deg, #fff, #fff7fb); + border: 1px solid #eec7df; color: #9333ea; font-size: .78rem; font-weight: 600; white-space: nowrap; +} +.live-dot { + display: inline-block; width: 10px; height: 10px; border-radius: 999px; background: #ec4899; + margin-right: 6px; animation: livePulse 1.6s infinite; vertical-align: middle; +} +@keyframes livePulse { + 0% { box-shadow: 0 0 0 0 rgba(236, 72, 153, .38); } + 70% { box-shadow: 0 0 0 8px rgba(236, 72, 153, 0); } + 100% { box-shadow: 0 0 0 0 rgba(236, 72, 153, 0); } +} + +/* layout */ +.stop-layout { display: grid; grid-template-columns: 1.35fr .9fr; gap: 16px; align-items: start; margin: 8px 0 48px; } +.stop-panel { background: #fff; border: 1px solid var(--line); border-radius: 16px; padding: 18px; box-shadow: 0 8px 24px rgba(67, 56, 202, .08); } +.stop-panel__empty { display: flex; align-items: center; justify-content: center; gap: 8px; color: var(--muted); padding: 40px 12px; border: 1px dashed #d9d2ea; border-radius: 12px; } + +/* route expander */ +.route-expander-list { list-style: none; margin: 0; padding: 0; display: grid; gap: 8px; } +.route-expander { border: 1px solid var(--line); border-radius: 12px; overflow: hidden; background: #fff; } +.route-expander summary { + list-style: none; display: flex; align-items: center; gap: 10px; padding: 12px 14px; + cursor: pointer; flex-wrap: wrap; +} +.route-expander summary::-webkit-details-marker { display: none; } +.route-expander__id { + flex: none; min-width: 44px; text-align: center; padding: 5px 10px; border-radius: 8px; + color: #fff; font-weight: 700; font-variant-numeric: tabular-nums; background: linear-gradient(135deg, #7a4cc0, #b07ce0); +} +.route-expander__id.sky { background: linear-gradient(135deg, #3071b8, #6ea7e8); } +.route-expander__id.pink { background: linear-gradient(135deg, #bb3a78, #f08bb9); } +.route-expander__id.mint { background: linear-gradient(135deg, #1f8765, #51c39c); } +.route-expander__name { flex: 1; min-width: 0; color: var(--ink); font-weight: 700; font-size: .94rem; } +.route-expander__count { flex: none; color: var(--muted); font-size: .8rem; font-weight: 700; } +.route-expander__body { border-top: 1px solid var(--line); padding: 12px 14px; background: #fbfaff; } +.route-expander__link { display: inline-block; margin-bottom: 8px; color: #7a4cc0; font-size: .85rem; font-weight: 700; text-decoration: none; } +.route-expander__link:hover { text-decoration: underline; } +.route-expander__times { display: flex; flex-wrap: wrap; gap: 8px; } +.time-chip { + padding: 6px 12px; border-radius: 10px; background: #f1f4fb; color: #2b2f42; + font-weight: 700; font-size: .85rem; border: 1px solid #e6eaf3; font-variant-numeric: tabular-nums; +} + +/* stop chips (map aside) */ +.stop-chips { display: flex; flex-wrap: wrap; gap: 8px; margin-top: 14px; } + +@media (max-width: 980px) { + .stop-hero { grid-template-columns: 1fr; } + .stop-layout { grid-template-columns: 1fr; } +} + +/* ---------- Check schedule (เช็กเวลาเดินรถ) ---------- */ +.check-selector { max-width: 520px; margin: 8px auto 0; } +.check-selector .route-select-wrap { text-align: left; } +.check-selector .select-box--toolbar { max-width: none; } +.check-stats { display: grid; grid-template-columns: repeat(4, 1fr); gap: 12px; margin: 22px 0; } +.check-stat { + background: #fff; border: 1px solid var(--line); border-radius: 14px; + padding: 14px 16px; text-align: center; box-shadow: 0 6px 14px rgba(67, 56, 202, .06); +} +.check-stat:nth-child(1) { background: linear-gradient(135deg, #f5efff, #fdf2f8); } +.check-stat:nth-child(2) { background: linear-gradient(135deg, #ebf5ff, #eff6ff); } +.check-stat:nth-child(3) { background: linear-gradient(135deg, #eafaf4, #ecfeff); } +.check-stat:nth-child(4) { background: linear-gradient(135deg, #fff1f2, #fff7ed); } +.check-stat b { display: block; font-size: 1.5rem; color: var(--ink); font-weight: 800; font-variant-numeric: tabular-nums; } +.check-stat span { display: block; margin-top: 4px; font-size: .78rem; color: var(--muted); font-weight: 700; } +.check-schedule { margin: 8px 0 52px; } +@media (max-width: 640px) { + .check-stats { grid-template-columns: repeat(2, 1fr); } +} + +/* ---------- Search form (toolbar) ---------- */ +.toolbar__search .toolbar__submit { + flex: none; background: var(--grad-cta); color: #fff; border: 0; border-radius: 8px; + padding: 8px 14px; font: inherit; font-size: .85rem; font-weight: 700; cursor: pointer; +} +.toolbar__search .toolbar__clear { + flex: none; width: 26px; height: 26px; display: flex; align-items: center; justify-content: center; + border-radius: 50%; background: #f1eef8; color: var(--muted); text-decoration: none; font-size: .8rem; + font-weight: 700; +} +.toolbar__search .toolbar__clear:hover { background: #e7e1f4; } + diff --git a/frontend/src/app/routes/[routeId]/page.tsx b/frontend/src/app/routes/[routeId]/page.tsx index ee69680..4ba732d 100644 --- a/frontend/src/app/routes/[routeId]/page.tsx +++ b/frontend/src/app/routes/[routeId]/page.tsx @@ -1,10 +1,20 @@ import Link from "next/link"; import { notFound } from "next/navigation"; -import { api, isApiNotFoundError, type RouteDetail, type RouteStop, type StopListItem, type Schedule } from "@/lib/api"; +import { + api, + isApiNotFoundError, + type RouteDetail, + type RouteStop, + type StopListItem, + type Schedule, + type RouteListItem, +} from "@/lib/api"; import LazyMapView from "@/components/LazyMapView"; +import { RouteSelect } from "@/components/RouteSelect"; import { VisitTracker } from "@/lib/visit-tracker"; import { routePhoto } from "@/lib/images"; import { routePath } from "@/lib/geojson"; +import { captionFor } from "@/lib/captions"; import { Icon } from "@/components/Icons"; const TONES = ["sky", "purple", "pink", "mint", "amber"] as const; @@ -13,23 +23,37 @@ type RouteDetailPageProps = { params: Promise<{ routeId: string }>; }; -export default async function RouteDetailPage({ - params, -}: RouteDetailPageProps) { +/** เที่ยวถัดไป = รอบแรกที่ยังไม่ผ่านของสายนี้ */ +function nextTrip(schedules: Schedule[]): string | null { + const all = schedules.flatMap((s) => s.departure_times); + if (all.length === 0) return null; + const now = new Date(); + const cur = now.getHours() * 60 + now.getMinutes(); + for (const t of [...all].sort()) { + const [h, m] = t.split(":").map(Number); + if (h * 60 + m >= cur) return t; + } + return null; +} + +export default async function RouteDetailPage({ params }: RouteDetailPageProps) { const { routeId } = await params; let route: RouteDetail | null = null; let stops: RouteStop[] = []; let schedules: Schedule[] = []; let allStops: StopListItem[] = []; + let allRoutes: RouteListItem[] = []; try { - [route, { items: stops }, { items: schedules }, { items: allStops }] = await Promise.all([ - api.route(routeId), - api.routeStops(routeId), - api.schedules({ route_id: routeId }), - api.stops(), - ]); + [route, { items: stops }, { items: schedules }, { items: allStops }, { items: allRoutes }] = + await Promise.all([ + api.route(routeId), + api.routeStops(routeId), + api.schedules({ route_id: routeId }), + api.stops(), + api.routes(), + ]); } catch (error) { if (isApiNotFoundError(error)) { notFound(); @@ -38,6 +62,7 @@ export default async function RouteDetailPage({ stops = []; schedules = []; allStops = []; + allRoutes = []; } if (!route) { @@ -53,12 +78,9 @@ export default async function RouteDetailPage({ ); } - // Build coord lookup by station_id from /stops dataset const coordById = new Map(); for (const s of allStops) { - if (s.lat != null && s.lng != null) { - coordById.set(s.id, { lat: s.lat, lng: s.lng }); - } + if (s.lat != null && s.lng != null) coordById.set(s.id, { lat: s.lat, lng: s.lng }); } const mapPoints = stops @@ -77,19 +99,33 @@ export default async function RouteDetailPage({ .filter((x): x is NonNullable => x !== null); const stopPath: [number, number][] = mapPoints.map((p) => [p.lat, p.lng]); - // เส้นทางจริงจาก design (geojson-web/.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), - ); + const provinceSet = new Set(stops.map((s) => s.province_th).filter((x): x is string => !!x)); - // รูปรถ/เส้นทางจาก design (.image/routes//car|hero) const photo = routePhoto(route.route_id, "car") ?? routePhoto(route.route_id, "hero"); + const cap = captionFor(route.route_id); + const next = nextTrip(schedules); + + // ติดต่อผู้ประกอบการ (จาก design routes.json) + const contact = (route.contact ?? {}) as { + phones?: { label?: string; number: string }[]; + web_url?: string; + }; + const phones = Array.isArray(contact.phones) ? contact.phones : []; + const lineUrl = typeof contact.web_url === "string" ? contact.web_url : ""; + const qr = cap?.qr ?? ""; return (
+
+

+ หน้าแรก / รายละเอียดสายรถ /{" "} + {route.route_id} +

+
+
@@ -117,142 +153,181 @@ export default async function RouteDetailPage({ {stops.length} จุดจอด {schedules.length} รอบเวลา {provinceSet.size} จังหวัด + + {next ?? "—"} {next ? "รอบถัดไป" : "ไม่มีรอบวันนี้"} +
- - ← กลับสายทั้งหมด - + ← กลับสายทั้งหมด +
+
+ +
+ {/* เลือกสายรถ (จาก design: route-select) */} +
+ ({ route_id: r.route_id, name_th: r.name_th }))} + current={route.route_id} + />
- {/* ติดต่อ */} -
-

ติดต่อ

- {Array.isArray((route.contact as any)?.phones) && (route.contact as any).phones.length > 0 ? ( -
    - {(route.contact as any).phones.map((p: any, i: number) => ( -
  • - {p.label || "โทร"}: {p.number} -
  • - ))} -
- ) : ( -

ไม่พบเบอร์ติดต่อ

+ {/* รถประจำสาย + ติดต่อผู้ประกอบการ (การ์ดเดียว) */} + {(photo || cap || qr || phones.length > 0 || lineUrl) && ( +
+ {photo && ( + {`รถของสาย + )} +
+

รถประจำสาย

+ {cap?.vehicle_title &&

{cap.vehicle_title}

} + {cap?.vehicle_desc &&

{cap.vehicle_desc}

} + {!cap?.vehicle_title && !cap?.vehicle_desc && ( +

สาย {route.route_id} · {route.vehicle_type}

)} -
-
- - {photo && ( -
-

รถประจำสาย

- {`รถของสาย -
- )} - -
-
-

เส้นทางวิ่ง

- - ต้นทาง - จุดผ่าน - ปลายทาง - -
- {mapPoints.length >= 1 ? ( -
- -
- ) : ( -

— ยังไม่มีพิกัดสำหรับจุดจอดของสายนี้ —

+
+ + )} - -
-

จุดจอดตามลำดับ ({stops.length})

-
    - {stops.map((s, i) => { - const tone = TONES[i % TONES.length]; - const isStart = i === 0; - const isEnd = i === stops.length - 1; - const hasCoord = coordById.has(s.station_id); - const stopHref = s.code ? `/stops/${encodeURIComponent(s.code)}` : null; - return ( -
  1. - - - {s.stop_sequence} - -
    -
    - {stopHref ? ( - - {s.name_th} - - ) : ( - {s.name_th} - )} - {isStart && ต้นทาง} - {isEnd && ปลายทาง} -
    -
    - {s.station_type} - {(s.city_th || s.province_th) && ( - - {[s.city_th, s.province_th].filter(Boolean).join(" · ")} - - )} - {!hasCoord && ( - ไม่มีพิกัดบนแผนที่ - )} -
    -
    - {stopHref ? ( - → - ) : ( - → - )} -
  2. - ); - })} -
-
+ {/* แผนที่เส้นทาง + จุดจอดตามเส้นทาง */} +
+
+

เส้นทางเดินรถ

+ + ต้นทาง + จุดผ่าน + ปลายทาง + +
+ {mapPoints.length >= 1 ? ( +
+ +
+ ) : ( +

— ยังไม่มีพิกัดสำหรับจุดจอดของสายนี้ —

+ )} -
-

ตารางเวลา ({schedules.length})

- {schedules.length === 0 ? ( -

ยังไม่มีข้อมูลตารางเวลา

- ) : ( -
- {schedules.map((s, i) => { + {stops.length > 0 && ( +
+

จุดจอดตามเส้นทาง (กม. จากต้นทาง)

+
    + {stops.map((s) => ( +
  1. + {s.stop_sequence} + {s.name_th} + {s.city_th && {s.city_th}} +
  2. + ))} +
+
+ )} +
+ + {/* จุดจอดตามลำดับ (รายละเอียด) */} +
+

จุดจอดตามลำดับ ({stops.length})

+
    + {stops.map((s, i) => { const tone = TONES[i % TONES.length]; + const isStart = i === 0; + const isEnd = i === stops.length - 1; + const hasCoord = coordById.has(s.station_id); + const stopHref = s.code ? `/stops/${encodeURIComponent(s.code)}` : null; return ( -
    - -
    -
    - {s.station_name_th} - จุดต้นทาง +
  1. + + + {s.stop_sequence} + +
    +
    + {stopHref ? ( + {s.name_th} + ) : ( + {s.name_th} + )} + {isStart && ต้นทาง} + {isEnd && ปลายทาง}
    -
    - {s.direction_note || "ทุกทิศทาง"} - {s.schedule_note && {s.schedule_note}} +
    + {s.station_type} + {(s.city_th || s.province_th) && ( + + {[s.city_th, s.province_th].filter(Boolean).join(" · ")} + + )} + {!hasCoord && ไม่มีพิกัดบนแผนที่}
    - {s.departure_times.length === 0 ? ( - — ยังไม่มีรอบ — + {stopHref ? ( + → ) : ( -
    - {s.departure_times.map((t, j) => ( - {t} - ))} -
    + → )} -
  2. + ); })} - - )} -
+ +
+ + {/* ตารางเวลา */} +
+

ตารางเวลา ({schedules.length})

+ {schedules.length === 0 ? ( +

ยังไม่มีข้อมูลตารางเวลา

+ ) : ( +
+ {schedules.map((s, i) => { + const tone = TONES[i % TONES.length]; + return ( +
+ +
+
+ {s.station_name_th} + จุดต้นทาง +
+
+ {s.direction_note || "ทุกทิศทาง"} + {s.schedule_note && {s.schedule_note}} +
+
+ {s.departure_times.length === 0 ? ( + — ยังไม่มีรอบ — + ) : ( +
+ {s.departure_times.map((t, j) => ( + {t} + ))} +
+ )} +
+ ); + })} +
+ )} +
+
); } diff --git a/frontend/src/app/stops/details/page.tsx b/frontend/src/app/stops/details/page.tsx index 111c1e8..a526405 100644 --- a/frontend/src/app/stops/details/page.tsx +++ b/frontend/src/app/stops/details/page.tsx @@ -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 = { + main_terminal: "สถานีขนส่ง", + local_stop: "ป้ายหลัก", + market: "ตลาด/ชุมชน", + private_stop: "จุดรับส่ง", + other: "อื่น ๆ", +}; + +const GROUP_TONE: Record = { + 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 ); } - 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/.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(); + 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 (
-
- {stop.station_type} -

{stop.name_th}

-

{place}{hasMap ? ` · ${stop.lat?.toFixed(4)}, ${stop.lng?.toFixed(4)}` : ""}

-
-
- {designPhoto ? ( -
- {stop.name_th} + +
+

+ หน้าแรก / ป้ายหยุดรถ /{" "} + {stop.name_th} +

+
+ +
+
+
+

+ {stop.name_th} +

+

+ {place} + {hasMap ? ` · ${stop.lat?.toFixed(4)}, ${stop.lng?.toFixed(4)}` : ""} +

+
+ {typeLabel} + {stop.province_th && {stop.province_th}} + {hasMap && มีพิกัดบนแผนที่} +
+
+
+

สายที่ผ่าน

+

{routes.length}

+
+
+

ประเภทป้าย

+

{typeLabel}

+
+
+

จังหวัด

+

{stop.province_th ?? "—"}

+
+
+

รอบเวลา

+

{allTimes.length}

+
+
- ) : stop.images.length > 0 ? ( -
- {(stop.images[0].meta - {stop.images.length > 1 && ( -
- {stop.images.slice(1, 5).map((img) => ( - {stop.name_th} - ))} +
+ {designPhoto ? ( + {stop.name_th} + ) : ( +
+ ยังไม่มีรูปป้ายนี้
)} +
- ) : ( -
-
ยังไม่มีรูปป้ายนี้
+
+ +
+
+

สายรถที่ผ่านจุดนี้

+ {routes.length === 0 ? ( +

ยังไม่มีข้อมูลสายที่ผ่าน

+ ) : ( +
    + {routes.map((r) => { + const times = timesByRoute.get(r.route_id) ?? []; + const tone = GROUP_TONE[r.route_group_code] ?? "purple"; + return ( +
  • +
    + + {r.route_id} + {r.name_th} + {times.length} รอบ + +
    + + ดูรายละเอียดสาย {r.route_id} → + + {times.length === 0 ? ( +

    ยังไม่มีรอบเวลา

    + ) : ( +
    + {times.map((t, j) => ( + {t} + ))} +
    + )} +
    +
    +
  • + ); + })} +
+ )}
- )} - {hasMap ? ( -
- -
- ) : ( -
-
ยังไม่มีพิกัดของป้ายนี้
-
- )} -
-

ตารางเวลาที่จุดนี้

- {schedules.length === 0 ? ( -

ยังไม่มีข้อมูล

- ) : ( -
- {schedules.map((s, i) => { - const tone = TONES[i % TONES.length]; - return ( -
-
-
- - เส้นทาง - {s.route_id} - -
- - - {s.direction_note || "ไม่ระบุทิศทาง"} - - {s.schedule_note && ( - {s.schedule_note} - )} -
-
-
- {s.departure_times.length === 0 ? ( - — ยังไม่มีรอบ — - ) : ( - s.departure_times.map((t, j) => ( - {t} - )) - )} -
-
- ); - })} + +
- )} +
); } diff --git a/frontend/src/app/stops/page.tsx b/frontend/src/app/stops/page.tsx index d11d741..4751bed 100644 --- a/frontend/src/app/stops/page.tsx +++ b/frontend/src/app/stops/page.tsx @@ -6,40 +6,55 @@ import { Icon, type IconName } from "@/components/Icons"; const TONES = ["sky", "purple", "pink", "mint", "amber"] as const; const TYPE_TONE: Record = { - 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 = { - 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 = { - 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>((acc, s) => { acc[s.station_type] = (acc[s.station_type] ?? 0) + 1; return acc; }, {}); + return (
+
+

+ หน้าแรก / ป้ายหยุดรถ +

+
+
@@ -60,80 +75,73 @@ export default async function StopsPage() {
- {points.length > 0 && ( -
- -
- )} +
+ {points.length > 0 && !q && ( +
+ +
+ )} -
-
- - +
+
+ + + {q && ( + ✕ + )} + + +
+ {Object.entries(typeCounts).map(([t, n]) => ( + + {TYPE_LABEL[t] ?? t} · {n} + + ))} +
-
- {Object.entries(typeCounts).map(([t, n]) => ( - - {TYPE_LABEL[t] ?? t} · {n} - - ))} -
-
-
- {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 ? ( - -
- -
-
-

{s.name_th}

-

{place || "—"}

-
- - {TYPE_LABEL[s.station_type] ?? s.station_type} - - {s.lat != null && s.lng != null && ( - บนแผนที่ - )} + {items.length === 0 ? ( +

ไม่พบป้ายที่ตรงกับ “{q}”

+ ) : ( +
+ {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 = ( + <> +
+
-
- → - - ) : ( -
-
- -
-
-

{s.name_th}

-

{place || "—"}

-
- - {TYPE_LABEL[s.station_type] ?? s.station_type} - - {s.lat != null && s.lng != null && ( - บนแผนที่ - )} +
+

{s.name_th}

+

{place || "—"}

+
+ + {TYPE_LABEL[s.station_type] ?? s.station_type} + + {s.lat != null && s.lng != null && ( + บนแผนที่ + )} +
+ → + + ); + return stopHref ? ( + + {body} + + ) : ( +
+ {body}
- → -
- ) - ); - })} + ); + })} +
+ )}
); } - diff --git a/frontend/src/components/Header.tsx b/frontend/src/components/Header.tsx index e97e888..c95f43a 100644 --- a/frontend/src/components/Header.tsx +++ b/frontend/src/components/Header.tsx @@ -99,7 +99,7 @@ export function Header() { / EN - {t("cta")} + {t("cta")} diff --git a/frontend/src/components/LiveClock.tsx b/frontend/src/components/LiveClock.tsx new file mode 100644 index 0000000..16dcf7f --- /dev/null +++ b/frontend/src/components/LiveClock.tsx @@ -0,0 +1,41 @@ +"use client"; + +import { useEffect, useState } from "react"; + +/** นาฬิกาสด ณ ป้าย + คำนวณเที่ยวถัดไปอัตโนมัติ (จาก design: live-clock-card) */ +export function LiveClock({ times }: { times: string[] }) { + const [now, setNow] = useState("--:--"); + const [next, setNext] = useState(null); + + useEffect(() => { + const tick = () => { + const d = new Date(); + setNow(`${String(d.getHours()).padStart(2, "0")}:${String(d.getMinutes()).padStart(2, "0")}`); + const cur = d.getHours() * 60 + d.getMinutes(); + const n = + [...times] + .sort() + .find((t) => { + const [h, m] = t.split(":").map(Number); + return h * 60 + m >= cur; + }) ?? null; + setNext(n); + }; + tick(); + const id = setInterval(tick, 30_000); + return () => clearInterval(id); + }, [times]); + + return ( +
+
+

เวลาปัจจุบัน ณ ป้ายนี้

+

{now}

+
+

+ + {next ? `เที่ยวถัดไป ${next}` : "กำลังคำนวณเที่ยวถัดไปอัตโนมัติ"} +

+
+ ); +} diff --git a/frontend/src/components/RouteSelect.tsx b/frontend/src/components/RouteSelect.tsx new file mode 100644 index 0000000..823b09f --- /dev/null +++ b/frontend/src/components/RouteSelect.tsx @@ -0,0 +1,41 @@ +"use client"; + +import { useRouter } from "next/navigation"; +import { Icon } from "@/components/Icons"; + +type Props = { + routes: { route_id: string; name_th: string }[]; + current: string; + /** คืน URL ปลายทางเมื่อเลือกสาย (default: /routes/:id) */ + to?: (routeId: string) => string; +}; + +/** เลือกสายรถ — เปลี่ยนสายโดยไม่ต้องกลับหน้ารายการ (จาก design: route-select) */ +export function RouteSelect({ routes, current, to }: Props) { + const router = useRouter(); + return ( +
+ +
+ + + +
+
+ ); +} diff --git a/frontend/src/data/captions-index.json b/frontend/src/data/captions-index.json new file mode 100644 index 0000000..dfd900f --- /dev/null +++ b/frontend/src/data/captions-index.json @@ -0,0 +1,86 @@ +{ + "101": { + "vehicle_title": "รถสองแถวประจำเส้นทาง", + "vehicle_desc": "ประมาณ 30 ที่นั่ง · ให้บริการตลอดเส้นทางอ่างทอง–ป่าโมก–อยุธยา", + "line_note": "ติดตามข่าวสาย 101 · รถออกก่อนเวลาบ่อยครั้ง · รถขาดช่วง", + "qr": "/images/qrcode/101.png" + }, + "1011": { + "vehicle_title": "รถเมล์ประจำเส้นทาง", + "vehicle_desc": "รถเมล์ ประมาณ 30 ที่นั่ง รถมีเที่ยว เช้า เที่บง เย็น", + "line_note": "", + "qr": "" + }, + "15": { + "vehicle_title": "รถมินิบัส 20 ที่นั่ง", + "vehicle_desc": "ปัจจุบันส่วนใหญ่วิ่งแค่ป่าโมก หมอชิตใหม่ เหลือแค่รถ เบอร์ 20 ที่กลับถึงอ่างทอง บขส.อ่างทองมีรถออกแค่เช้ามืดถึงโมงเช้า", + "line_note": "", + "qr": "/images/qrcode/15.JPG" + }, + "2194": { + "vehicle_title": "รถสองแถวประจำเส้นทาง", + "vehicle_desc": "รถสองแถวเช้ามืดและเย็น ผ่านอ่างทองแค่สามแยกข้ามสะพานโผงเผงและวัดถนน", + "line_note": "", + "qr": "" + }, + "2231": { + "vehicle_title": "รถสองแถวประจำเส้นทาง", + "vehicle_desc": "มีเที่ยวเดียว เช้า-เย็น", + "line_note": "", + "qr": "" + }, + "324": { + "vehicle_title": "รถสองแถวประจำเส้นทาง", + "vehicle_desc": "รถมีเที่ยว เช้า อย่างเดียว วิ่งสุดสายแค่วัดไชโย", + "line_note": "", + "qr": "" + }, + "464": { + "vehicle_title": "", + "vehicle_desc": "", + "line_note": "", + "qr": "/images/qrcode/464.jpeg" + }, + "641": { + "vehicle_title": "", + "vehicle_desc": "", + "line_note": "", + "qr": "" + }, + "8": { + "vehicle_title": "", + "vehicle_desc": "", + "line_note": "", + "qr": "" + }, + "902": { + "vehicle_title": "", + "vehicle_desc": "", + "line_note": "", + "qr": "/images/qrcode/902.png" + }, + "951": { + "vehicle_title": "", + "vehicle_desc": "", + "line_note": "", + "qr": "" + }, + "952": { + "vehicle_title": "", + "vehicle_desc": "", + "line_note": "", + "qr": "" + }, + "954": { + "vehicle_title": "", + "vehicle_desc": "", + "line_note": "", + "qr": "" + }, + "999": { + "vehicle_title": "", + "vehicle_desc": "", + "line_note": "", + "qr": "" + } +} \ No newline at end of file diff --git a/frontend/src/data/captions/caption101.json b/frontend/src/data/captions/caption101.json new file mode 100644 index 0000000..c535e2f --- /dev/null +++ b/frontend/src/data/captions/caption101.json @@ -0,0 +1,8 @@ +{ + "route_id": "101", + "vehicle_image": "car.jpeg", + "qr_image": "101.png", + "vehicle_title": "รถสองแถวประจำเส้นทาง", + "vehicle_desc": "ประมาณ 30 ที่นั่ง · ให้บริการตลอดเส้นทางอ่างทอง–ป่าโมก–อยุธยา", + "line_note": "ติดตามข่าวสาย 101 · รถออกก่อนเวลาบ่อยครั้ง · รถขาดช่วง" +} diff --git a/frontend/src/data/captions/caption1011.json b/frontend/src/data/captions/caption1011.json new file mode 100644 index 0000000..0f2b6f6 --- /dev/null +++ b/frontend/src/data/captions/caption1011.json @@ -0,0 +1,8 @@ +{ + "route_id": "1011", + "vehicle_image": "car.jpeg", + "qr_image": "", + "vehicle_title": "รถเมล์ประจำเส้นทาง", + "vehicle_desc": "รถเมล์ ประมาณ 30 ที่นั่ง รถมีเที่ยว เช้า เที่บง เย็น", + "line_note": "" +} diff --git a/frontend/src/data/captions/caption15.json b/frontend/src/data/captions/caption15.json new file mode 100644 index 0000000..30a21d6 --- /dev/null +++ b/frontend/src/data/captions/caption15.json @@ -0,0 +1,8 @@ +{ + "route_id": "15", + "vehicle_image": "car.jpg", + "qr_image": "15.JPG", + "vehicle_title": "รถมินิบัส 20 ที่นั่ง", + "vehicle_desc": "ปัจจุบันส่วนใหญ่วิ่งแค่ป่าโมก หมอชิตใหม่ เหลือแค่รถ เบอร์ 20 ที่กลับถึงอ่างทอง บขส.อ่างทองมีรถออกแค่เช้ามืดถึงโมงเช้า", + "line_note": "" +} diff --git a/frontend/src/data/captions/caption2194.json b/frontend/src/data/captions/caption2194.json new file mode 100644 index 0000000..701d114 --- /dev/null +++ b/frontend/src/data/captions/caption2194.json @@ -0,0 +1,8 @@ +{ + "route_id": "2194", + "vehicle_image": "car.jpg", + "qr_image": "", + "vehicle_title": "รถสองแถวประจำเส้นทาง", + "vehicle_desc": "รถสองแถวเช้ามืดและเย็น ผ่านอ่างทองแค่สามแยกข้ามสะพานโผงเผงและวัดถนน", + "line_note": "" +} diff --git a/frontend/src/data/captions/caption2231.json b/frontend/src/data/captions/caption2231.json new file mode 100644 index 0000000..969188f --- /dev/null +++ b/frontend/src/data/captions/caption2231.json @@ -0,0 +1,8 @@ +{ + "route_id": "2231", + "vehicle_image": "car.jpg", + "qr_image": "", + "vehicle_title": "รถสองแถวประจำเส้นทาง", + "vehicle_desc": "มีเที่ยวเดียว เช้า-เย็น", + "line_note": "" +} diff --git a/frontend/src/data/captions/caption324.json b/frontend/src/data/captions/caption324.json new file mode 100644 index 0000000..1002afd --- /dev/null +++ b/frontend/src/data/captions/caption324.json @@ -0,0 +1,8 @@ +{ + "route_id": "324", + "vehicle_image": "car.jpg", + "qr_image": "", + "vehicle_title": "รถสองแถวประจำเส้นทาง", + "vehicle_desc": "รถมีเที่ยว เช้า อย่างเดียว วิ่งสุดสายแค่วัดไชโย", + "line_note": "" +} diff --git a/frontend/src/data/captions/caption464.json b/frontend/src/data/captions/caption464.json new file mode 100644 index 0000000..0766219 --- /dev/null +++ b/frontend/src/data/captions/caption464.json @@ -0,0 +1,8 @@ +{ + "route_id": "464", + "vehicle_image": "car.jpeg", + "qr_image": "464.jpeg", + "vehicle_title": "", + "vehicle_desc": "", + "line_note": "" +} diff --git a/frontend/src/data/captions/caption641.json b/frontend/src/data/captions/caption641.json new file mode 100644 index 0000000..f076c27 --- /dev/null +++ b/frontend/src/data/captions/caption641.json @@ -0,0 +1,8 @@ +{ + "route_id": "641", + "vehicle_image": "car.jpeg", + "qr_image": "", + "vehicle_title": "", + "vehicle_desc": "", + "line_note": "" +} diff --git a/frontend/src/data/captions/caption8.json b/frontend/src/data/captions/caption8.json new file mode 100644 index 0000000..48a71ab --- /dev/null +++ b/frontend/src/data/captions/caption8.json @@ -0,0 +1,8 @@ +{ + "route_id": "8", + "vehicle_image": "", + "qr_image": "", + "vehicle_title": "", + "vehicle_desc": "", + "line_note": "" +} diff --git a/frontend/src/data/captions/caption902.json b/frontend/src/data/captions/caption902.json new file mode 100644 index 0000000..b638ada --- /dev/null +++ b/frontend/src/data/captions/caption902.json @@ -0,0 +1,8 @@ +{ + "route_id": "902", + "vehicle_image": "car.jpg", + "qr_image": "902.png", + "vehicle_title": "", + "vehicle_desc": "", + "line_note": "" +} diff --git a/frontend/src/data/captions/caption951.json b/frontend/src/data/captions/caption951.json new file mode 100644 index 0000000..c4ed125 --- /dev/null +++ b/frontend/src/data/captions/caption951.json @@ -0,0 +1,8 @@ +{ + "route_id": "951", + "vehicle_image": "car.jpg", + "qr_image": "", + "vehicle_title": "", + "vehicle_desc": "", + "line_note": "" +} diff --git a/frontend/src/data/captions/caption952.json b/frontend/src/data/captions/caption952.json new file mode 100644 index 0000000..5b2f792 --- /dev/null +++ b/frontend/src/data/captions/caption952.json @@ -0,0 +1,8 @@ +{ + "route_id": "952", + "vehicle_image": "car.jpg", + "qr_image": "", + "vehicle_title": "", + "vehicle_desc": "", + "line_note": "" +} diff --git a/frontend/src/data/captions/caption954.json b/frontend/src/data/captions/caption954.json new file mode 100644 index 0000000..9007c72 --- /dev/null +++ b/frontend/src/data/captions/caption954.json @@ -0,0 +1,8 @@ +{ + "route_id": "954", + "vehicle_image": "", + "qr_image": "", + "vehicle_title": "", + "vehicle_desc": "", + "line_note": "" +} diff --git a/frontend/src/data/captions/caption999.json b/frontend/src/data/captions/caption999.json new file mode 100644 index 0000000..790cd3d --- /dev/null +++ b/frontend/src/data/captions/caption999.json @@ -0,0 +1,8 @@ +{ + "route_id": "999", + "vehicle_image": "", + "qr_image": "", + "vehicle_title": "", + "vehicle_desc": "", + "line_note": "" +} diff --git a/frontend/src/lib/captions.ts b/frontend/src/lib/captions.ts new file mode 100644 index 0000000..833ea9d --- /dev/null +++ b/frontend/src/lib/captions.ts @@ -0,0 +1,15 @@ +import captions from "@/data/captions-index.json"; + +export type RouteCaption = { + vehicle_title: string; + vehicle_desc: string; + line_note: string; + qr: string; // e.g. "/images/qrcode/101.png" ("" ถ้าไม่มี) +}; + +/** caption รถ/QR จาก design (resource/data/captions + .image/qrcode) */ +export function captionFor(routeId: string): RouteCaption | undefined { + const c = (captions as Record)[String(routeId)]; + if (!c) return undefined; + return c.vehicle_title || c.vehicle_desc || c.line_note || c.qr ? c : undefined; +}