Files
web-alterflixhub/app/app/components/cinema/CinemaCard.tsx
T
Bkk1234 44823a5b90 feat(app): single-page UX — detail sheet, mobile/tablet responsive
- 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=<slug> (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
2026-10-27 01:14:55 +07:00

95 lines
4.0 KiB
TypeScript

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=<slug>
*/
onSelect?: (slug: string) => void;
}
/**
* การ์ดโรงภาพยนตร์
* ★ มือถือ (<640px): การ์ดแนวนอน ปกซ้าย 112px → สแกน list ได้เร็ว กินพื้นที่น้อย
* ★ แท็บเล็ต/เดสก์ท็อป: การ์ดแนวตั้ง ปก 16:9
* ★ ใช้ <a href="/?cinema=..."> จริง (กดกลาง/เปิดแท็บใหม่ได้, 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<HTMLAnchorElement>) => {
// ปล่อยให้เบราว์เซอร์จัดการถ้าผู้ใช้เปิดแท็บใหม่ / กด 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 (
<a
href={href}
onClick={handleClick}
className="group flex overflow-hidden rounded-xl border border-white/10 bg-[#141414] transition-colors duration-150 hover:border-[#ff1f1f] focus-visible:outline-2 focus-visible:outline-offset-2 focus-visible:outline-[#ff1f1f] active:bg-[#1c1c1c] sm:block"
>
{/* ปก */}
<div
className="relative aspect-square w-28 shrink-0 sm:aspect-[16/9] sm:w-full"
style={{ background: cinema.cover }}
>
<span
className={`absolute left-2 top-2 rounded-full border px-2 py-0.5 text-[10px] font-bold leading-tight sm:left-3 sm:top-3 sm:px-2.5 sm:text-[11px] ${
isOpen
? "border-[#ff1f1f] bg-[#e00000]/85 text-white"
: "border-white/20 bg-black/55 text-white"
}`}
>
{isOpen ? t("status.open") : t("status.closed")}
</span>
</div>
{/* เนื้อหา */}
<div className="flex min-w-0 flex-1 flex-col justify-center gap-1 px-3 py-2.5 sm:gap-1.5 sm:px-4 sm:py-3.5">
<h3 className="truncate text-[15px] font-bold leading-tight sm:text-base">
{cinema.name}
</h3>
<p className="truncate text-xs text-[#9ca3af] sm:text-[13px]">{cinema.area}</p>
<div className="mt-0.5 flex items-center gap-2.5 text-xs sm:text-[13px]">
<span className="inline-flex items-center gap-1 font-bold text-[#ff1f1f]">
<IconStar size={14} stroke={2} className="shrink-0" aria-hidden="true" />
{cinema.rating.toFixed(1)}
</span>
<span className="text-[#6b7280]">·</span>
<span className={isOpen ? "font-medium text-[#22c55e]" : "text-[#9ca3af]"}>
{isOpen ? t("status.open") : t("status.closed")}
</span>
</div>
{/* แท็ก — ซ่อนบนมือถือเพื่อไม่ให้แน่น */}
{cinema.tags.length > 0 && (
<div className="mt-1 hidden flex-wrap gap-1.5 sm:flex">
{cinema.tags.map((tag) => (
<span
key={tag}
className="rounded-full border border-[#A92626] px-2.5 py-0.5 text-[11px] text-[#D47272]"
>
{tag}
</span>
))}
</div>
)}
</div>
</a>
);
}