first commit

This commit is contained in:
phattaranun.a committed 2026-05-24 22:55:17 +07:00
commit 2a1854ab08
120 files changed
+11300

No files matched your search

+14
View File
@@ -0,0 +1,14 @@
import { notFound, redirect } from "next/navigation";
interface StopDetailPageProps {
params: Promise<{ stopId: string }>;
}
export default async function StopDetailPage({ params }: StopDetailPageProps) {
const { stopId } = await params;
if (!stopId || stopId === "undefined") {
notFound();
}
redirect(`/stops/details?code=${encodeURIComponent(stopId)}`);
return null;
}
+132
View File
@@ -0,0 +1,132 @@
import Link from "next/link";
import { notFound } from "next/navigation";
import { api, isApiNotFoundError, resolveFileUrl, type Schedule, type StopDetail } from "@/lib/api";
import LazyMapView from "@/components/LazyMapView";
import { VisitTracker } from "@/lib/visit-tracker";
const TONES = ["sky", "purple", "pink", "mint", "amber"] as const;
type StopDetailsPageProps = {
searchParams: Promise<{ code?: string }>;
};
export default async function StopDetailsPage({ searchParams }: StopDetailsPageProps) {
const { code } = await searchParams;
if (!code) notFound();
let stop: StopDetail | null = null;
let schedules: Schedule[] = [];
try {
stop = await api.stop(code);
({ items: schedules } = await api.schedules({ stop_code: stop.code }));
} catch (error) {
if (isApiNotFoundError(error)) {
notFound();
}
stop = null;
schedules = [];
}
if (!stop) {
return (
<main className="page">
<VisitTracker path={`/stops/details?code=${code}`} />
<section className="hero">
<h1>ไม่สามารถโหลดข้อมูลป้ายนี้ได้</h1>
<p className="muted">ระบบยังเปิดอยู่ แต่ backend ตอบกลับไม่ได้ในตอนนี้</p>
<Link href="/stops">กลับไปหน้าป้ายหยุดรถ</Link>
</section>
</main>
);
}
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 }]
: [];
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">📍 {place}{hasMap ? ` · ${stop.lat?.toFixed(4)}, ${stop.lng?.toFixed(4)}` : ""}</p>
</section>
<div className="stop-detail__split">
{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>
)}
</div>
) : (
<div className="stop-detail__gallery stop-detail__gallery--empty">
<div className="stop-detail__placeholder">📷 ยังไม่มีรูปป้ายนี้</div>
</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">🗺️ ยังไม่มีพิกัดของป้ายนี้</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">
<span aria-hidden>🧭</span>
{s.direction_note || "ไม่ระบุทิศทาง"}
</span>
{s.schedule_note && (
<span className="schedule-card__note">📝 {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">🕒 {t}</span>
))
)}
</div>
</article>
);
})}
</div>
)}
</main>
);
}
+138
View File
@@ -0,0 +1,138 @@
import Link from "next/link";
import { api } from "@/lib/api";
import LazyMapView from "@/components/LazyMapView";
import { VisitTracker } from "@/lib/visit-tracker";
const TONES = ["sky", "purple", "pink", "mint", "amber"] as const;
const TYPE_TONE: Record<string, (typeof TONES)[number]> = {
terminal: "purple",
station: "sky",
pickup: "amber",
market: "pink",
landmark: "mint",
};
const TYPE_ICON: Record<string, string> = {
terminal: "🚍",
station: "🚏",
pickup: "🛣️",
market: "🏪",
landmark: "📍",
};
const TYPE_LABEL: Record<string, string> = {
terminal: "สถานีขนส่ง",
station: "ป้ายหลัก",
pickup: "จุดรับส่ง",
market: "ตลาด/ชุมชน",
landmark: "จุดสังเกต",
};
export default async function StopsPage() {
const { items } = await api.stops().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" />
<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">🚏 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>
{points.length > 0 && (
<div className="map-wrap map-wrap--soft">
<LazyMapView points={points} />
</div>
)}
<div className="toolbar">
<div className="toolbar__search">
<span aria-hidden>🔍</span>
<input placeholder="ค้นหาชื่อป้าย หรือจังหวัด…" disabled />
</div>
<div className="toolbar__chips">
{Object.entries(typeCounts).map(([t, n]) => (
<span key={t} className={`chip-soft chip-soft--${TYPE_TONE[t] ?? "sky"}`}>
{TYPE_ICON[t] ?? "📍"} {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] ?? "📍";
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}`}>
<span>{icon}</span>
</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">📍 บนแผนที่</span>
)}
</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}`}>
<span>{icon}</span>
</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">📍 บนแผนที่</span>
)}
</div>
</div>
<span className="tile__arrow" aria-hidden>→</span>
</div>
)
);
})}
</div>
</main>
);
}