From 44823a5b90c28c0b56ab5abf31ea601022bc633e Mon Sep 17 00:00:00 2001 From: Bkk1234 Date: Tue, 27 Oct 2026 01:14:55 +0700 Subject: [PATCH] =?UTF-8?q?feat(app):=20single-page=20UX=20=E2=80=94=20det?= =?UTF-8?q?ail=20sheet,=20mobile/tablet=20responsive?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit - merge two routes into one page: detail opens as overlay on top of the list (list stays mounted, scroll preserved, no page refresh) - URL stays shareable via ?cinema= (pushState), browser back closes it - /cinema/:slug kept as client-side redirect for old links - mobile 6in: full-screen sheet, 44px touch targets, sticky bottom CTA, horizontal list cards, safe-area insets - tablet: 2-col grid, centered sheet (707x922), 4-col facilities - desktop: 3-col grid, sheet capped at 960px - extract Cinemalist-agnostic data layer (lib/cinemas.ts) + TH/EN i18n context - allow pinch-zoom (drop maximum-scale/user-scalable=no), html lang=th --- app/app/components/cinema/AboutDialog.tsx | 71 ++++ app/app/components/cinema/CinemaCard.tsx | 94 +++++ .../components/cinema/CinemaDetailSheet.tsx | 363 ++++++++++++++++ app/app/components/cinema/SiteHeader.tsx | 138 +++++++ app/app/components/layout/Layout.tsx | 15 +- app/app/lib/cinemas.ts | 124 ++++++ app/app/lib/i18n.tsx | 214 ++++++++++ app/app/root.tsx | 6 +- app/app/routes/_index.tsx | 391 ++++-------------- app/app/routes/cinema.$slug.tsx | 21 + 10 files changed, 1129 insertions(+), 308 deletions(-) create mode 100644 app/app/components/cinema/AboutDialog.tsx create mode 100644 app/app/components/cinema/CinemaCard.tsx create mode 100644 app/app/components/cinema/CinemaDetailSheet.tsx create mode 100644 app/app/components/cinema/SiteHeader.tsx create mode 100644 app/app/lib/cinemas.ts create mode 100644 app/app/lib/i18n.tsx create mode 100644 app/app/routes/cinema.$slug.tsx diff --git a/app/app/components/cinema/AboutDialog.tsx b/app/app/components/cinema/AboutDialog.tsx new file mode 100644 index 0000000..e125ba8 --- /dev/null +++ b/app/app/components/cinema/AboutDialog.tsx @@ -0,0 +1,71 @@ +import { useEffect, useRef } from "react"; + +import { useLang } from "@/lib/i18n"; + +interface AboutDialogProps { + open: boolean; + onClose: () => void; +} + +/** + * ป๊อปอัป "เกี่ยวกับเรา" — ใช้ native (โฟกัส trap + Esc ให้เอง) + * ★ มือถือ: กว้าง 92vw, ปุ่มเต็มความกว้าง, เผื่อ safe-area ล่าง (มือถือมีแถบ gesture) + * ★ แท็บเล็ต: กว้างสูงสุด 420px + */ +export function AboutDialog({ open, onClose }: AboutDialogProps) { + const dialogRef = useRef(null); + const { t } = useLang(); + + useEffect(() => { + const el = dialogRef.current; + if (!el) return; + + if (open && !el.open) { + el.showModal(); + } else if (!open && el.open) { + el.close(); + } + }, [open]); + + useEffect(() => { + const el = dialogRef.current; + if (!el) return; + + // ปิดด้วย Esc → บอก parent ให้ sync state + const handleClose = () => onClose(); + el.addEventListener("close", handleClose); + return () => el.removeEventListener("close", handleClose); + }, [onClose]); + + return ( + { + // คลิกฉากหลัง (นอกกล่องเนื้อหา) = ปิด + if (event.target === dialogRef.current) onClose(); + }} + > +
+

+ {t("about.title")} +

+

{t("about.body")}

+ +
+ {t("about.dev")}:{" "} + AlterFlixHub Team · v1.0.0 +
+ + +
+
+ ); +} diff --git a/app/app/components/cinema/CinemaCard.tsx b/app/app/components/cinema/CinemaCard.tsx new file mode 100644 index 0000000..8756f01 --- /dev/null +++ b/app/app/components/cinema/CinemaCard.tsx @@ -0,0 +1,94 @@ +import { IconStar } from "@tabler/icons-react"; +import type { MouseEvent } from "react"; + +import type { Cinema } from "@/lib/cinemas"; +import { useLang } from "@/lib/i18n"; + +interface CinemaCardProps { + cinema: Cinema; + /** + * เปิดรายละเอียดบนหน้าเดิม (ไม่เปลี่ยน route) + * ★ ถ้าไม่ส่งมา จะเป็นการนำทางปกติไป /?cinema= + */ + onSelect?: (slug: string) => void; +} + +/** + * การ์ดโรงภาพยนตร์ + * ★ มือถือ (<640px): การ์ดแนวนอน ปกซ้าย 112px → สแกน list ได้เร็ว กินพื้นที่น้อย + * ★ แท็บเล็ต/เดสก์ท็อป: การ์ดแนวตั้ง ปก 16:9 + * ★ ใช้ จริง (กดกลาง/เปิดแท็บใหม่ได้, crawler อ่านได้) + * แต่คลิกปกติ = preventDefault แล้วเรียก onSelect → ไม่รีเฟรชหน้า + */ +export function CinemaCard({ cinema, onSelect }: CinemaCardProps) { + const { t } = useLang(); + const isOpen = cinema.status === "open"; + const href = `/?cinema=${cinema.slug}`; + + const handleClick = (event: MouseEvent) => { + // ปล่อยให้เบราว์เซอร์จัดการถ้าผู้ใช้เปิดแท็บใหม่ / กด modifier + if (!onSelect) return; + if (event.metaKey || event.ctrlKey || event.shiftKey || event.altKey) return; + if (event.button !== 0) return; + + event.preventDefault(); + onSelect(cinema.slug); + }; + + return ( + + {/* ปก */} +
+ + {isOpen ? t("status.open") : t("status.closed")} + +
+ + {/* เนื้อหา */} +
+

+ {cinema.name} +

+

{cinema.area}

+ +
+ + + · + + {isOpen ? t("status.open") : t("status.closed")} + +
+ + {/* แท็ก — ซ่อนบนมือถือเพื่อไม่ให้แน่น */} + {cinema.tags.length > 0 && ( +
+ {cinema.tags.map((tag) => ( + + {tag} + + ))} +
+ )} +
+
+ ); +} diff --git a/app/app/components/cinema/CinemaDetailSheet.tsx b/app/app/components/cinema/CinemaDetailSheet.tsx new file mode 100644 index 0000000..c6c8e3e --- /dev/null +++ b/app/app/components/cinema/CinemaDetailSheet.tsx @@ -0,0 +1,363 @@ +import { + IconBook, + IconBriefcase, + IconBus, + IconCar, + IconChevronLeft, + IconChevronRight, + IconCircleCheck, + IconCoffee, + IconExternalLink, + IconMap, + IconMapPin, + IconPlant2, + IconShoppingBag, + IconSofa, + IconTicket, + IconToolsKitchen2, + IconTrain, + IconX, +} from "@tabler/icons-react"; +import { useEffect, useRef, type ComponentType } from "react"; + +import { CinemaCard } from "./CinemaCard"; +import { getCinema, getOtherCinemas } from "@/lib/cinemas"; +import { useLang, type MessageKey } from "@/lib/i18n"; + +const BORDER = "#332B2B"; + +type IconType = ComponentType<{ size?: number; stroke?: number; className?: string }>; + +const TRANSPORT: { icon: IconType; labelKey: MessageKey; valueKey: MessageKey }[] = [ + { icon: IconCar, labelKey: "transport.car", valueKey: "transport.carValue" }, + { icon: IconTrain, labelKey: "transport.train", valueKey: "transport.trainValue" }, + { icon: IconBus, labelKey: "transport.bus", valueKey: "transport.busValue" }, +]; + +const FACILITIES: { icon: IconType; titleKey: MessageKey; subKey: MessageKey }[] = [ + { icon: IconSofa, titleKey: "facility.lounge", subKey: "facility.loungeSub" }, + { icon: IconTicket, titleKey: "facility.ticket", subKey: "facility.ticketSub" }, + { icon: IconToolsKitchen2, titleKey: "facility.food", subKey: "facility.foodSub" }, + { icon: IconCoffee, titleKey: "facility.cafe", subKey: "facility.cafeSub" }, + { icon: IconPlant2, titleKey: "facility.garden", subKey: "facility.gardenSub" }, + { icon: IconBook, titleKey: "facility.book", subKey: "facility.bookSub" }, + { icon: IconBriefcase, titleKey: "facility.colearn", subKey: "facility.colearnSub" }, + { icon: IconShoppingBag, titleKey: "facility.other", subKey: "facility.otherSub" }, +]; + +const CONTACTS = [ + { label: "Website", value: "alterflixhub.com" }, + { label: "Mobile Application", value: "AlterFlixHub" }, + { label: "Facebook", value: "AlterFlixHub" }, + { label: "Call", value: "098-869-0997" }, +]; + +interface CinemaDetailSheetProps { + /** slug ที่กำลังเปิด — null = ปิด */ + slug: string | null; + onClose: () => void; + /** เปลี่ยนโรงโดยไม่ปิด sheet (แทนการนำทาง) */ + onSelectCinema: (slug: string) => void; +} + +/** + * รายละเอียดโรงภาพยนตร์ — เปิดเป็น overlay บนหน้าเดิม (single page) + * ------------------------------------------------------------ + * ★ ไม่เปลี่ยน route → รายการด้านหลังไม่ unmount, scroll ไม่หาย, ไม่รีเฟรช + * ★ URL ยังเปลี่ยน (?cinema=slug) → แชร์ลิงก์ได้, back ได้ + * ★ มือถือ 6": full-screen sheet + ปุ่มปิด 44px + CTA ติดขอบล่าง (thumb zone) + * ★ แท็บเล็ต/เดสก์ท็อป: การ์ดกลางจอ สูงสุด 90dvh, เลื่อนในกล่อง + * ★ ใช้ native → focus trap + Esc + backdrop ให้เอง + */ +export function CinemaDetailSheet({ slug, onClose, onSelectCinema }: CinemaDetailSheetProps) { + const dialogRef = useRef(null); + const { t } = useLang(); + const cinema = getCinema(slug ?? undefined); + + /* เปิด/ปิด dialog ตาม slug */ + useEffect(() => { + const el = dialogRef.current; + if (!el) return; + + if (slug && !el.open) { + el.showModal(); + } else if (!slug && el.open) { + el.close(); + } + }, [slug]); + + /* Esc / ปิดจากเบราว์เซอร์ → sync state */ + useEffect(() => { + const el = dialogRef.current; + if (!el) return; + + const handleClose = () => onClose(); + el.addEventListener("close", handleClose); + return () => el.removeEventListener("close", handleClose); + }, [onClose]); + + /* เปลี่ยน slug = เลื่อนกลับขึ้นบนสุดของ sheet */ + useEffect(() => { + if (slug) dialogRef.current?.scrollTo({ top: 0 }); + }, [slug]); + + const isOpen = cinema?.status === "open"; + const others = cinema ? getOtherCinemas(cinema.slug, 3) : []; + const mapHref = cinema + ? `https://maps.google.com/?q=${encodeURIComponent(cinema.mapQuery)}` + : "#"; + + return ( + + {cinema && ( +
+ {/* ---------- แถบปิด (ติดบน) ---------- */} +
+
+

{cinema.name}

+

+ {cinema.area} · ★ {cinema.rating.toFixed(1)} +

+
+ +
+ + {/* ---------- เนื้อหา (เลื่อน) ---------- */} +
+ {/* แกลเลอรี */} +
+
+
+
+ + {cinema.name} + +
+ + +
+
+ + {/* หัวเรื่อง */} +
+
+ {cinema.tags.map((tag) => ( + + {tag} + + ))} + + {isOpen ? t("status.open") : t("status.closed")} + +
+ +

+ {cinema.name} +

+ +
+
+
+ + {t("detail.map")} + +
+ +

+ {cinema.description} +

+
+ + {/* การเดินทาง */} +
+

+ {t("detail.transport")} +

+ {TRANSPORT.map((row, index) => { + const Icon = row.icon; + return ( +
+
+
+
+ {t(row.valueKey)} +
+
+ ); + })} +
+ + {/* ติดต่อ + ชำระเงิน */} +
+

{t("detail.contactTitle")}

+ +
+ {CONTACTS.map((contact) => ( +
+ {contact.label} + + {contact.value} + +
+ ))} +
+ +
+ {t("detail.payment")} +
+ {["เงินสด", "บัตรเครดิต", "สแกนจ่าย"].map((payment) => ( + + + ))} +
+
+
+ + {/* สิ่งอำนวยความสะดวก */} +
+

+ {t("detail.facilities")} +

+
+ {FACILITIES.map((facility) => { + const Icon = facility.icon; + return ( +
+
+
+
+
+ {t(facility.titleKey)} +
+
+ {t(facility.subKey)} +
+
+
+ ); + })} +
+
+ + {/* ที่ตั้ง */} +
+

{t("detail.location")}

+ + + + +

{cinema.address}

+
+ + {/* โรงอื่น ๆ — เปลี่ยนใน sheet ทันที ไม่รีโหลด */} +
+

+ {t("detail.otherCinemas")} +

+
+ {others.map((other) => ( + onSelectCinema(other.slug)} + /> + ))} +
+
+
+ + {/* ---------- CTA ติดขอบล่าง (thumb zone) ---------- */} +
+ +
+
+ )} +
+ ); +} diff --git a/app/app/components/cinema/SiteHeader.tsx b/app/app/components/cinema/SiteHeader.tsx new file mode 100644 index 0000000..ecb4cc8 --- /dev/null +++ b/app/app/components/cinema/SiteHeader.tsx @@ -0,0 +1,138 @@ +import { + IconBrandFacebook, + IconBrandInstagram, + IconBrandLinkedin, + IconBrandTelegram, + IconBrandYoutube, +} from "@tabler/icons-react"; +import { useState } from "react"; +import { Link, useLocation } from "react-router"; + +import { AboutDialog } from "./AboutDialog"; +import { useLang } from "@/lib/i18n"; + +/** โซเชียลใน footer — เพิ่ม/ลบที่นี่ที่เดียว */ +const SOCIALS = [ + { label: "Facebook", href: "https://facebook.com", icon: IconBrandFacebook }, + { label: "Instagram", href: "https://instagram.com", icon: IconBrandInstagram }, + { label: "LinkedIn", href: "https://linkedin.com", icon: IconBrandLinkedin }, + { label: "YouTube", href: "https://youtube.com", icon: IconBrandYoutube }, + { label: "Telegram", href: "https://telegram.org", icon: IconBrandTelegram }, +] as const; + +/** + * Header กลาง — ใช้ทั้งหน้าแรกและหน้ารายละเอียด + * ★ มือถือ 6": ความสูง 56px, แบรนด์เล็กลง, ปุ่ม lang กระชับ — ไม่ล้นที่ 360px + * ★ แตะง่าย: ทุกปุ่มขั้นต่ำ 40px, ปุ่มหลัก 44px + * ★ sticky + พื้นหลังเบลอ เพื่อไม่ให้เนื้อหาทะลุตอนเลื่อน + */ +export function SiteHeader() { + const { t, lang, setLang } = useLang(); + const [aboutOpen, setAboutOpen] = useState(false); + const { pathname } = useLocation(); + + const isHome = pathname === "/"; + + return ( + <> +
+
+ {/* แบรนด์ */} + + + + AlterFlixHub + + + +
+ {/* กลับหน้าแรก — แสดงเฉพาะเมื่อไม่ใช่หน้าแรก */} + {!isHome && ( + + {t("nav.allCinemas")} + + )} + + + + {/* สลับภาษา */} +
+ {(["th", "en"] as const).map((code) => ( + + ))} +
+
+
+
+ + setAboutOpen(false)} /> + + ); +} + +/** Footer กลาง — กระชับบนมือถือ */ +export function SiteFooter() { + const { t } = useLang(); + + return ( +
+ {/* โซเชียล — เล็กลงบนมือถือเพื่อไม่กินพื้นที่ */} +
+ {SOCIALS.map((social) => { + const Icon = social.icon; + return ( + + + ); + })} +
+ +

+ © 2026 AlterFlixHub · {t("footer.rights")} +

+
+ ); +} diff --git a/app/app/components/layout/Layout.tsx b/app/app/components/layout/Layout.tsx index 92d7df2..aaf8d00 100644 --- a/app/app/components/layout/Layout.tsx +++ b/app/app/components/layout/Layout.tsx @@ -1,5 +1,7 @@ import { HeaderActionsProvider } from "@agent-native/toolkit/app-shell"; +import { LangProvider } from "@/lib/i18n"; + interface LayoutProps { children: React.ReactNode; } @@ -18,11 +20,14 @@ interface LayoutProps { export function Layout({ children }: LayoutProps) { return ( -
-
- {children} -
-
+ {/* LangProvider ครอบทั้งแอป — header/footer/ทุกหน้าอ่านภาษาจากที่เดียว */} + +
+
+ {children} +
+
+
); } diff --git a/app/app/lib/cinemas.ts b/app/app/lib/cinemas.ts new file mode 100644 index 0000000..fc64668 --- /dev/null +++ b/app/app/lib/cinemas.ts @@ -0,0 +1,124 @@ +/** + * ข้อมูลโรงภาพยนตร์ — แหล่งเดียวสำหรับหน้าแรกและหน้ารายละเอียด + * ★ เพิ่มโรงใหม่ = เพิ่ม object ที่นี่ (ทั้ง 2 หน้าอ่านจากที่เดียว) + */ + +export type CinemaStatus = "open" | "closed"; + +export interface Cinema { + /** ใช้ใน URL: /cinema/ */ + slug: string; + name: string; + /** ย่อสถานที่ เช่น "ชั้น 4 เซ็นทรัลเวิลด์" */ + area: string; + rating: number; + status: CinemaStatus; + tags: string[]; + description: string; + address: string; + /** query สำหรับ Google Maps */ + mapQuery: string; + /** ไล่ระดับสีปกการ์ด (ดำ-แดง ตามธีม) */ + cover: string; +} + +/** ไล่ระดับสีปก — ใช้ซ้ำทั้งการ์ดหน้าแรกและหน้ารายละเอียด */ +export const COVER_GRADIENTS = [ + "linear-gradient(135deg,#7a0000,#e00000)", + "linear-gradient(135deg,#3a0d0d,#a00000)", + "linear-gradient(135deg,#1a0a0a,#c00000)", + "linear-gradient(135deg,#5c0505,#ff1f1f)", + "linear-gradient(135deg,#2b0a0a,#b00000)", + "linear-gradient(135deg,#4d0707,#e00000)", +] as const; + +export const CINEMAS: Cinema[] = [ + { + slug: "alterflix-major", + name: "AlterFlix Major", + area: "ชั้น 4 เซ็นทรัลเวิลด์", + rating: 4.8, + status: "open", + tags: ["อาร์ตเฮาส์", "หนังนอกกระแส"], + description: + "โรงภาพยนตร์สำหรับคนที่อยากค้นพบหนังหลากหลาย เน้นภาพยนตร์นอกกระแสและเรื่องที่ไม่ได้เข้าฉายในวงกว้าง พร้อมเรื่องราวและมุมมองที่แตกต่างสำหรับคนรักหนัง", + address: "ชั้น 4 เซ็นทรัลเวิลด์ 999/9 ถนนพระราม 1 เขตปทุมวัน กรุงเทพฯ 10330", + mapQuery: "Central World Bangkok", + cover: COVER_GRADIENTS[0], + }, + { + slug: "alterflix-imax", + name: "AlterFlix IMAX", + area: "ชั้น 5 สยามพารากอน", + rating: 4.9, + status: "open", + tags: ["IMAX", "จอใหญ่"], + description: + "จอ IMAX ขนาดใหญ่พร้อมระบบเสียงรอบทิศทาง เหมาะกับหนังบล็อกบัสเตอร์ที่ต้องการความสมจริงที่สุด", + address: "ชั้น 5 สยามพารากอน 991/1 ถนนพระราม 1 เขตปทุมวัน กรุงเทพฯ 10330", + mapQuery: "Siam Paragon Bangkok", + cover: COVER_GRADIENTS[1], + }, + { + slug: "alterflix-plus", + name: "AlterFlix Plus", + area: "ชั้น 3 เอ็มควอเทียร์", + rating: 4.7, + status: "open", + tags: ["ที่นั่งกว้าง", "ครอบครัว"], + description: + "โรงภาพยนตร์ที่นั่งกว้างเป็นพิเศษ เดินทางสะดวกด้วยรถไฟฟ้า เหมาะกับครอบครัวและกลุ่มเพื่อน", + address: "ชั้น 3 เอ็มควอเทียร์ 689 ถนนสุขุมวิท เขตวัฒนา กรุงเทพฯ 10110", + mapQuery: "EmQuartier Bangkok", + cover: COVER_GRADIENTS[2], + }, + { + slug: "alterflix-mini", + name: "AlterFlix Mini", + area: "ชั้น 2 เดอะมอลล์บางกะปิ", + rating: 4.5, + status: "closed", + tags: ["โรงเล็ก", "ราคาย่อมเยา"], + description: + "โรงขนาดเล็กบรรยากาศอบอุ่น ราคาย่อมเยา ปัจจุบันปิดปรับปรุงเพื่อเปลี่ยนระบบภาพและเสียงใหม่", + address: "ชั้น 2 เดอะมอลล์บางกะปิ 3522 ถนนลาดพร้าว เขตบางกะปิ กรุงเทพฯ 10240", + mapQuery: "The Mall Bangkapi", + cover: COVER_GRADIENTS[3], + }, + { + slug: "alterflix-vip", + name: "AlterFlix VIP", + area: "ชั้น 6 ไอคอนสยาม", + rating: 4.9, + status: "open", + tags: ["VIP", "เสิร์ฟถึงที่นั่ง"], + description: + "โรงภาพยนตร์ระดับพรีเมียม ที่นั่ง recliner พร้อมบริการเสิร์ฟอาหารและเครื่องดื่มถึงที่นั่ง", + address: "ชั้น 6 ไอคอนสยาม 299 ถนนเจริญนคร เขตคลองสาน กรุงเทพฯ 10600", + mapQuery: "ICONSIAM Bangkok", + cover: COVER_GRADIENTS[4], + }, + { + slug: "alterflix-classic", + name: "AlterFlix Classic", + area: "ชั้น 3 ฟิวเจอร์พาร์ค", + rating: 4.4, + status: "open", + tags: ["หนังคลาสสิก", "ราคาย่อมเยา"], + description: + "โรงภาพยนตร์ที่ฉายหนังคลาสสิกและหนังไทย restored เป็นรอบพิเศษ เหมาะกับคนที่ชอบบรรยากาศโรงหนังแบบเดิม", + address: "ชั้น 3 ฟิวเจอร์พาร์ค รังสิต 94 ถนนพหลโยธิน ต.คูคต อ.ลำลูกกา ปทุมธานี 12130", + mapQuery: "Future Park Rangsit", + cover: COVER_GRADIENTS[5], + }, +]; + +export function getCinema(slug: string | undefined): Cinema | undefined { + if (!slug) return undefined; + return CINEMAS.find((c) => c.slug === slug); +} + +/** โรงอื่น ๆ ที่ไม่ใช่ slug ที่ระบุ — ใช้แสดง "โรงหนังอิสระอื่นๆ" */ +export function getOtherCinemas(slug: string, limit = 3): Cinema[] { + return CINEMAS.filter((c) => c.slug !== slug).slice(0, limit); +} diff --git a/app/app/lib/i18n.tsx b/app/app/lib/i18n.tsx new file mode 100644 index 0000000..c1f3d67 --- /dev/null +++ b/app/app/lib/i18n.tsx @@ -0,0 +1,214 @@ +/** + * i18n แบบเบา — TH/EN สำหรับ chrome (nav, hero, ปุ่ม, footer) + * ★ ข้อความไทยเป็นค่าเริ่มต้น · เก็บภาษาที่เลือกใน localStorage + * ★ เพิ่มข้อความใหม่ = เพิ่มทั้ง th และ en (คีย์ต้องตรงกัน) + */ +import { + createContext, + useCallback, + useContext, + useEffect, + useMemo, + useState, + type ReactNode, +} from "react"; + +export type Lang = "th" | "en"; + +const STORAGE_KEY = "alterflixhub:lang"; + +const DICT = { + th: { + "brand.partA": "Alter", + "brand.partB": "Flix", + "brand.partC": "Hub", + "nav.about": "เกี่ยวกับเรา", + "nav.home": "หน้าแรก", + "nav.allCinemas": "โรงภาพยนตร์ทั้งหมด", + "lang.label": "ภาษา", + + "home.hero1": "ค้นพบโรงภาพยนตร์", + "home.hero2": "รอบตัวคุณ", + "home.lead": "เลือกโรงภาพยนตร์ที่ใช่ ดูรอบฉายและรายละเอียดได้ในที่เดียว", + "home.sectionTitle": "โรงภาพยนตร์ทั้งหมด", + "home.count": "{n} แห่ง", + + "status.open": "เปิดบริการ", + "status.closed": "ปิดปรับปรุง", + + "detail.back": "ย้อนกลับ", + "detail.breadcrumb": "หน้าแรก / รายละเอียดโรงภาพยนตร์", + "detail.map": "เปิด Google map", + "detail.contactTitle": "สอบถามข้อมูลและจองตั๋ว", + "detail.book": "ดูรอบฉาย", + "detail.payment": "ชำระเงิน", + "detail.facilities": "สิ่งอำนวยความสะดวก", + "detail.location": "ที่ตั้ง", + "detail.otherCinemas": "โรงหนังอิสระอื่นๆ", + "detail.transport": "การเดินทาง", + + "transport.car": "รถยนต์ส่วนตัว", + "transport.carValue": "ที่จอดรถภายในศูนย์การค้า", + "transport.train": "รถไฟฟ้า", + "transport.trainValue": "MRT / BTS สถานีใกล้เคียง", + "transport.bus": "รถประจำทาง", + "transport.busValue": "29, 34, 36, 40, 47, 50", + + "facility.lounge": "โซนนั่งรอ", + "facility.loungeSub": "บริเวณโถงโรงภาพยนตร์", + "facility.ticket": "จุดจำหน่ายตั๋ว", + "facility.ticketSub": "Box Office", + "facility.food": "ร้านอาหาร", + "facility.foodSub": "ภายในศูนย์การค้า", + "facility.cafe": "ร้านคาเฟ่", + "facility.cafeSub": "บริเวณโถงโรงภาพยนตร์", + "facility.garden": "สวนหย่อม", + "facility.gardenSub": "ลานกลางแจ้ง", + "facility.book": "ร้านหนังสือ", + "facility.bookSub": "ภายในศูนย์การค้า", + "facility.colearn": "Co-Learning Space", + "facility.colearnSub": "บริเวณโถงโรงภาพยนตร์", + "facility.other": "อื่นๆ", + "facility.otherSub": "ร้านทำผม ร้านทำเล็บ", + + "about.title": "เกี่ยวกับเรา", + "about.body": + "AlterFlixHub — ศูนย์รวมข้อมูลโรงภาพยนตร์ ดูรอบฉาย เปรียบเทียบ และค้นพบประสบการณ์ชมภาพยนตร์ที่ดีที่สุด", + "about.dev": "ผู้พัฒนา", + "about.close": "ปิด", + + "footer.rights": "สงวนลิขสิทธิ์", + "notFound.title": "ไม่พบโรงภาพยนตร์นี้", + "notFound.body": "ลิงก์อาจเปลี่ยนไปแล้ว หรือโรงภาพยนตร์ถูกนำออกจากระบบ", + "notFound.cta": "ดูโรงภาพยนตร์ทั้งหมด", + }, + en: { + "brand.partA": "Alter", + "brand.partB": "Flix", + "brand.partC": "Hub", + "nav.about": "About us", + "nav.home": "Home", + "nav.allCinemas": "All cinemas", + "lang.label": "Language", + + "home.hero1": "Discover cinemas", + "home.hero2": "around you", + "home.lead": "Pick the right cinema, check showtimes and details in one place.", + "home.sectionTitle": "All cinemas", + "home.count": "{n} venues", + + "status.open": "Now open", + "status.closed": "Temporarily closed", + + "detail.back": "Back", + "detail.breadcrumb": "Home / Cinema details", + "detail.map": "Open Google map", + "detail.contactTitle": "Contact & booking", + "detail.book": "Showtimes", + "detail.payment": "Payment", + "detail.facilities": "Facilities", + "detail.location": "Location", + "detail.otherCinemas": "Other indie cinemas", + "detail.transport": "Getting here", + + "transport.car": "By car", + "transport.carValue": "Parking inside the mall", + "transport.train": "By rail", + "transport.trainValue": "Nearby MRT / BTS station", + "transport.bus": "By bus", + "transport.busValue": "29, 34, 36, 40, 47, 50", + + "facility.lounge": "Waiting lounge", + "facility.loungeSub": "Cinema lobby", + "facility.ticket": "Ticket counter", + "facility.ticketSub": "Box office", + "facility.food": "Restaurants", + "facility.foodSub": "Inside the mall", + "facility.cafe": "Cafés", + "facility.cafeSub": "Cinema lobby", + "facility.garden": "Garden", + "facility.gardenSub": "Outdoor plaza", + "facility.book": "Bookstore", + "facility.bookSub": "Inside the mall", + "facility.colearn": "Co-Learning Space", + "facility.colearnSub": "Cinema lobby", + "facility.other": "Others", + "facility.otherSub": "Hair & nail salon", + + "about.title": "About us", + "about.body": + "AlterFlixHub — your hub for cinema info, showtimes and the best movie-going experience.", + "about.dev": "Developer", + "about.close": "Close", + + "footer.rights": "All rights reserved", + "notFound.title": "Cinema not found", + "notFound.body": "The link may have changed, or this cinema was removed.", + "notFound.cta": "Browse all cinemas", + }, +} as const; + +export type MessageKey = keyof (typeof DICT)["th"]; + +interface LangContextValue { + lang: Lang; + setLang: (next: Lang) => void; + /** แปลคีย์ → ข้อความ · รองรับ {n} */ + t: (key: MessageKey, vars?: Record) => string; +} + +const LangContext = createContext(null); + +function readInitialLang(): Lang { + if (typeof window === "undefined") return "th"; + try { + const saved = window.localStorage.getItem(STORAGE_KEY); + if (saved === "th" || saved === "en") return saved; + } catch { + /* localStorage ถูกปิด */ + } + return "th"; +} + +export function LangProvider({ children }: { children: ReactNode }) { + const [lang, setLangState] = useState(readInitialLang); + + const setLang = useCallback((next: Lang) => { + setLangState(next); + try { + window.localStorage.setItem(STORAGE_KEY, next); + } catch { + /* ignore */ + } + }, []); + + // sync เพื่อ a11y + ให้เบราว์เซอร์เลือกฟอนต์ถูก + useEffect(() => { + document.documentElement.lang = lang; + }, [lang]); + + const value = useMemo(() => { + const dict = DICT[lang] as Record; + const fallback = DICT.th as Record; + + const t = (key: MessageKey, vars?: Record) => { + let text = dict[key] ?? fallback[key] ?? key; + if (vars) { + for (const [k, v] of Object.entries(vars)) { + text = text.split(`{${k}}`).join(String(v)); + } + } + return text; + }; + + return { lang, setLang, t }; + }, [lang, setLang]); + + return {children}; +} + +export function useLang(): LangContextValue { + const ctx = useContext(LangContext); + if (!ctx) throw new Error("useLang ต้องอยู่ใต้ "); + return ctx; +} diff --git a/app/app/root.tsx b/app/app/root.tsx index f52c4a3..3723f9d 100644 --- a/app/app/root.tsx +++ b/app/app/root.tsx @@ -32,12 +32,14 @@ const THEME_INIT_SCRIPT = getThemeInitScript(); export function Layout({ children }: { children: React.ReactNode }) { return ( - + + {/* ★ ห้ามใส่ maximum-scale / user-scalable=no — บล็อก pinch-zoom (a11y) + viewport-fit=cover เปิดให้ env(safe-area-inset-*) ทำงานบนมือถือขอบโค้ง */}