reboot alterflixhub

This commit is contained in:
Bkk1234 committed 2026-11-01 17:24:44 +07:00
commit 1e84023a44
188 files changed
+31629

No files matched your search

+300
View File
@@ -0,0 +1,300 @@
import { useState } from "react";
import type { AboutContent, AboutSection } from "@/lib/content-types";
import type { Locale } from "@/lib/i18n/messages";
const inputClass =
"w-full rounded-lg border border-[#303030] bg-[#141414] px-3 py-2 text-sm text-white outline-none transition focus:border-[#A92626] focus-visible:ring-2 focus-visible:ring-[#A92626]/40";
const labelClass = "flex flex-col gap-1.5 text-xs text-[#999]";
const buttonClass =
"min-h-11 rounded-lg border border-[#303030] px-3 text-sm transition hover:border-[#A92626] hover:text-[#D47272] focus-visible:outline focus-visible:outline-2 focus-visible:outline-[#A92626]";
const primaryButtonClass =
"min-h-11 rounded-lg bg-[#8F0808] px-4 text-sm font-medium transition hover:bg-[#a30a0a] focus-visible:outline focus-visible:outline-2 focus-visible:outline-[#D47272]";
const LOCALE_TABS: Array<{ code: Locale; label: string }> = [
{ code: "th", label: "ไทย" },
{ code: "en", label: "English" },
];
type AboutEditorProps = {
value: Record<Locale, AboutContent>;
defaults: Record<Locale, AboutContent>;
onChange: (next: Record<Locale, AboutContent>) => void;
onSave: () => void;
saving: boolean;
};
/**
* ตัวแก้ไขหน้า "เกี่ยวกับเรา" — แยกแท็บตามภาษา มีตัวอย่างหน้าเว็บให้ดูสด ๆ
* ฟิลด์ที่เว้นว่างจะถูกเซิร์ฟเวอร์คืนเป็นข้อความตั้งต้นให้อัตโนมัติ (sanitizeAbout)
*/
export function AboutEditor({
value,
defaults,
onChange,
onSave,
saving,
}: AboutEditorProps) {
const [locale, setLocale] = useState<Locale>("th");
const current = value[locale];
function patch(next: Partial<AboutContent>) {
onChange({ ...value, [locale]: { ...current, ...next } });
}
function patchSection(index: number, next: Partial<AboutSection>) {
patch({
sections: current.sections.map((section, i) =>
i === index ? { ...section, ...next } : section,
),
});
}
function moveSection(index: number, direction: -1 | 1) {
const target = index + direction;
if (target < 0 || target >= current.sections.length) return;
const sections = [...current.sections];
const [moved] = sections.splice(index, 1);
sections.splice(target, 0, moved);
patch({ sections });
}
function addSection() {
patch({
sections: [
...current.sections,
{ heading: `หัวข้อที่ ${current.sections.length + 1}`, body: "" },
],
});
}
function removeSection(index: number) {
patch({ sections: current.sections.filter((_, i) => i !== index) });
}
function restoreDefaults() {
onChange({ ...value, [locale]: defaults[locale] });
}
const titleMissing = current.title.trim() === "";
const leadTooLong = current.lead.length > 400;
return (
<div className="px-6 py-5">
<div className="mb-4 flex flex-wrap items-center justify-between gap-3">
<div
role="tablist"
aria-label="ภาษา"
className="flex items-center gap-1 rounded-lg border border-[#242424] bg-[#141414] p-1"
>
{LOCALE_TABS.map((tab) => (
<button
key={tab.code}
type="button"
role="tab"
aria-selected={locale === tab.code}
onClick={() => setLocale(tab.code)}
className={`min-h-9 rounded-md px-4 text-sm transition ${
locale === tab.code
? "bg-[#242424] font-semibold text-[#D47272]"
: "text-[#999] hover:text-white"
}`}
>
{tab.label}
</button>
))}
</div>
<div className="flex flex-wrap items-center gap-2">
<button type="button" className={buttonClass} onClick={restoreDefaults}>
คืนค่าตั้งต้น ({locale.toUpperCase()})
</button>
<button
type="button"
className={primaryButtonClass}
onClick={onSave}
disabled={saving}
>
{saving ? "กำลังบันทึก…" : "บันทึกหน้าเกี่ยวกับเรา"}
</button>
</div>
</div>
<div className="grid gap-6 lg:grid-cols-[minmax(0,1fr)_360px]">
<div className="flex flex-col gap-4">
<label className={labelClass}>
หัวข้อหลัก (H1)
<input
className={inputClass}
value={current.title}
onChange={(event) => patch({ title: event.target.value })}
aria-describedby="about-title-help"
aria-invalid={titleMissing}
/>
<span
id="about-title-help"
className={titleMissing ? "text-[#D47272]" : "text-[#8A8A8A]"}
>
{titleMissing
? "ต้องมีหัวข้อ — ถ้าเว้นว่าง ระบบจะใช้ข้อความตั้งต้น"
: `แสดงบนสุดของหน้า · ${current.title.length}/80 ตัวอักษร`}
</span>
</label>
<label className={labelClass}>
ย่อหน้าแนะนำ (ใต้หัวข้อ)
<textarea
className={`${inputClass} min-h-24 leading-[1.7]`}
value={current.lead}
onChange={(event) => patch({ lead: event.target.value })}
aria-describedby="about-lead-help"
aria-invalid={leadTooLong}
/>
<span
id="about-lead-help"
className={leadTooLong ? "text-[#D47272]" : "text-[#8A8A8A]"}
>
{leadTooLong
? "ยาวเกิน 400 ตัวอักษร — บนมือถือจะอ่านยาก"
: `${current.lead.length}/400 ตัวอักษร`}
</span>
</label>
<fieldset className="flex flex-col gap-3">
<legend className="mb-1 text-xs text-[#999]">
ส่วนย่อย ({current.sections.length} ส่วน)
</legend>
{current.sections.map((section, index) => (
<div
key={index}
className="rounded-xl border border-[#242424] bg-[#141414] p-4"
>
<div className="mb-2 flex items-center justify-between gap-2">
<span className="text-xs text-[#8A8A8A]">ส่วนที่ {index + 1}</span>
<div className="flex items-center gap-1">
<button
type="button"
className="size-8 rounded-md text-[#999] transition hover:bg-[#242424] hover:text-white disabled:opacity-40"
onClick={() => moveSection(index, -1)}
disabled={index === 0}
aria-label={`เลื่อนส่วนที่ ${index + 1} ขึ้น`}
>
↑
</button>
<button
type="button"
className="size-8 rounded-md text-[#999] transition hover:bg-[#242424] hover:text-white disabled:opacity-40"
onClick={() => moveSection(index, 1)}
disabled={index === current.sections.length - 1}
aria-label={`เลื่อนส่วนที่ ${index + 1} ลง`}
>
↓
</button>
<button
type="button"
className="min-h-8 rounded-md px-2 text-xs text-[#D47272] transition hover:bg-[#242424]"
onClick={() => removeSection(index)}
>
ลบ
</button>
</div>
</div>
<label className={labelClass}>
หัวข้อย่อย
<input
className={inputClass}
value={section.heading}
onChange={(event) =>
patchSection(index, { heading: event.target.value })
}
/>
</label>
<label className={`${labelClass} mt-2`}>
เนื้อหา
<textarea
className={`${inputClass} min-h-24 leading-[1.75]`}
value={section.body}
onChange={(event) =>
patchSection(index, { body: event.target.value })
}
/>
</label>
</div>
))}
<button
type="button"
className={`${buttonClass} self-start`}
onClick={addSection}
>
+ เพิ่มส่วน
</button>
</fieldset>
<div className="rounded-xl border border-[#A92626]/40 bg-[#141414] p-4">
<p className="mb-3 text-xs text-[#999]">กล่องติดต่อ (ท้ายหน้า)</p>
<label className={labelClass}>
หัวข้อ
<input
className={inputClass}
value={current.contactHeading}
onChange={(event) =>
patch({ contactHeading: event.target.value })
}
/>
</label>
<label className={`${labelClass} mt-2`}>
ข้อความ
<textarea
className={`${inputClass} min-h-20 leading-[1.75]`}
value={current.contactNote}
onChange={(event) => patch({ contactNote: event.target.value })}
/>
</label>
</div>
</div>
<aside className="lg:sticky lg:top-24 lg:self-start">
<p className="mb-2 text-xs text-[#8A8A8A]">ตัวอย่างหน้าเว็บ (สด)</p>
<div className="rounded-xl border border-[#242424] bg-[#0D0D0D] p-4">
<h3 className="text-xl font-bold leading-[1.3]">
{current.title || "—"}
</h3>
<p className="mt-2 text-sm leading-[1.7] text-[#B3B3B3]">
{current.lead || "—"}
</p>
<div className="mt-3 flex flex-col gap-2">
{current.sections.map((section, index) => (
<div
key={index}
className="rounded-lg border border-[#242424] bg-[#141414] p-3"
>
<p className="text-sm font-semibold">{section.heading}</p>
<p className="mt-1 text-xs leading-[1.7] text-[#B3B3B3]">
{section.body}
</p>
</div>
))}
</div>
<div className="mt-3 rounded-lg border border-[#A92626]/50 bg-gradient-to-b from-[#8F0808]/20 to-transparent p-3">
<p className="text-sm font-semibold">{current.contactHeading}</p>
<p className="mt-1 text-xs leading-[1.7] text-[#B3B3B3]">
{current.contactNote}
</p>
</div>
</div>
<a
href={`/about?lang=${locale}`}
target="_blank"
rel="noreferrer"
className="mt-3 inline-flex min-h-11 items-center text-xs text-[#D47272] underline-offset-4 hover:underline"
>
เปิดหน้า /about?lang={locale} ↗
</a>
</aside>
</div>
</div>
);
}
+51
View File
@@ -0,0 +1,51 @@
import { IconChevronRight } from "@tabler/icons-react";
import type { ReactNode } from "react";
/**
* หมวดการ์ดแบบพับได้ของหลังบ้าน (ใช้ <details> เนทีฟ — คีย์บอร์ดและ screen reader ทำงานได้เอง)
* ค่าเริ่มต้น = พับเก็บ เพื่อไม่ให้หน้าแอดมินยืดยาว
*/
type Props = {
title: string;
description?: string;
/** ข้อความสั้น ๆ เช่นจำนวนรายการ */
badge?: string;
defaultOpen?: boolean;
children: ReactNode;
};
export function AdminSection({
title,
description,
badge,
defaultOpen = false,
children,
}: Props) {
return (
<details
open={defaultOpen}
className="group overflow-hidden rounded-xl border border-[#242424] bg-[#111111]"
>
<summary className="flex cursor-pointer list-none items-center justify-between gap-3 px-4 py-3 transition hover:bg-[#171717] focus-visible:outline focus-visible:outline-2 focus-visible:outline-offset-[-2px] focus-visible:outline-[#A92626] [&::-webkit-details-marker]:hidden">
<span className="flex min-w-0 items-center gap-2">
<IconChevronRight
size={16}
className="shrink-0 text-[#8F8F8F] transition-transform group-open:rotate-90"
/>
<span className="truncate text-sm font-medium">{title}</span>
{badge ? (
<span className="shrink-0 rounded-full bg-[#242424] px-2 py-0.5 text-[11px] text-[#B3B3B3]">
{badge}
</span>
) : null}
</span>
{description ? (
<span className="hidden shrink-0 text-[11px] text-[#777] sm:block">
{description}
</span>
) : null}
</summary>
<div className="border-t border-[#242424] px-4 py-4">{children}</div>
</details>
);
}
+82
View File
@@ -0,0 +1,82 @@
type ChipOption = {
value: string;
label: string;
};
type ChipPickerProps = {
options: ChipOption[];
selected: string[];
onToggle: (value: string) => void;
/** ข้อความเมื่อยังไม่ได้เลือกอะไร */
emptyHint?: string;
};
/**
* ปุ่มเลือกหลายค่าแบบชิป สำหรับหลังบ้าน (หมวดหมู่ / สิ่งอำนวยความสะดวก)
* ค่าที่เลือกจะถูกเก็บตามลำดับ options เสมอ เพื่อให้ข้อมูลในไฟล์นิ่ง
*/
export function ChipPicker({
options,
selected,
onToggle,
emptyHint,
}: ChipPickerProps) {
const chosen = new Set(selected);
const known = new Set(options.map((option) => option.value));
const extras = selected.filter((value) => !known.has(value));
return (
<div className="flex flex-wrap gap-2">
{options.map((option) => {
const active = chosen.has(option.value);
return (
<button
key={option.value}
type="button"
aria-pressed={active}
onClick={() => onToggle(option.value)}
className={`rounded-full border px-3 py-1 text-xs transition ${
active
? "border-[#A92626] bg-[rgba(143,8,8,0.18)] text-[#D47272]"
: "border-[#303030] text-[#999] hover:border-[#A92626] hover:text-white"
}`}
>
{option.label}
</button>
);
})}
{extras.map((value) => (
<button
key={value}
type="button"
aria-pressed
onClick={() => onToggle(value)}
className="rounded-full border border-[#A92626] bg-[rgba(143,8,8,0.18)] px-3 py-1 text-xs text-[#D47272] transition hover:border-[#D47272]"
>
{value}
</button>
))}
{options.length === 0 && extras.length === 0 && emptyHint ? (
<span className="text-xs text-[#777]">{emptyHint}</span>
) : null}
</div>
);
}
/**
* สลับค่าหนึ่งตัวในลิสต์ แล้วเรียงตามลำดับ options (ค่าที่ไม่รู้จักต่อท้าย)
*/
export function toggleValue(
selected: string[],
value: string,
order: string[],
): string[] {
const next = selected.includes(value)
? selected.filter((item) => item !== value)
: [...selected, value];
const rank = (item: string) => {
const index = order.indexOf(item);
return index < 0 ? order.length + 1 : index;
};
return [...next].sort((a, b) => rank(a) - rank(b));
}
@@ -0,0 +1,105 @@
import type { Cinema } from "@/lib/cinemas";
import { DEFAULT_LOCALE, MESSAGES, type FacilityKey } from "@/lib/i18n/messages";
/**
* แก้ข้อความสิ่งอำนวยความสะดวก "ของโรงนี้" (ผูกกับโรง ไม่ใช่ส่วนกลาง)
*
* - ชื่อหัวข้อ: ช่องเดียว (ใช้ทั้ง TH/EN) — ว่าง = ใช้ค่าเริ่มต้นจาก messages.ts
* - คำอธิบาย TH/EN: แสดงเฉพาะโรงที่ต้องการ (hasDescriptions) เช่น เฮ้าส์ สามย่าน
* ที่มีข้อมูลครบแล้ว โรงอื่นไม่ต้องกรอก
*/
export type FacilityDetail = {
label?: string;
sub_th?: string;
sub_en?: string;
};
const ADMIN_MESSAGES = MESSAGES[DEFAULT_LOCALE];
type Props = {
facilities: FacilityKey[];
details: NonNullable<Cinema["facility_details"]>;
hasDescriptions: boolean;
onChange: (next: NonNullable<Cinema["facility_details"]>) => void;
inputClass: string;
labelClass: string;
};
export function CinemaFacilitiesEditor({
facilities,
details,
hasDescriptions,
onChange,
inputClass,
labelClass,
}: Props) {
if (facilities.length === 0) {
return (
<span className="text-[11px] text-[#777]">
เลือกหัวข้อด้านบนก่อน แล้วค่อยใส่ชื่อที่ต้องการ
</span>
);
}
function update(key: FacilityKey, patch: FacilityDetail) {
const current = details[key] ?? {};
const next: FacilityDetail = { ...current, ...patch };
const cleaned: FacilityDetail = {};
if (next.label?.trim()) cleaned.label = next.label;
if (next.sub_th?.trim()) cleaned.sub_th = next.sub_th;
if (next.sub_en?.trim()) cleaned.sub_en = next.sub_en;
onChange({ ...details, [key]: cleaned });
}
return (
<div className="flex flex-col gap-2">
{facilities.map((key) => {
const fallback = ADMIN_MESSAGES.facilities[key];
const detail = details[key] ?? {};
return (
<div
key={key}
className="grid gap-2 rounded-lg border border-[#242424] p-2 sm:grid-cols-2"
>
<label className={labelClass}>
ชื่อหัวข้อ
<input
className={inputClass}
value={detail.label ?? ""}
placeholder={fallback.title}
onChange={(event) => update(key, { label: event.target.value })}
/>
</label>
{hasDescriptions ? (
<>
<label className={labelClass}>
คำอธิบาย (TH)
<input
className={inputClass}
value={detail.sub_th ?? ""}
placeholder={fallback.sub}
onChange={(event) =>
update(key, { sub_th: event.target.value })
}
/>
</label>
<label className={labelClass}>
คำอธิบาย (EN)
<input
className={inputClass}
value={detail.sub_en ?? ""}
placeholder={MESSAGES.en.facilities[key].sub}
onChange={(event) =>
update(key, { sub_en: event.target.value })
}
/>
</label>
</>
) : null}
</div>
);
})}
</div>
);
}
+253
View File
@@ -0,0 +1,253 @@
import {
IconArrowDown,
IconArrowUp,
IconGripVertical,
IconSortAscendingLetters,
} from "@tabler/icons-react";
import { useMemo, useState } from "react";
import type { Cinema } from "@/lib/cinemas";
/**
* รายชื่อโรงหนังในหลังบ้าน — เรียง ก-ฮ และสลับตำแหน่งได้
*
* - โหมด "ลำดับที่จัดไว้": ลากวางสลับที่ หรือกด ↑ ↓ (ใช้เมาส์/คีย์บอร์ดได้ทั้งคู่)
* ลำดับที่ได้คือลำดับเดียวกับที่หน้าเว็บแสดง (อาร์เรย์ cinemas ใน content.json)
* - โหมด "ก-ฮ": เรียงตามชื่อไทยด้วย Intl.Collator("th") — ยังไม่บันทึกจนกว่าจะกด "ใช้ลำดับนี้"
* (กันเข้าใจผิดว่าลากในโหมดเรียงได้)
*/
const thaiCollator = new Intl.Collator("th", {
sensitivity: "base",
numeric: true,
});
function sortKey(cinema: Cinema): string {
return (cinema.name_th?.trim() || cinema.name || "").trim();
}
/** เรียงชื่อโรงหนังภาษาไทยตามพจนานุกรม ก-ฮ */
export function sortCinemasByName(cinemas: Cinema[]): Cinema[] {
return [...cinemas].sort((a, b) => thaiCollator.compare(sortKey(a), sortKey(b)));
}
/** เทียบว่าสองลิสต์มี slug เรียงเหมือนกันหรือยัง */
export function hasSameOrder(a: Cinema[], b: Cinema[]): boolean {
if (a.length !== b.length) return false;
return a.every((cinema, index) => cinema.slug === b[index]?.slug);
}
/** ย้ายโรงหนังจากตำแหน่งหนึ่งไปแทรกก่อน/หลังอีกตัว */
export function moveCinema(
cinemas: Cinema[],
fromSlug: string,
toSlug: string,
position: "before" | "after" = "before",
): Cinema[] {
if (fromSlug === toSlug) return cinemas;
const from = cinemas.findIndex((item) => item.slug === fromSlug);
const target = cinemas.findIndex((item) => item.slug === toSlug);
if (from < 0 || target < 0) return cinemas;
const next = [...cinemas];
const [moved] = next.splice(from, 1);
const insertAt = next.findIndex((item) => item.slug === toSlug);
if (insertAt < 0) return cinemas;
next.splice(position === "after" ? insertAt + 1 : insertAt, 0, moved);
return next;
}
/** เลื่อนขึ้น/ลงทีละหนึ่งตำแหน่ง (สำหรับปุ่มลูกศร) */
export function shiftCinema(cinemas: Cinema[], slug: string, delta: number): Cinema[] {
const from = cinemas.findIndex((item) => item.slug === slug);
const to = from + delta;
if (from < 0 || to < 0 || to >= cinemas.length) return cinemas;
const next = [...cinemas];
const [moved] = next.splice(from, 1);
next.splice(to, 0, moved);
return next;
}
type SortMode = "manual" | "thai";
type CinemaListProps = {
cinemas: Cinema[];
selected: string | null;
/** ลำดับในหน้าเว็บยังไม่ตรงกับที่บันทึกไว้หรือไม่ */
dirty: boolean;
saving: boolean;
onSelect: (slug: string) => void;
onReorder: (next: Cinema[]) => void;
onSaveOrder: () => void;
};
const modeButtonClass = (active: boolean) =>
`flex-1 rounded-md px-2 py-1 text-[11px] transition ${
active ? "bg-[#242424] text-[#D47272]" : "text-[#999] hover:text-white"
}`;
const arrowButtonClass =
"flex size-6 items-center justify-center rounded text-[#777] transition hover:bg-[#242424] hover:text-white disabled:pointer-events-none disabled:opacity-30";
export function CinemaList({
cinemas,
selected,
dirty,
saving,
onSelect,
onReorder,
onSaveOrder,
}: CinemaListProps) {
const [mode, setMode] = useState<SortMode>("manual");
const [dragSlug, setDragSlug] = useState<string | null>(null);
const [overSlug, setOverSlug] = useState<string | null>(null);
const visible = useMemo(
() => (mode === "thai" ? sortCinemasByName(cinemas) : cinemas),
[cinemas, mode],
);
function handleDrop(event: React.DragEvent<HTMLLIElement>, toSlug: string) {
event.preventDefault();
const fromSlug = dragSlug ?? event.dataTransfer.getData("text/plain");
setOverSlug(null);
setDragSlug(null);
if (!fromSlug || fromSlug === toSlug) return;
onReorder(moveCinema(cinemas, fromSlug, toSlug));
}
return (
<div className="mt-2 flex flex-col gap-2">
<div className="flex items-center gap-1 rounded-lg border border-[#303030] p-1">
<button
type="button"
className={modeButtonClass(mode === "manual")}
aria-pressed={mode === "manual"}
onClick={() => setMode("manual")}
>
ลำดับที่จัดไว้
</button>
<button
type="button"
className={modeButtonClass(mode === "thai")}
aria-pressed={mode === "thai"}
onClick={() => setMode("thai")}
>
<span className="inline-flex items-center justify-center gap-1">
<IconSortAscendingLetters size={13} /> ก-ฮ
</span>
</button>
</div>
{mode === "thai" ? (
<div className="rounded-lg border border-[#303030] bg-[#141414] p-2 text-[11px] leading-[1.7] text-[#999]">
เรียงตามชื่อไทย ก-ฮ · โหมดนี้ลากสลับไม่ได้
<button
type="button"
className="mt-1 block w-full rounded-md border border-[#303030] px-2 py-1 text-[11px] text-[#D47272] transition hover:border-[#A92626]"
onClick={() => {
onReorder(sortCinemasByName(cinemas));
setMode("manual");
}}
>
ใช้ลำดับ ก-ฮ นี้ (แล้วกดบันทึก)
</button>
</div>
) : (
<p className="px-1 text-[11px] leading-[1.6] text-[#777]">
ลากชื่อเพื่อสลับตำแหน่ง หรือกด ↑ ↓ ทีละขั้น
</p>
)}
{dirty ? (
<button
type="button"
disabled={saving}
className="rounded-lg bg-[#8F0808] px-3 py-1.5 text-[11px] font-medium transition hover:bg-[#a30a0a] disabled:opacity-60"
onClick={onSaveOrder}
>
{saving ? "กำลังบันทึก…" : "บันทึกลำดับใหม่"}
</button>
) : null}
<ul className="flex max-h-[62vh] flex-col gap-1 overflow-y-auto pr-1">
{visible.map((item, index) => {
const isSelected = item.slug === selected;
const isDragging = dragSlug === item.slug;
const isOver = overSlug === item.slug && dragSlug !== item.slug;
return (
<li
key={item.slug}
draggable={mode === "manual"}
onDragStart={(event) => {
setDragSlug(item.slug);
event.dataTransfer.effectAllowed = "move";
event.dataTransfer.setData("text/plain", item.slug);
}}
onDragOver={(event) => {
if (mode !== "manual") return;
event.preventDefault();
event.dataTransfer.dropEffect = "move";
setOverSlug(item.slug);
}}
onDragLeave={() => {
setOverSlug((current) => (current === item.slug ? null : current));
}}
onDrop={(event) => handleDrop(event, item.slug)}
onDragEnd={() => {
setDragSlug(null);
setOverSlug(null);
}}
className={`group flex items-center gap-1 rounded-lg pr-1 transition ${
isSelected ? "bg-[#242424]" : "hover:bg-[#1B1B1B]"
} ${isDragging ? "opacity-40" : ""} ${
isOver ? "outline outline-2 outline-offset-[-2px] outline-[#A92626]" : ""
} ${mode === "manual" ? "cursor-grab active:cursor-grabbing" : ""}`}
>
<span
aria-hidden="true"
className={`pl-1 ${
mode === "manual" ? "text-[#555] group-hover:text-[#999]" : "text-transparent"
}`}
>
<IconGripVertical size={14} />
</span>
<button
type="button"
onClick={() => onSelect(item.slug)}
className={`min-w-0 flex-1 py-2 text-left text-sm transition ${
isSelected ? "text-[#D47272]" : "text-[#B3B3B3] hover:text-white"
}`}
>
<span className="block truncate">{item.name_th || item.name}</span>
<span className="block truncate text-[10px] text-[#777]">{item.slug}</span>
</button>
{mode === "manual" ? (
<span className="flex flex-col">
<button
type="button"
className={arrowButtonClass}
aria-label={`เลื่อน ${item.name_th || item.name} ขึ้น`}
disabled={index === 0}
onClick={() => onReorder(shiftCinema(cinemas, item.slug, -1))}
>
<IconArrowUp size={13} />
</button>
<button
type="button"
className={arrowButtonClass}
aria-label={`เลื่อน ${item.name_th || item.name} ลง`}
disabled={index === visible.length - 1}
onClick={() => onReorder(shiftCinema(cinemas, item.slug, 1))}
>
<IconArrowDown size={13} />
</button>
</span>
) : null}
</li>
);
})}
</ul>
</div>
);
}
+64
View File
@@ -0,0 +1,64 @@
import { useEffect, useState } from "react";
/**
* ช่องกรอกหลายค่า คั่นด้วย "," (เช่น หมวด, ช่องทางชำระเงิน)
*
* ทำไมต้องมี draft: ถ้าผูก value เข้ากับ array ตรง ๆ แล้ว split/join ทุกคีย์
* ตัว "," ที่เพิ่งพิมพ์จะถูกตัดทิ้งทันที ( join(", ") ไม่มีตัวคั่นให้ค่าว่าง )
* ทำให้พิมพ์คั่นค่าไม่ได้เลย — draft เก็บข้อความดิบระหว่างพิมพ์ แล้วค่อย
* normalize เป็น ", " เมื่อออกจากช่อง
*/
/** แปลงข้อความ → รายการ (รับ , , 、 และขึ้นบรรทัดใหม่เป็นตัวคั่นด้วย) */
export function parseCommaList(value: string): string[] {
return value
.replace(/[,、]/g, ",")
.split(/[,\n]/)
.map((item) => item.trim())
.filter((item) => item !== "");
}
export function formatList(value: string[]): string {
return value.join(", ");
}
type CommaListInputProps = {
value: string[];
onChangeValue: (next: string[]) => void;
className?: string;
placeholder?: string;
id?: string;
};
export function CommaListInput({
value,
onChangeValue,
className,
placeholder,
id,
}: CommaListInputProps) {
const canonical = formatList(value);
const [draft, setDraft] = useState<string | null>(null);
// ค่าถูกเปลี่ยนจากที่อื่น (เช่น เปลี่ยนโรง / ใช้ JSON / คืนค่า) → ทิ้ง draft
useEffect(() => {
if (draft === null) return;
if (formatList(parseCommaList(draft)) !== canonical) setDraft(null);
}, [canonical, draft]);
return (
<input
id={id}
className={className}
placeholder={placeholder}
value={draft ?? canonical}
spellCheck={false}
onChange={(event) => {
const text = event.target.value;
setDraft(text);
onChangeValue(parseCommaList(text));
}}
onBlur={() => setDraft(null)}
/>
);
}
+113
View File
@@ -0,0 +1,113 @@
import { IconPlus, IconTrash } from "@tabler/icons-react";
import type { ContactChannel } from "@/lib/cinemas";
/**
* แก้ช่องทางติดต่อของการ์ด "สอบถามข้อมูลและจองตั๋ว" ต่อโรง
* แต่ละแถว = label / ค่าที่แสดง / ลิงก์ (ถ้าไม่มีลิงก์ หน้าเว็บแสดงเป็นข้อความธรรมดา)
*/
const SUGGESTED_LABELS = [
"Website",
"Facebook",
"Instagram",
"Line",
"Call",
"อีเมล",
"จองตั๋ว",
];
const smallButtonClass =
"flex min-h-9 items-center gap-1 rounded-lg border border-[#303030] px-2 text-xs text-[#999] transition hover:border-[#A92626] hover:text-[#D47272]";
type Props = {
contacts: ContactChannel[];
onChange: (next: ContactChannel[]) => void;
inputClass: string;
labelClass: string;
};
export function ContactsEditor({ contacts, onChange, inputClass, labelClass }: Props) {
function updateAt(index: number, patch: Partial<ContactChannel>) {
onChange(
contacts.map((item, i) => (i === index ? { ...item, ...patch } : item)),
);
}
return (
<div className="flex flex-col gap-2">
<span className="text-xs text-[#999]">ช่องทางติดต่อ / จองตั๋ว</span>
{contacts.length === 0 ? (
<span className="text-[11px] text-[#777]">
ยังไม่มีช่องทางติดต่อ — หน้าเว็บจะขึ้น “ยังไม่ระบุช่องทางติดต่อ”
</span>
) : null}
{contacts.map((contact, index) => (
<div
key={index}
className="grid gap-2 rounded-lg border border-[#242424] p-2 sm:grid-cols-[130px_minmax(0,1fr)_minmax(0,1fr)_auto]"
>
<label className={labelClass}>
ป้ายชื่อ
<input
className={inputClass}
value={contact.label}
placeholder="Website"
list="contact-label-options"
onChange={(event) => updateAt(index, { label: event.target.value })}
/>
</label>
<label className={labelClass}>
ข้อความที่แสดง
<input
className={inputClass}
value={contact.value}
placeholder="www.housesamyan.com"
onChange={(event) => updateAt(index, { value: event.target.value })}
/>
</label>
<label className={labelClass}>
ลิงก์ (ไม่บังคับ)
<input
className={inputClass}
value={contact.href ?? ""}
placeholder="https://… หรือ tel:+66…"
onChange={(event) =>
updateAt(index, {
href: event.target.value.trim() === "" ? null : event.target.value,
})
}
/>
</label>
<div className="flex items-end">
<button
type="button"
className={smallButtonClass}
aria-label={`ลบช่องทางที่ ${index + 1}`}
onClick={() => onChange(contacts.filter((_, i) => i !== index))}
>
<IconTrash size={14} />
</button>
</div>
</div>
))}
<datalist id="contact-label-options">
{SUGGESTED_LABELS.map((label) => (
<option key={label} value={label} />
))}
</datalist>
<button
type="button"
className={`${smallButtonClass} w-fit`}
onClick={() => onChange([...contacts, { label: "", value: "", href: null }])}
>
<IconPlus size={14} />
เพิ่มช่องทางติดต่อ
</button>
</div>
);
}
+106
View File
@@ -0,0 +1,106 @@
import { IconPlus, IconTrash } from "@tabler/icons-react";
/**
* แก้รายการรูปโรงหนัง (อาร์เรย์ `photos`) — ใส่เป็น URL หรือ path ในโปรเจกต์
* รูปแรกใช้เป็นภาพหลักของแกลเลอรี · ลากสลับลำดับไม่ได้ ใช้ปุ่ม ↑/↓ แทน
*/
type Props = {
photos: string[];
onChange: (next: string[]) => void;
inputClass: string;
labelClass: string;
};
const smallButtonClass =
"flex min-h-9 items-center gap-1 rounded-lg border border-[#303030] px-2 text-xs text-[#999] transition hover:border-[#A92626] hover:text-[#D47272]";
export function PhotosEditor({ photos, onChange, inputClass, labelClass }: Props) {
function updateAt(index: number, value: string) {
onChange(photos.map((item, i) => (i === index ? value : item)));
}
return (
<div className="flex flex-col gap-2">
<span className="text-xs text-[#999]">รูปภาพโรงหนัง</span>
{photos.length === 0 ? (
<span className="text-[11px] text-[#777]">
ยังไม่มีรูป — หน้าเว็บจะแสดงช่องแทน (ภาพที่ 1/2/3)
</span>
) : null}
{photos.map((photo, index) => (
<div
key={index}
className="grid items-center gap-2 rounded-lg border border-[#242424] p-2 sm:grid-cols-[64px_minmax(0,1fr)_auto_auto]"
>
<div className="size-16 overflow-hidden rounded-md border border-[#303030] bg-[#141414]">
{photo ? (
// eslint-disable-next-line jsx-a11y/alt-text
<img
src={photo}
alt=""
className="size-full object-cover"
loading="lazy"
/>
) : null}
</div>
<label className={labelClass}>
{index === 0 ? "รูปหลัก (URL หรือ /images/...)" : `รูปที่ ${index + 1}`}
<input
className={inputClass}
value={photo}
placeholder="/images/hero.png หรือ https://…/photo.jpg"
onChange={(event) => updateAt(index, event.target.value)}
/>
</label>
<div className="flex gap-1">
<button
type="button"
className={smallButtonClass}
aria-label={`เลื่อนรูปที่ ${index + 1} ขึ้น`}
disabled={index === 0}
onClick={() => {
const next = [...photos];
[next[index - 1], next[index]] = [next[index], next[index - 1]];
onChange(next);
}}
>
↑
</button>
<button
type="button"
className={smallButtonClass}
aria-label={`เลื่อนรูปที่ ${index + 1} ลง`}
disabled={index === photos.length - 1}
onClick={() => {
const next = [...photos];
[next[index + 1], next[index]] = [next[index], next[index + 1]];
onChange(next);
}}
>
↓
</button>
</div>
<button
type="button"
className={smallButtonClass}
aria-label={`ลบรูปที่ ${index + 1}`}
onClick={() => onChange(photos.filter((_, i) => i !== index))}
>
<IconTrash size={14} />
</button>
</div>
))}
<button
type="button"
className={`${smallButtonClass} w-fit`}
onClick={() => onChange([...photos, ""])}
>
<IconPlus size={14} />
เพิ่มรูป
</button>
</div>
);
}
+120
View File
@@ -0,0 +1,120 @@
import { useEffect, useRef, useState } from "react";
/**
* ช่องแก้ slug (ใช้ใน URL) ของโรงหนัง
*
* ทำไมของเดิม "แก้ไม่ได้": อินพุตผูกกับ `cinema.slug` ตรง ๆ และแปลงค่าทุกคีย์
* (`replace(/[^a-z0-9-]/g, "-")`) — พอพิมพ์ตัวอักษรไทย/เว้นวรรค มันกลายเป็น "-"
* ทันที และถ้าลบจนว่าง ค่าก็ว่างทันที ทำให้ดูเหมือนพิมพ์อะไรไม่ได้เลย
*
* ที่นี่เก็บ "ข้อความดิบ" ระหว่างพิมพ์ (draft) แล้วค่อยจัดรูปตอนออกจากช่อง (blur)
* slug ว่างหรือซ้ำกับโรงอื่นจะไม่ถูกบันทึก — คืนค่าเดิมให้
*/
const SLUG_PATTERN = /^[a-z0-9]+(?:-[a-z0-9]+)*$/;
/** จัดรูป slug: ตัวเล็ก, ช่องว่าง/ขีดซ้ำ → ขีดเดียว, ตัดอักขระที่ไม่ใช่ a-z0-9- */
export function normalizeSlug(value: string): string {
return value
.trim()
.toLowerCase()
.replace(/[\s_]+/g, "-")
.replace(/[^a-z0-9-]/g, "")
.replace(/-{2,}/g, "-")
.replace(/^-+|-+$/g, "");
}
/**
* แนะนำ slug จากชื่อโรงหนังภาษาอังกฤษ
* "HOUSE CINEMA SAMYAN" → "house-cinema-samyan" · "." และอักขระอื่นถูกตัดให้เอง
*/
export function suggestSlug(name: string): string {
return normalizeSlug(
name
.normalize("NFKD")
.replace(/[\u0300-\u036f]/g, "")
.replace(/&/g, " and ")
.replace(/['’]/g, ""),
);
}
/** เหตุผลที่ slug ใช้ไม่ได้ (null = ใช้ได้) */
export function slugProblem(
slug: string,
options: { others: string[]; self?: string },
): string | null {
if (slug === "") return "slug ว่างไม่ได้";
if (!SLUG_PATTERN.test(slug)) return "ใช้ได้เฉพาะ a-z, 0-9 และ - (ห้ามขีดติดกัน/หัวท้าย)";
if (options.others.some((other) => other === slug && other !== options.self)) {
return "slug นี้มีโรงอื่นใช้อยู่";
}
return null;
}
type SlugInputProps = {
value: string;
/** slug ของโรงอื่นทั้งหมด ใช้ตรวจซ้ำ */
others: string[];
onChange: (slug: string) => void;
className?: string;
};
export function SlugInput({ value, others, onChange, className }: SlugInputProps) {
const [draft, setDraft] = useState<string | null>(null);
const [notice, setNotice] = useState<string | null>(null);
const lastValue = useRef(value);
// ค่าถูกเปลี่ยนจากภายนอก (สลับโรง / ใช้ JSON / คืนค่า) → ทิ้ง draft
// เทียบกับค่าก่อนหน้า ไม่ใช่เทียบกับ draft เพราะระหว่างพิมพ์ value ยังไม่เปลี่ยน
useEffect(() => {
if (lastValue.current === value) return;
lastValue.current = value;
setDraft(null);
}, [value]);
const shown = draft ?? value;
const preview = normalizeSlug(shown);
const problem = slugProblem(preview, { others, self: value });
const dirty = preview !== value;
return (
<div className="flex flex-col gap-1">
<input
className={className}
value={shown}
spellCheck={false}
placeholder="house-cinema-samyan"
onChange={(event) => {
setDraft(event.target.value);
setNotice(null);
}}
onBlur={() => {
const next = normalizeSlug(draft ?? value);
if (next !== "" && slugProblem(next, { others, self: value }) === null) {
if (next !== value) {
onChange(next);
setNotice("เปลี่ยน slug แล้ว — ลิงก์เดิมของโรงนี้จะใช้ไม่ได้ (ต้องกดบันทึก)");
}
} else if (next !== value) {
setNotice("slug ไม่ถูกบันทึก (ว่าง/ซ้ำ/รูปแบบไม่ถูก) — คงค่าเดิมไว้");
}
setDraft(null);
}}
/>
<div className="flex flex-wrap items-center gap-2 text-[11px]">
<code className="text-[#777]">/cinema/{preview || "…"}</code>
{problem && dirty ? (
<span className="text-[#D47272]">{problem}</span>
) : null}
{!problem && dirty ? (
<span className="text-[#B3B3B3]">กด Tab/คลิกออกเพื่อยืนยัน slug ใหม่</span>
) : null}
</div>
{notice ? (
<span className="text-[11px] text-[#D47272]">{notice}</span>
) : null}
</div>
);
}
+116
View File
@@ -0,0 +1,116 @@
import { IconPlus, IconTrash } from "@tabler/icons-react";
import type { TransportMode } from "@/lib/cinemas";
import { DEFAULT_LOCALE, MESSAGES } from "@/lib/i18n/messages";
/**
* แก้ไขข้อมูลการเดินทางของโรงหนัง (รถยนต์ส่วนตัว / รถไฟฟ้า / รถประจำทาง)
* เรียงตามลำดับในอาร์เรย์ transport ของ content.json
*/
const ADMIN_MESSAGES = MESSAGES[DEFAULT_LOCALE];
const ICON_OPTIONS: Array<TransportMode["icon_name"]> = [
"private_car",
"metro",
"bus",
];
type TransportEditorProps = {
value: TransportMode[];
onChange: (next: TransportMode[]) => void;
inputClass: string;
labelClass: string;
};
const smallButtonClass =
"flex min-h-9 items-center gap-1 rounded-lg border border-[#303030] px-2 text-xs text-[#999] transition hover:border-[#A92626] hover:text-[#D47272]";
export function TransportEditor({
value,
onChange,
inputClass,
labelClass,
}: TransportEditorProps) {
function updateAt(index: number, patch: Partial<TransportMode>) {
onChange(value.map((item, i) => (i === index ? { ...item, ...patch } : item)));
}
return (
<div className="flex flex-col gap-2">
<span className="text-xs text-[#999]">การเดินทาง</span>
{value.length === 0 ? (
<span className="text-[11px] text-[#777]">
ยังไม่มีข้อมูล — หน้าเว็บจะซ่อนบล็อกการเดินทาง
</span>
) : null}
{value.map((route, index) => (
<div
key={index}
className="grid gap-2 rounded-lg border border-[#242424] p-2 sm:grid-cols-[130px_minmax(0,1fr)_minmax(0,1fr)_auto]"
>
<label className={labelClass}>
วิธีเดินทาง
<select
className={inputClass}
value={route.icon_name}
onChange={(event) =>
updateAt(index, {
icon_name: event.target.value as TransportMode["icon_name"],
})
}
>
{ICON_OPTIONS.map((icon) => (
<option key={icon} value={icon}>
{ADMIN_MESSAGES.transport[icon]}
</option>
))}
</select>
</label>
<label className={labelClass}>
รายละเอียด (TH)
<input
className={inputClass}
value={route.value}
placeholder="MRT สถานีสามย่าน"
onChange={(event) => updateAt(index, { value: event.target.value })}
/>
</label>
<label className={labelClass}>
รายละเอียด (EN)
<input
className={inputClass}
value={route.value_en ?? ""}
placeholder="MRT Sam Yan station"
onChange={(event) =>
updateAt(index, { value_en: event.target.value })
}
/>
</label>
<div className="flex items-end">
<button
type="button"
className={smallButtonClass}
aria-label={`ลบวิธีเดินทางลำดับที่ ${index + 1}`}
onClick={() => onChange(value.filter((_, i) => i !== index))}
>
<IconTrash size={14} />
</button>
</div>
</div>
))}
<button
type="button"
className={`${smallButtonClass} w-fit`}
onClick={() =>
onChange([...value, { icon_name: "bus", value: "", value_en: "" }])
}
>
<IconPlus size={14} />
เพิ่มวิธีเดินทาง
</button>
</div>
);
}
@@ -0,0 +1,83 @@
import { describe, expect, it } from "vitest";
import { parseCommaList, formatList } from "@/components/admin/CommaListInput";
import { normalizeSlug, slugProblem, suggestSlug } from "@/components/admin/SlugInput";
/**
* สเปกของตัวช่วยในหลังบ้าน — กันบั๊กที่เคยเจอจริง
* 1) ช่องคั่นด้วย "," ที่กลืนตัวคั่นระหว่างพิมพ์
* 2) slug ที่พิมพ์ไทย/เว้นวรรคแล้วหาย
*/
describe("parseCommaList", () => {
it("แยกด้วย , และตัดช่องว่างหัวท้าย", () => {
expect(parseCommaList("อาร์ตเฮาส์, สารคดี")).toEqual(["อาร์ตเฮาส์", "สารคดี"]);
});
it("ทิ้งค่าว่าง และรับตัวคั่นเต็มความกว้าง/ขึ้นบรรทัดใหม่", () => {
expect(parseCommaList("เงินสด, , โอน")).toEqual(["เงินสด", "โอน"]);
expect(parseCommaList("เงินสด,โอน")).toEqual(["เงินสด", "โอน"]);
expect(parseCommaList("ก\nข")).toEqual(["ก", "ข"]);
});
it("ค่าว่างได้อาร์เรย์ว่าง", () => {
expect(parseCommaList(" ")).toEqual([]);
});
});
describe("formatList", () => {
it("ต่อด้วย ', ' เสมอ", () => {
expect(formatList(["a", "b"])).toBe("a, b");
expect(formatList([])).toBe("");
});
});
describe("normalizeSlug", () => {
it("ตัวเล็ก + ช่องว่างเป็นขีด", () => {
expect(normalizeSlug("Mecani Cinema")).toBe("mecani-cinema");
});
it("ตัดอักขระที่ไม่ใช่ a-z0-9- และยุบขีดซ้ำ", () => {
expect(normalizeSlug(" HOUSE & Co. ")).toBe("house-co");
expect(normalizeSlug("a__b")).toBe("a-b");
expect(normalizeSlug("--a--b--")).toBe("a-b");
});
it("ภาษาไทยล้วนได้ค่าว่าง (ไม่ยอมให้บันทึก พร้อมเหตุผล)", () => {
expect(normalizeSlug("เมคานี ใหม่")).toBe("");
expect(slugProblem("", { others: [] })).toBe("slug ว่างไม่ได้");
});
});
describe("suggestSlug", () => {
it("แปลงชื่ออังกฤษเป็น slug", () => {
expect(suggestSlug("HOUSE CINEMA SAMYAN")).toBe("house-cinema-samyan");
expect(suggestSlug("MECANI")).toBe("mecani");
});
it("& กลายเป็น 'and' และตัด apostrophe", () => {
expect(suggestSlug("Doc Club & Friends")).toBe("doc-club-and-friends");
expect(suggestSlug("O'Brien Cinema")).toBe("obrien-cinema");
});
it("ตัดเสียง accent", () => {
expect(suggestSlug("Café Lumière")).toBe("cafe-lumiere");
});
});
describe("slugProblem", () => {
it("ซ้ำกับโรงอื่น = ใช้ไม่ได้", () => {
expect(
slugProblem("mecani", { others: ["mecani", "loprama"], self: "loprama" }),
).toBe("slug นี้มีโรงอื่นใช้อยู่");
});
it("ซ้ำกับตัวเอง = ผ่าน (ตอนแก้ฟิลด์อื่น)", () => {
expect(slugProblem("mecani", { others: ["mecani"], self: "mecani" })).toBeNull();
});
it("รูปแบบผิด เช่นขีดหัว/ท้าย = ใช้ไม่ได้", () => {
expect(slugProblem("-mecani", { others: [] })).toContain("a-z");
expect(slugProblem("mecani--x", { others: [] })).toContain("a-z");
});
});
+26
View File
@@ -0,0 +1,26 @@
import { Link } from "react-router";
import { SiteShell } from "@/components/site/SiteShell";
import { useI18n } from "@/lib/i18n";
import { COLORS } from "@/lib/design-tokens";
/** หน้า fallback เมื่อ slug ไม่ตรงกับโรงหนังที่มีอยู่ */
export function CinemaNotFound() {
const { messages } = useI18n();
return (
<SiteShell variant="detail">
<main className="relative z-10 mx-auto flex max-w-[1440px] flex-col items-center gap-6 px-5 py-32 text-center md:px-[108px]">
<h1 className="text-3xl font-bold">{messages.notFound.title}</h1>
<p className="text-[#B3B3B3]">{messages.notFound.text}</p>
<Link
to="/"
className="rounded-lg px-6 py-2 font-medium"
style={{ background: COLORS.brand }}
>
{messages.notFound.cta}
</Link>
</main>
</SiteShell>
);
}
+60
View File
@@ -0,0 +1,60 @@
import { IconMap, IconMapPin } from "@tabler/icons-react";
import {
cinemaDescription,
cinemaLocationLabel,
cinemaName,
type Cinema,
} from "@/lib/cinemas";
import { useI18n } from "@/lib/i18n";
import { COLORS } from "@/lib/design-tokens";
/** หัวโรงหนัง: ป้ายประเภท + ชื่อ + ที่ตั้ง + ปุ่มแผนที่ + คำอธิบาย */
export function CinemaSummary({ cinema }: { cinema: Cinema }) {
const { locale, messages } = useI18n();
const locationLabel = cinemaLocationLabel(cinema, locale);
const description = cinemaDescription(cinema, locale);
return (
<div className="flex flex-col gap-6">
<div className="flex flex-col gap-4">
<div className="flex flex-wrap gap-2">
{cinema.tags.map((tag) => (
<span
key={tag}
className="rounded-[18px] border border-[#A92626] px-4 py-2 text-sm text-[#D47272]"
style={{ background: COLORS.pillGradient }}
>
{messages.tags[tag] ?? tag}
</span>
))}
</div>
<h1 className="text-[40px] font-bold leading-[1.3]">
{cinemaName(cinema, locale)}
</h1>
</div>
<div className="flex flex-wrap items-center justify-between gap-4">
<div className="flex items-center gap-2 text-lg">
<IconMapPin size={24} className="shrink-0" />
{locationLabel || messages.card.locationFallback}
</div>
{cinema.map_url ? (
<a
href={cinema.map_url}
target="_blank"
rel="noreferrer"
className="flex w-[200px] items-center justify-center gap-2 rounded-lg border border-white px-4 py-2 text-lg font-medium"
>
{messages.detail.openMap}
<IconMap size={24} />
</a>
) : null}
</div>
{description ? (
<p className="text-xl leading-[1.3]">{description}</p>
) : null}
</div>
);
}
+73
View File
@@ -0,0 +1,73 @@
import { IconCircleCheck, IconExternalLink } from "@tabler/icons-react";
import type { Cinema, ContactChannel } from "@/lib/cinemas";
import { useI18n } from "@/lib/i18n";
import { translate } from "@/lib/i18n/messages";
import { COLORS } from "@/lib/design-tokens";
function isExternal(href: string | null): boolean {
return href !== null && href.startsWith("http");
}
function ContactRow({ channel }: { channel: ContactChannel }) {
return (
<div className="flex flex-col gap-2">
<span className="text-sm text-[#999]">{channel.label}</span>
<a
href={channel.href ?? undefined}
target={isExternal(channel.href) ? "_blank" : undefined}
rel="noreferrer"
className="flex items-center justify-between"
>
<span>{channel.value}</span>
<IconExternalLink size={16} />
</a>
</div>
);
}
/** กล่องติดต่อ/จองตั๋ว — แต่ละส่วนซ่อนได้ถ้ายังไม่มีข้อมูล */
export function ContactPanel({ cinema }: { cinema: Cinema }) {
const { messages } = useI18n();
return (
<aside
className="flex flex-col justify-between gap-6 rounded-xl p-6"
style={{ border: `1px solid ${COLORS.border}` }}
>
<div className="flex flex-col gap-4">
<h2 className="text-2xl font-semibold leading-[1.3]">
{(cinema.contact_heading?.trim() || messages.detail.contactTitle)}
</h2>
{cinema.contacts.length === 0 ? (
<p className="text-sm text-[#999]">{messages.detail.contactsFallback}</p>
) : (
cinema.contacts.map((channel) => (
<ContactRow key={channel.label} channel={channel} />
))
)}
<div className="flex flex-col gap-3">
<span className="text-sm text-[#999]">
{messages.detail.paymentMethods}
</span>
{cinema.payments.length === 0 ? (
<span className="text-sm text-[#999]">
{messages.detail.paymentsFallback}
</span>
) : (
<div className="flex flex-wrap items-center gap-6">
{cinema.payments.map((payment) => (
<span key={payment} className="flex items-center gap-1 text-sm">
<IconCircleCheck size={16} />
{translate(messages.payments, payment)}
</span>
))}
</div>
)}
</div>
</div>
</aside>
);
}
@@ -0,0 +1,77 @@
import {
IconBook,
IconBriefcase,
IconCoffee,
IconPlant2,
IconShoppingBag,
IconSofa,
IconTicket,
IconToolsKitchen2,
type Icon as TablerIcon,
} from "@tabler/icons-react";
import { LocationPanel } from "@/components/cinema/LocationPanel";
import { cinemaFacilities, type Cinema } from "@/lib/cinemas";
import { useI18n } from "@/lib/i18n";
import type { FacilityKey } from "@/lib/i18n/messages";
import { COLORS } from "@/lib/design-tokens";
const FACILITY_ICONS: Record<FacilityKey, TablerIcon> = {
seating: IconSofa,
ticket: IconTicket,
restaurant: IconToolsKitchen2,
cafe: IconCoffee,
garden: IconPlant2,
bookstore: IconBook,
colearning: IconBriefcase,
other: IconShoppingBag,
};
/** สิ่งอำนวยความสะดวก (ซ้าย) + ที่ตั้ง (ขวา) ตาม layout ใน Figma */
export function FacilitiesSection({ cinema }: { cinema: Cinema }) {
const { locale, messages } = useI18n();
const facilities = cinemaFacilities(cinema);
return (
<section className="grid gap-10 lg:grid-cols-[minmax(0,749px)_minmax(0,384px)] lg:justify-between">
<div className="flex flex-col gap-8">
<h2 className="text-2xl font-semibold leading-[1.3]">
{messages.detail.facilities}
</h2>
{facilities.length > 0 ? (
<div className="grid grid-cols-2 gap-x-4 gap-y-10 sm:grid-cols-4">
{facilities.map((key) => {
const Icon = FACILITY_ICONS[key];
const base = messages.facilities[key];
const custom = cinema.facility_details?.[key];
const title = custom?.label?.trim() || base.title;
// คำอธิบายแสดงเฉพาะที่กรอกไว้รายโรง (ค่าเริ่มต้นใช้เป็น placeholder ในหลังบ้าน)
const sub =
(locale === "en" ? custom?.sub_en : custom?.sub_th)?.trim() ?? "";
return (
<div key={key} className="flex flex-col items-center gap-3">
<div
className="flex size-[72px] items-center justify-center rounded-full"
style={{ background: COLORS.glowSoft }}
>
<Icon size={40} stroke={1.5} />
</div>
<div className="text-center">
<div className="font-medium">{title}</div>
{sub ? (
<div className="mt-1 text-sm text-[#B3B3B3]">{sub}</div>
) : null}
</div>
</div>
);
})}
</div>
) : (
<p className="text-sm text-[#777]">{messages.detail.noData}</p>
)}
</div>
<LocationPanel cinema={cinema} />
</section>
);
}
+97
View File
@@ -0,0 +1,97 @@
import { IconChevronLeft, IconChevronRight } from "@tabler/icons-react";
import type { ReactNode } from "react";
import { Logo } from "@/components/site/Logo";
import { splitGallery } from "@/lib/gallery";
import { useI18n } from "@/lib/i18n";
type GalleryProps = {
photos: string[];
cinemaName: string;
};
type GallerySlotProps = {
photo: string | null;
alt: string;
/** เนื้อหาที่แสดงเมื่อยังไม่มีรูป — ใช้โลโก้ AlterFlixHub แทนข้อความ */
placeholder: ReactNode;
className: string;
};
function GallerySlot({ photo, alt, placeholder, className }: GallerySlotProps) {
if (!photo) {
return (
<div
className={`flex items-center justify-center bg-[#242424] text-sm text-[#999] ${className}`}
>
{placeholder}
</div>
);
}
return (
<img
src={photo}
alt={alt}
className={`bg-[#242424] object-cover ${className}`}
/>
);
}
/** แกลเลอรีภาพโรงหนัง — ป้าย "+N" คำนวณจากจำนวนรูปจริงในข้อมูล */
export function Gallery({ photos, cinemaName }: GalleryProps) {
const { messages } = useI18n();
const { main, thumbs, remaining } = splitGallery(photos);
const [firstThumb = null, secondThumb = null] = thumbs;
return (
<section className="grid gap-6 lg:grid-cols-[minmax(0,807px)_minmax(0,387px)]">
<div className="relative overflow-hidden rounded-xl">
<GallerySlot
photo={main}
alt={`${messages.gallery.main} — ${cinemaName}`}
placeholder={<Logo size="md" />}
className="aspect-[269/202] w-full lg:aspect-auto lg:h-[606px]"
/>
<button
type="button"
aria-label={messages.gallery.previous}
className="absolute left-6 top-1/2 flex size-10 -translate-y-1/2 items-center justify-center rounded-full bg-black/50"
>
<IconChevronLeft size={24} />
</button>
<button
type="button"
aria-label={messages.gallery.next}
className="absolute right-6 top-1/2 flex size-10 -translate-y-1/2 items-center justify-center rounded-full bg-black/50"
>
<IconChevronRight size={24} />
</button>
</div>
<div className="grid grid-cols-2 gap-6 lg:grid-cols-1 lg:grid-rows-2">
<div className="overflow-hidden rounded-xl">
<GallerySlot
photo={firstThumb}
alt={`${messages.gallery.second} — ${cinemaName}`}
placeholder={<Logo size="sm" />}
className="aspect-[387/290] w-full"
/>
</div>
<div className="relative overflow-hidden rounded-xl">
<GallerySlot
photo={secondThumb}
alt={`${messages.gallery.third} — ${cinemaName}`}
placeholder={<Logo size="sm" />}
className="aspect-[387/290] w-full"
/>
{remaining > 0 ? (
<div className="absolute bottom-2.5 right-2.5 flex size-[60px] items-center justify-center rounded-lg bg-black/80 text-lg font-medium">
{messages.gallery.more(remaining)}
</div>
) : null}
</div>
</div>
</section>
);
}
+93
View File
@@ -0,0 +1,93 @@
import { IconMap } from "@tabler/icons-react";
import { COLORS } from "@/lib/design-tokens";
import { cinemaAddressLines, cinemaName, type Cinema } from "@/lib/cinemas";
import { useI18n } from "@/lib/i18n";
import { mapEmbedUrl, mapOpenUrl } from "@/lib/map-embed";
/**
* การ์ดที่ตั้ง + แผนที่
* แผนที่ดึงจากลิงก์ Google Maps ของโรง ถ้าไม่มีจึงใช้พิกัดที่กรอกในหลังบ้าน
* ถ้าไม่มีทั้งสองอย่างแสดง "ไม่มีข้อมูล"
*/
export function LocationPanel({ cinema }: { cinema: Cinema }) {
const { locale, messages } = useI18n();
const addressLines = cinemaAddressLines(cinema, locale);
const embedUrl = mapEmbedUrl(cinema, locale);
const openUrl = mapOpenUrl(cinema);
return (
<aside
className="flex flex-col gap-6 self-start rounded-xl p-6"
style={{ border: `1px solid ${COLORS.border}` }}
>
<div className="flex flex-col gap-4">
<div className="flex items-center justify-between gap-3">
<h2 className="text-2xl font-semibold leading-[1.3]">
{messages.detail.location}
</h2>
{openUrl ? (
<a
href={openUrl}
target="_blank"
rel="noreferrer"
className="inline-flex items-center gap-1 text-sm text-[#D47272] transition hover:text-white"
>
<IconMap size={16} />
{messages.detail.openMap}
</a>
) : null}
</div>
{embedUrl ? (
<div
className="relative h-[183px] overflow-hidden rounded-xl"
style={{
border: `1px solid ${COLORS.border}`,
background: COLORS.surfaceMuted,
}}
>
{/* ลายตารางใต้แผนที่ — กันช่องว่างขาวตอน iframe ยังโหลดไม่เสร็จ */}
<div
aria-hidden="true"
className="pointer-events-none absolute inset-0"
style={{
backgroundImage:
"linear-gradient(rgba(255,255,255,0.05) 1px, transparent 1px), linear-gradient(90deg, rgba(255,255,255,0.05) 1px, transparent 1px)",
backgroundSize: "24px 24px",
}}
/>
<iframe
title={`${messages.detail.location} — ${cinemaName(cinema, locale)}`}
src={embedUrl}
loading="lazy"
referrerPolicy="no-referrer-when-downgrade"
allowFullScreen
className="relative size-full border-0"
/>
</div>
) : (
<div
className="flex h-[183px] items-center justify-center rounded-xl text-sm text-[#777]"
style={{
border: `1px dashed ${COLORS.border}`,
background: COLORS.surfaceMuted,
}}
>
{messages.detail.noData}
</div>
)}
</div>
<p className="text-sm leading-[1.3] text-[#999]">
{addressLines.length > 0
? addressLines.map((line) => (
<span key={line} className="block">
{line}
</span>
))
: messages.detail.addressFallback}
</p>
</aside>
);
}
+49
View File
@@ -0,0 +1,49 @@
import {
IconBus,
IconCar,
IconTrain,
type Icon as TablerIcon,
} from "@tabler/icons-react";
import { transportValue, type TransportMode } from "@/lib/cinemas";
import { useI18n } from "@/lib/i18n";
import { COLORS } from "@/lib/design-tokens";
const TRANSPORT_ICONS: Record<TransportMode["icon_name"], TablerIcon> = {
private_car: IconCar,
metro: IconTrain,
bus: IconBus,
};
/** วิธีเดินทางมาถึงโรงหนัง — ซ่อนทั้งบล็อกถ้ายังไม่มีข้อมูล */
export function TransportList({ transport }: { transport: TransportMode[] }) {
const { locale, messages } = useI18n();
// แถวที่ยังไม่ได้กรอกรายละเอียด (เพิ่มจากหลังบ้านแล้วเว้นว่าง) ไม่ต้องแสดง
const routes = transport.filter((route) => route.value.trim() !== "");
if (routes.length === 0) return null;
return (
<div className="flex flex-col">
{routes.map((route, index) => {
const Icon = TRANSPORT_ICONS[route.icon_name];
const isLast = index === routes.length - 1;
return (
<div
key={`${route.icon_name}-${index}`}
className="flex flex-col justify-between gap-1 py-2.5 sm:min-h-10 sm:flex-row sm:gap-4"
style={{
borderBottom: isLast ? undefined : `1px solid ${COLORS.border}`,
}}
>
<div className="flex items-center gap-2 font-medium">
<Icon size={20} />
{messages.transport[route.icon_name]}
</div>
<div className="sm:text-right">{transportValue(route, locale)}</div>
</div>
);
})}
</div>
);
}
+97
View File
@@ -0,0 +1,97 @@
import { IconCircleCheck, IconMapPin, IconSearch } from "@tabler/icons-react";
import type { NearMeStatus } from "@/hooks/use-near-me";
import { useI18n } from "@/lib/i18n";
type HeroSectionProps = {
query: string;
onQueryChange: (query: string) => void;
nearMeStatus: NearMeStatus;
onRequestLocation: () => void;
};
/** ข้อความสถานะของปุ่ม "ใกล้ฉัน" — แสดงเฉพาะตอนกำลังหา/ผิดพลาด/พร้อมใช้ */
function statusMessage(status: NearMeStatus, messages: ReturnType<typeof useI18n>["messages"]) {
switch (status) {
case "locating":
return messages.search.locating;
case "denied":
return messages.search.denied;
case "unsupported":
return messages.search.unsupported;
case "error":
return messages.search.error;
case "ready":
return messages.search.sortedByDistance;
default:
return null;
}
}
/** ฮีโร่หน้าแรก: หัวข้อ + ช่องค้นหา (ค้นทันทีขณะพิมพ์) + ปุ่มหาตำแหน่ง */
export function HeroSection({
query,
onQueryChange,
nearMeStatus,
onRequestLocation,
}: HeroSectionProps) {
const { messages } = useI18n();
const status = statusMessage(nearMeStatus, messages);
const isReady = nearMeStatus === "ready";
return (
<section className="mx-auto flex max-w-[1016px] flex-col items-center gap-10 pt-24 md:pt-[167px]">
<div className="flex max-w-[745px] flex-col items-center gap-4 text-center">
<h1 className="text-4xl font-bold leading-[1.3] md:text-[56px]">
{messages.hero.titlePrefix}
<span className="text-[#A92626]">{messages.hero.titleHighlight}</span>
{messages.hero.titleSuffix}
</h1>
<p className="text-base md:text-xl">{messages.hero.subtitle}</p>
</div>
<div className="w-full rounded-2xl border border-[#303030] bg-[#1B1B1B]/80 px-4 py-6 backdrop-blur-[32px] md:px-10">
<div className="flex h-14 items-center gap-3 rounded-lg border border-[#1B1B1B] bg-[#1F1F1F] px-5">
<IconSearch size={16} className="shrink-0 text-[#999]" />
<input
value={query}
onChange={(event) => onQueryChange(event.target.value)}
placeholder={messages.search.placeholder}
aria-label={messages.search.placeholder}
className="min-w-0 flex-1 bg-transparent text-sm text-white outline-none placeholder:text-[#454545]"
/>
<button
type="button"
onClick={onRequestLocation}
disabled={nearMeStatus === "locating"}
aria-label={messages.search.nearMe}
className={`hidden items-center gap-2 border-l border-[#999] px-4 text-sm transition disabled:opacity-60 sm:flex ${
isReady ? "text-[#D47272]" : "text-[#999] hover:text-white"
}`}
>
{isReady ? <IconCircleCheck size={16} /> : <IconMapPin size={16} />}
{messages.search.nearMe}
</button>
<button
type="button"
className="h-8 rounded-lg border border-[#8F0808] bg-[#8F0808] px-6 text-sm font-medium transition hover:bg-[#a30a0a]"
>
{messages.search.submit}
</button>
</div>
{status ? (
<p
role="status"
aria-live="polite"
className={`px-1 pt-3 text-xs ${
nearMeStatus === "ready" ? "text-[#B3B3B3]" : "text-[#D47272]"
}`}
>
{status}
</p>
) : null}
</div>
</section>
);
}
+28
View File
@@ -0,0 +1,28 @@
import { HeaderActionsProvider } from "@agent-native/toolkit/app-shell";
interface LayoutProps {
children: React.ReactNode;
}
/**
* Clean Agent-Native app shell: a single full-height canvas with no chat or
* agent UI mounted by default. The app already satisfies the Agent-Native
* contract (data in SQL, actions as the source of truth, application state for
* navigation, real-time sync) — the agent rail and chat are opt-in surfaces.
*
* To add the persistent agent rail when the user asks for it, wrap {children}
* in `AgentSidebar` from "@agent-native/core/client/agent-chat"
* (position="right", a stable storageKey, browserTabId={TAB_ID} from
* "@/lib/tab-id"). See the `agent-native-toolkit` skill for the full pattern.
*/
export function Layout({ children }: LayoutProps) {
return (
<HeaderActionsProvider>
<div className="flex h-screen w-full flex-col overflow-hidden bg-background text-foreground">
<main className="agent-native-app-main min-w-0 flex-1 overflow-y-auto overscroll-contain">
{children}
</main>
</div>
</HeaderActionsProvider>
);
}
+98
View File
@@ -0,0 +1,98 @@
import {
IconArrowRight,
IconBuildingCommunity,
IconMapPin,
} from "@tabler/icons-react";
import { Link } from "react-router";
import {
CARD_GRADIENTS,
cinemaCategoryLabel,
cinemaLocationLabel,
cinemaName,
type Cinema,
} from "@/lib/cinemas";
import { formatDistance } from "@/lib/geo";
import { trackEvent } from "@/lib/analytics-client";
import { useNearMe } from "@/hooks/use-near-me";
import { useI18n } from "@/lib/i18n";
type CinemaCardProps = {
cinema: Cinema;
/** ลำดับการ์ด ใช้เลือก gradient ให้สลับสีสม่ำเสมอ */
index?: number;
/** ที่มาของการ์ด ใช้บันทึกสถิติการคลิก */
source?: string;
/** คำค้นปัจจุบัน (แนบไปกับการคลิกเพื่อวัด CTR ของคำค้น) */
searchQuery?: string;
};
export function CinemaCard({
cinema,
index = 0,
source = "list",
searchQuery,
}: CinemaCardProps) {
const { locale, messages } = useI18n();
const { distances } = useNearMe();
const gradient = CARD_GRADIENTS[index % CARD_GRADIENTS.length];
// รูปแรก = ปกการ์ด (ถ้าไม่มีรูป ใช้ gradient เดิมเป็นพื้นหลัง)
const cover = cinema.photos.find((photo) => photo.trim() !== "");
const distanceLabel = formatDistance(
distances[cinema.slug],
messages.card.distanceFallback,
);
return (
<article
className={`relative flex aspect-[3/4] flex-col justify-end overflow-hidden rounded-[20px] bg-gradient-to-br p-2 lg:aspect-auto lg:h-[308px] ${gradient}`}
>
{cover ? (
<>
<img
src={cover}
alt=""
aria-hidden="true"
loading="lazy"
className="absolute inset-0 size-full object-cover"
/>
{/* ไล่เงาเพื่อให้ตัวอักษรบนการ์ดอ่านได้ */}
<div
aria-hidden="true"
className="absolute inset-0 bg-gradient-to-t from-[#0D0D0D]/95 via-[#0D0D0D]/35 to-transparent"
/>
</>
) : null}
<div className="relative flex flex-col gap-1.5 rounded-2xl border border-white/10 bg-[#1B1B1B]/80 p-3 backdrop-blur-xl">
<span className="text-[10px] text-[#B3B3B3]">{distanceLabel}</span>
<h3 className="text-sm font-semibold">{cinemaName(cinema, locale)}</h3>
<p className="flex items-center gap-1.5 text-xs text-[#B3B3B3]">
<IconMapPin size={12} />
{cinemaLocationLabel(cinema, locale) || messages.card.locationFallback}
</p>
<p className="flex items-center gap-1.5 text-xs text-[#B3B3B3]">
<IconBuildingCommunity size={12} />
{cinemaCategoryLabel(cinema, messages) ||
messages.card.categoryFallback}
</p>
<Link
to={`/cinema/${cinema.slug}`}
onClick={() =>
trackEvent({
type: "cinema_select",
slug: cinema.slug,
source,
query: searchQuery,
position: index + 1,
locale,
})
}
className="mt-3 flex items-center justify-end gap-2 text-xs font-medium"
>
{messages.card.seeDetail} <IconArrowRight size={12} />
</Link>
</div>
</article>
);
}
+66
View File
@@ -0,0 +1,66 @@
import { CinemaCard } from "@/components/site/CinemaCard";
import type { Cinema, CinemaCategory } from "@/lib/cinemas";
import { useI18n } from "@/lib/i18n";
/** กริดการ์ดโรงหนัง — ใช้ทั้งหน้าแรกและส่วน "โรงหนังอิสระอื่นๆ" */
export function CinemaGrid({
cinemas,
source = "list",
searchQuery,
}: {
cinemas: Cinema[];
source?: string;
searchQuery?: string;
}) {
return (
<div className="grid grid-cols-1 gap-4 sm:grid-cols-2 lg:grid-cols-4">
{cinemas.map((cinema, index) => (
<CinemaCard
key={cinema.slug}
cinema={cinema}
index={index}
source={source}
searchQuery={searchQuery}
/>
))}
</div>
);
}
type CategoryFilterProps = {
/** เก็บคีย์หมวดเป็นภาษาไทยเสมอ เพื่อใช้กรองข้อมูลได้ทุกภาษา */
active: CinemaCategory;
categories: readonly CinemaCategory[];
onChange: (category: CinemaCategory) => void;
};
export function CategoryFilter({
active,
categories,
onChange,
}: CategoryFilterProps) {
const { messages } = useI18n();
return (
<div className="flex flex-wrap gap-2">
{categories.map((category) => {
const isActive = category === active;
return (
<button
key={category}
type="button"
onClick={() => onChange(category)}
aria-pressed={isActive}
className={
isActive
? "rounded-[18px] border border-[#A92626] bg-gradient-to-b from-[#8F0808]/30 to-[#1B1B1B]/0 px-4 py-2 text-sm text-[#D47272]"
: "rounded-[18px] border border-[#303030] bg-[#242424] px-4 py-2 text-sm text-[#B3B3B3] transition hover:border-[#A92626]/60"
}
>
{messages.categories[category]}
</button>
);
})}
</div>
);
}
+86
View File
@@ -0,0 +1,86 @@
import { useI18n } from "@/lib/i18n";
import { LOCALE_OPTIONS } from "@/lib/i18n/messages";
import { COLORS } from "@/lib/design-tokens";
/** ธงชาติไทยย่อส่วน */
function FlagTh() {
return (
<span
className="block h-4 w-[21px] shrink-0 rounded-[1px]"
style={{ background: COLORS.flagGradient }}
/>
);
}
/** ธงสหราชอาณาจักรย่อส่วน */
function FlagEn() {
return (
<span
className="relative block h-4 w-[21px] shrink-0 overflow-hidden rounded-[1px]"
style={{ background: "#012169" }}
>
<span
className="absolute inset-0"
style={{
background:
"linear-gradient(45deg, transparent 44%, #F4F5F8 44% 56%, transparent 56%), linear-gradient(-45deg, transparent 44%, #F4F5F8 44% 56%, transparent 56%)",
}}
/>
<span
className="absolute inset-0"
style={{
background:
"linear-gradient(90deg, transparent 40%, #F4F5F8 40% 60%, transparent 60%), linear-gradient(0deg, transparent 33%, #F4F5F8 33% 67%, transparent 67%)",
}}
/>
<span
className="absolute inset-0"
style={{
background:
"linear-gradient(90deg, transparent 44%, #C8102E 44% 56%, transparent 56%), linear-gradient(0deg, transparent 40%, #C8102E 40% 60%, transparent 60%)",
}}
/>
</span>
);
}
const FLAGS = { th: FlagTh, en: FlagEn } as const;
/**
* สลับภาษาเป็นปุ่มสองปุ่ม (TH / EN) — ไม่มีเมนูให้เปิด/ปิด
* จึงไม่มีปัญหาคลิกพลาดหรือเมนูถูกบัง และกดครั้งเดียวเปลี่ยนทันที
*/
export function LocaleSwitcher() {
const { locale, setLocale } = useI18n();
return (
<div role="group" aria-label="ภาษา" className="flex items-center gap-1">
{LOCALE_OPTIONS.map((option) => {
const Flag = FLAGS[option.locale];
const isActive = option.locale === locale;
return (
<button
key={option.locale}
type="button"
lang={option.locale}
onClick={() => setLocale(option.locale)}
aria-pressed={isActive}
title={option.name}
className={`flex items-center gap-1.5 rounded-lg px-1.5 py-1 text-sm transition sm:gap-2 sm:px-2 ${
isActive
? "bg-[#242424] font-semibold text-[#D47272]"
: "text-[#B3B3B3] hover:text-white"
}`}
>
<span className="hidden sm:block">
<Flag />
</span>
<span className="text-base font-medium leading-none sm:text-lg">
{option.code}
</span>
</button>
);
})}
</div>
);
}
+35
View File
@@ -0,0 +1,35 @@
import { describe, expect, it } from "vitest";
import { LOGO_SPEC } from "@/lib/design-tokens";
import { logoClasses } from "@/components/site/Logo";
/**
* กันการเผลอเปลี่ยนโลโก้: สเปกใน DESIGN.md ถูกตรึงไว้ที่นี่
* ถ้าเทสต์นี้พัง แปลว่ามีคนแก้สเปกโลโก้ — ต้องขออนุมัติก่อน
*/
describe("โลโก้ AlterFlixHub (สเปกที่ห้ามเปลี่ยน)", () => {
it("ใช้คำว่า AlterFlixHub เท่านั้น", () => {
expect(LOGO_SPEC.wordmark).toBe("AlterFlixHub");
});
it("ฟอนต์ต้องเป็น Jersey 15", () => {
expect(LOGO_SPEC.fontFamily).toContain("Jersey 15");
expect(logoClasses("md")).toContain("font-['Jersey_15']");
expect(logoClasses("sm")).toContain("font-['Jersey_15']");
});
it("สีต้องเป็นแดงแบรนด์ #8F0808", () => {
expect(LOGO_SPEC.color).toBe("#8F0808");
});
it("header 36px (md) และ footer 24px (sm) เท่านั้น", () => {
expect(LOGO_SPEC.sizes.md).toBe("text-4xl");
expect(LOGO_SPEC.sizes.sm).toBe("text-2xl");
expect(logoClasses("md")).toContain("text-4xl");
expect(logoClasses("sm")).toContain("text-2xl");
});
it("ไม่มีตัวเลือกขนาดอื่นนอกเหนือจาก sm/md", () => {
expect(Object.keys(LOGO_SPEC.sizes).sort()).toEqual(["md", "sm"]);
});
});
+26
View File
@@ -0,0 +1,26 @@
import { LOGO_SPEC, type LogoSize } from "@/lib/design-tokens";
type LogoProps = {
className?: string;
/** sm = footer (24px) · md = header (36px) */
size?: LogoSize;
};
/**
* โลโก้ AlterFlixHub — ตาม DESIGN.md หัวข้อ "โลโก้ (ห้ามเปลี่ยนแปลง)"
* ฟอนต์ Jersey 15 สี #8F0808 และมีสองขนาดเท่านั้น (sm/md)
*/
export function logoClasses(size: LogoSize = "md"): string {
return `font-['Jersey_15'] leading-none ${LOGO_SPEC.sizes[size]}`;
}
export function Logo({ className = "", size = "md" }: LogoProps) {
return (
<span
className={`${logoClasses(size)} ${className}`}
style={{ fontFamily: LOGO_SPEC.fontFamily, color: LOGO_SPEC.color }}
>
{LOGO_SPEC.wordmark}
</span>
);
}
+55
View File
@@ -0,0 +1,55 @@
import { Link } from "react-router";
import { Logo } from "@/components/site/Logo";
import { footerIcon } from "@/components/site/footer-icons";
import { useContent } from "@/lib/content-context";
import { useI18n } from "@/lib/i18n";
/**
* Footer ใช้คอนเทนเนอร์เดียวกับ <main> ของทุกหน้า (max-w-[1440px] + px เดียวกัน)
* ขอบซ้าย/ขวาจึงตรงกับกริดการ์ดโรงหนังเป๊ะ ไม่ว่าหน้าจะแสดงการ์ดกี่ใบ
*/
export function SiteFooter() {
const { site } = useContent();
const { messages } = useI18n();
return (
<footer className="relative z-10 mx-auto w-full max-w-[1440px] px-5 pb-6 md:px-[108px]">
<div className="flex flex-col items-center gap-3 border-t border-white/10 pt-4 sm:flex-row sm:justify-between">
<div className="flex items-center gap-4">
<Logo size="sm" />
<nav aria-label="เมนูล่าง" className="flex items-center gap-3 text-xs">
<Link
to="/about"
className="text-[#B3B3B3] transition hover:text-white"
>
{messages.nav.about}
</Link>
</nav>
</div>
<div className="flex flex-wrap items-center justify-center gap-1.5">
{site.footer.map((item) => {
const Icon = footerIcon(item.icon_name);
const isExternal = item.href.startsWith("http");
return (
<a
key={item.id}
href={item.href || "#"}
aria-label={item.label}
title={item.label}
target={isExternal ? "_blank" : undefined}
rel={isExternal ? "noreferrer" : undefined}
className="flex size-8 items-center justify-center rounded-full bg-white/90 text-[#0D0D0D] transition hover:bg-white"
>
<Icon size={18} />
</a>
);
})}
</div>
<p className="text-xs text-[#999]">Copyright © AlterFlixHub</p>
</div>
</footer>
);
}
+39
View File
@@ -0,0 +1,39 @@
import { Link, useLocation } from "react-router";
import { Logo } from "@/components/site/Logo";
import { LocaleSwitcher } from "@/components/site/LocaleSwitcher";
import { useI18n } from "@/lib/i18n";
/**
* Header: โลโก้ชิดซ้าย · ด้านขวาเป็น [เกี่ยวกับเรา] + [ปุ่มภาษา TH/EN]
* ไม่มีเมนู "หน้าแรก" — กลับหน้าแรกได้ด้วยการกดโลโก้
*/
export function SiteHeader() {
const { messages } = useI18n();
const { pathname } = useLocation();
const isAbout = pathname.startsWith("/about");
return (
<header className="relative z-10 mx-auto flex h-[68px] w-full max-w-[1440px] items-center justify-between gap-4 px-5 md:px-[108px]">
<Link to="/" aria-label={`AlterFlixHub — ${messages.nav.home}`} className="shrink-0">
<Logo />
</Link>
<div className="flex items-center gap-1.5 sm:gap-2">
<Link
to="/about"
aria-current={isAbout ? "page" : undefined}
className={`rounded-lg border px-2 py-1 text-xs transition sm:px-3 sm:py-1.5 sm:text-sm ${
isAbout
? "border-[#A92626] bg-[#8F0808]/20 text-white"
: "border-[#303030] text-[#B3B3B3] hover:border-[#A92626]/60 hover:text-white"
}`}
>
{messages.nav.about}
</Link>
<LocaleSwitcher />
</div>
</header>
);
}
+73
View File
@@ -0,0 +1,73 @@
import type { ReactNode } from "react";
import { SiteFooter } from "@/components/site/SiteFooter";
import { SiteHeader } from "@/components/site/SiteHeader";
type ShellVariant = "home" | "detail";
const HERO_IMAGE = "/images/hero.png";
/**
* กรอบของตกแต่งพื้นหลัง
* ต้องมี overflow-hidden ไม่งั้น glow ที่วางด้วย top/bottom แบบ px
* จะยืด scrollHeight ของหน้าให้ยาวเกินเนื้อหา → เกิดพื้นที่ว่างใต้ footer
*/
function BackdropFrame({ children }: { children: ReactNode }) {
return (
<div
aria-hidden="true"
className="pointer-events-none absolute inset-0 overflow-hidden"
>
{children}
</div>
);
}
/** พื้นหลังหน้าแรก: รูปฮีโร่ + ไล่สีลงพื้นหลัง + แสงแดงสองจุด */
function HomeBackdrop() {
return (
<BackdropFrame>
<img
src={HERO_IMAGE}
alt=""
className="pointer-events-none absolute inset-x-0 top-0 h-[553px] w-full object-cover"
/>
<div className="pointer-events-none absolute inset-x-0 top-0 h-[553px] bg-gradient-to-b from-transparent via-[#0D0D0D]/60 to-[#0D0D0D]" />
<div className="pointer-events-none absolute left-1/2 top-0 size-[382px] -translate-x-1/2 -translate-y-1/2 rounded-full bg-[#8F0808] blur-[237px]" />
{/* จุดล่างยึดกับขอบล่างของหน้า (เดิมใช้ top-[1620px] ตายตัว จึงล้นเลย footer เมื่อแสดงโรงหนังแบบย่อ) */}
<div className="pointer-events-none absolute bottom-[-140px] left-1/2 size-[382px] -translate-x-1/2 rounded-full bg-[#4C0404]/70 blur-[237px]" />
</BackdropFrame>
);
}
/** พื้นหลังหน้ารายละเอียด: แสงแดงจุดเดียวตามระยะใน Figma */
function DetailBackdrop() {
return (
<BackdropFrame>
<div className="pointer-events-none absolute left-1/2 top-[649px] size-[382px] -translate-x-1/2 rounded-full bg-[#4C0404] opacity-[0.66] blur-[237px]" />
</BackdropFrame>
);
}
/**
* โครงหน้าเว็บที่ทุก route ใช้ร่วมกัน (พื้นหลัง + header + footer)
* variant เลือกชุดพื้นหลัง ไม่ใช่ layout — เนื้อหายังคงอยู่ใน route
*/
export function SiteShell({
variant,
children,
}: {
variant: ShellVariant;
children: ReactNode;
}) {
return (
<div className="relative flex min-h-dvh w-full flex-col overflow-x-hidden bg-[#0D0D0D] text-white">
{variant === "home" ? <HomeBackdrop /> : <DetailBackdrop />}
<SiteHeader />
{/* flex-1 ดัน footer ไปท้ายจอเมื่อเนื้อหาสั้น — เป็น block ธรรมดา
(ไม่ใช้ flex-col เพื่อไม่ให้ main ที่มี mx-auto หดเหลือ max-content จนล้นจอมือถือ) */}
<div className="flex-1">{children}</div>
<SiteFooter />
</div>
);
}
+33
View File
@@ -0,0 +1,33 @@
import {
IconBrandFacebook,
IconBrandInstagram,
IconBrandLinkedin,
IconBrandTelegram,
IconBrandTiktok,
IconBrandX,
IconBrandYoutube,
IconLink,
IconMail,
IconPhone,
type Icon as TablerIcon,
} from "@tabler/icons-react";
/** ไอคอนที่เลือกใช้ได้ใน footer — เพิ่มชื่อใหม่ได้โดยเติมใน map นี้ */
export const FOOTER_ICONS: Record<string, TablerIcon> = {
IconBrandFacebook,
IconBrandInstagram,
IconBrandLinkedin,
IconBrandYoutube,
IconBrandTelegram,
IconBrandTiktok,
IconBrandX,
IconMail,
IconPhone,
IconLink,
};
export const FOOTER_ICON_NAMES = Object.keys(FOOTER_ICONS);
export function footerIcon(name: string): TablerIcon {
return FOOTER_ICONS[name] ?? IconLink;
}
+1
View File
@@ -0,0 +1 @@
export * from "@agent-native/toolkit/ui/button";
+20
View File
@@ -0,0 +1,20 @@
import {
ToolkitProvider,
type ToolkitComponents,
} from "@agent-native/toolkit/provider";
import type { ReactNode } from "react";
import { Button } from "@/components/ui/button";
import { designSystem } from "@/design-system";
const components: ToolkitComponents = {
Button: Button as ToolkitComponents["Button"],
};
export function AppToolkitProvider({ children }: { children: ReactNode }) {
return (
<ToolkitProvider components={components} designSystem={designSystem}>
{children}
</ToolkitProvider>
);
}