พอร์ต UI จาก web-at-transit-mock เข้า Next.js + data sync เข้า Postgres/SeaweedFS
- 8 หน้า (home/stops/routes/stop/check/blog/about/credits) แปลง partials → React component ตรง mock
- ตรรกะพอร์ตเป็น src/lib/ui/*.ts (mount()) + runtime/PageRuntime
- CSS: base + pages/*.css import ต่อ route (คงลำดับ cascade ของ mock)
- asset/content: public/{image,resource/data,content,locales,vendor}
- แก้ path รูปไทล์พาร์ทเนอร์ (.image → /image) + fallback absolute
- ลบ UI เดิมที่ไม่ตรง mock (expanded/stops details/old components/globals.css)
- script/sync_data_to_postgres.mjs + sync_images_to_storage.mjs (dry-run/--apply, backup)
- docs/UI-PORT.md + DESIGN.md + README
This commit is contained in:
1 parent
24187fc3b7
commit
138a3d15d8
300 files changed
+20213
-1978
No files matched your search
+16
-119
@@ -1,127 +1,24 @@
|
||||
import Link from "next/link";
|
||||
import { api, type RouteListItem } from "@/lib/api";
|
||||
import { VisitTracker } from "@/lib/visit-tracker";
|
||||
import HomeView from "@/components/views/HomeView";
|
||||
import PageRuntime from "@/components/PageRuntime";
|
||||
|
||||
// Map route_group_code to visual tone
|
||||
const ZONE_TONES: Record<string, "sky" | "purple" | "pink" | "mint"> = {
|
||||
bangkok: "sky",
|
||||
interprovincial: "purple",
|
||||
in_province: "pink",
|
||||
municipal: "mint",
|
||||
};
|
||||
export const metadata = { title: "หน้าแรก" };
|
||||
|
||||
const ZONE_DESCS: Record<string, string> = {
|
||||
bangkok: "เส้นทางเชื่อมต่อกรุงเทพมหานคร",
|
||||
interprovincial: "เส้นทางเชื่อมต่อจังหวัดใกล้เคียง",
|
||||
in_province: "เส้นทางภายในจังหวัดอ่างทอง",
|
||||
municipal: "เส้นทางภายในเขตเทศบาล",
|
||||
};
|
||||
|
||||
// Display order: bangkok → interprovincial → in_province → municipal
|
||||
const ZONE_ORDER = ["bangkok", "interprovincial", "in_province", "municipal"];
|
||||
|
||||
// Cycle chip colors within a zone for visual rhythm
|
||||
const CHIP_CYCLE = ["purple", "sky", "pink", "mint"] as const;
|
||||
|
||||
export default async function HomePage() {
|
||||
const [groupsRes, routesRes] = await Promise.allSettled([
|
||||
api.routeGroups(),
|
||||
api.routes(),
|
||||
]);
|
||||
|
||||
const groups = groupsRes.status === "fulfilled" ? groupsRes.value.items : [];
|
||||
const routes = routesRes.status === "fulfilled" ? routesRes.value.items : [];
|
||||
|
||||
// Group routes by code
|
||||
const byCode = new Map<string, RouteListItem[]>();
|
||||
for (const r of routes) {
|
||||
const list = byCode.get(r.route_group_code) ?? [];
|
||||
list.push(r);
|
||||
byCode.set(r.route_group_code, list);
|
||||
export default async function Page({
|
||||
searchParams,
|
||||
}: {
|
||||
searchParams: Promise<Record<string, string | string[] | undefined>>;
|
||||
}) {
|
||||
const sp = await searchParams;
|
||||
const query: Record<string, string> = {};
|
||||
// ลิงก์สั้นเดิม: #/?s=<รหัสสถานี> และ #/?p=<province_id>
|
||||
for (const key of ["s", "p"]) {
|
||||
const value = sp[key];
|
||||
if (typeof value === "string") query[key] = value;
|
||||
}
|
||||
|
||||
const orderedGroups = [...groups].sort((a, b) => {
|
||||
const ai = ZONE_ORDER.indexOf(a.code);
|
||||
const bi = ZONE_ORDER.indexOf(b.code);
|
||||
return (ai === -1 ? 99 : ai) - (bi === -1 ? 99 : bi);
|
||||
});
|
||||
|
||||
return (
|
||||
<>
|
||||
<VisitTracker path="/" />
|
||||
|
||||
<section className="hero">
|
||||
<div className="hero__blob one" aria-hidden />
|
||||
<div className="hero__blob two" aria-hidden />
|
||||
<div className="hero__blob three" aria-hidden />
|
||||
<div className="container hero__inner">
|
||||
<span className="hero__badge">✨ ยินดีต้อนรับ</span>
|
||||
<h1>
|
||||
สถานีขนส่งผู้โดยสารภายใน
|
||||
<br />
|
||||
<span className="hero__grad">จังหวัดอ่างทอง</span>
|
||||
</h1>
|
||||
<p className="hero__lead">
|
||||
ดูสายรถ, ค้นหาป้าย และเปิดตัวอย่างเส้นทางได้ทันทีจากหน้าแรก
|
||||
</p>
|
||||
<div className="hero__actions">
|
||||
<Link className="pill-link pill-link--primary" href="/routes">
|
||||
ดูรายละเอียดสายรถ
|
||||
</Link>
|
||||
<Link className="pill-link pill-link--secondary" href="/stops">
|
||||
ค้นหาป้ายหยุดรถ
|
||||
</Link>
|
||||
{routes[0] && (
|
||||
<Link
|
||||
className="pill-link pill-link--accent"
|
||||
href={`/routes/${encodeURIComponent(routes[0].route_id)}`}
|
||||
>
|
||||
ดูตัวอย่างสายรถ
|
||||
</Link>
|
||||
)}
|
||||
</div>
|
||||
</div>
|
||||
</section>
|
||||
|
||||
<main className="main">
|
||||
<div className="container">
|
||||
{orderedGroups.map((g) => {
|
||||
const items = byCode.get(g.code) ?? [];
|
||||
if (items.length === 0) return null;
|
||||
const tone = ZONE_TONES[g.code] ?? "purple";
|
||||
return (
|
||||
<section key={g.id} className="zone">
|
||||
<div className="zone__head">
|
||||
<span className={`zone__tag ${tone}`}>{g.label_th}</span>
|
||||
<p className="zone__desc">
|
||||
{ZONE_DESCS[g.code] ?? ""} · {items.length} เส้นทาง
|
||||
</p>
|
||||
</div>
|
||||
<div className="grid">
|
||||
{items.map((r, i) => (
|
||||
<Link
|
||||
key={r.route_id}
|
||||
href={`/routes/${encodeURIComponent(r.route_id)}`}
|
||||
className="card"
|
||||
>
|
||||
<div className={`card__head ${tone}`}>
|
||||
<p className="card__num">{r.route_id}</p>
|
||||
</div>
|
||||
<div className="card__body">
|
||||
<p className="card__name">{r.name_th}</p>
|
||||
<span className={`chip ${CHIP_CYCLE[i % CHIP_CYCLE.length]}`}>
|
||||
✅ ดูตาราง
|
||||
</span>
|
||||
</div>
|
||||
</Link>
|
||||
))}
|
||||
</div>
|
||||
</section>
|
||||
);
|
||||
})}
|
||||
</div>
|
||||
</main>
|
||||
|
||||
<HomeView />
|
||||
<PageRuntime page="home" query={query} />
|
||||
</>
|
||||
);
|
||||
}
|
||||
Reference in new issue
Block a user