- บทความจากหลังบ้าน: /for-film-lovers, /for-cinemas (ArticlePage + ArticleEditor แบบบล็อกย่อหน้า/รูป) - แชร์: ปุ่มบนการ์ดและท้ายหน้ารายละเอียด · ลิงก์ย่อ /c/<slug> (302) · ธีมแก้วตาม DESIGN.md - PWA: manifest/sw/offline + ถอดการล็อกซูม (WCAG 1.4.4) + touch target ≥44px - แอนิเมชัน reveal: IntersectionObserver + gate ด้วย html.fx-motion · เคารพ prefers-reduced-motion - ค้นหา: normalize/ตัดวรรณยุกต์ + AND หลายคำ + จัดอันดับ · รองรับ /?q= จาก SearchAction - SEO: pageMeta (canonical/OG/Twitter) + JSON-LD (WebSite/Organization/BreadcrumbList/MovieTheater/Article) - ไม่ฝังโดเมนในโค้ด: origin มาจาก request (x-forwarded-host/proto) ทั้ง canonical, sitemap, robots, ลิงก์แชร์ - กัน AI: robots.txt (Nitro route, บล็อก AI 21 ตัว) + ai.txt + OG image 1200x630 - เอกสาร: README สรุปโปรเจกต์, DESIGN.md (motion/PWA/SEO/ข้อมูล), architecture.html, admin-guide - tests: 135 ผ่าน (16 ไฟล์)
117 lines
4.5 KiB
TypeScript
117 lines
4.5 KiB
TypeScript
import { IconChevronLeft, IconChevronRight } from "@tabler/icons-react";
|
|
import { useState, type ReactNode } from "react";
|
|
|
|
import { Logo } from "@/components/site/Logo";
|
|
import { rotateGallery, 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}`}
|
|
/>
|
|
);
|
|
}
|
|
|
|
/** แกลเลอรีภาพโรงหนัง — ปุ่มลูกศรเลื่อนดูภาพทั้งหมดโดยภาพหลักและภาพย่อยเลื่อนตามกัน */
|
|
export function Gallery({ photos, cinemaName }: GalleryProps) {
|
|
const { messages } = useI18n();
|
|
const [startIndex, setStartIndex] = useState(0);
|
|
const total = photos.length;
|
|
// หมุนรายการตามตำแหน่งที่เลือก แล้วแบ่งเป็นภาพหลัก + ภาพย่อยตามเดิม
|
|
const { main, thumbs, remaining } = splitGallery(
|
|
rotateGallery(photos, startIndex),
|
|
);
|
|
const [firstThumb = null, secondThumb = null] = thumbs;
|
|
const canNavigate = total > 1;
|
|
|
|
function step(direction: 1 | -1) {
|
|
setStartIndex((current) => current + direction);
|
|
}
|
|
|
|
return (
|
|
<section className="grid gap-6 lg:grid-cols-[minmax(0,807px)_minmax(0,387px)]">
|
|
<div className="relative overflow-hidden rounded-xl">
|
|
<GallerySlot
|
|
key={`main-${main ?? "empty"}`}
|
|
photo={main}
|
|
alt={`${messages.gallery.main} — ${cinemaName}`}
|
|
placeholder={<Logo size="md" />}
|
|
className="fx-swap aspect-[269/202] w-full lg:aspect-auto lg:h-[606px]"
|
|
/>
|
|
{canNavigate ? (
|
|
<>
|
|
<button
|
|
type="button"
|
|
onClick={() => step(-1)}
|
|
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 text-white transition after:absolute after:-inset-1 after:content-[''] hover:bg-black/75 focus-visible:outline-none focus-visible:ring-2 focus-visible:ring-[#A92626] active:scale-95"
|
|
>
|
|
<IconChevronLeft size={24} />
|
|
</button>
|
|
<button
|
|
type="button"
|
|
onClick={() => step(1)}
|
|
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 text-white transition after:absolute after:-inset-1 after:content-[''] hover:bg-black/75 focus-visible:outline-none focus-visible:ring-2 focus-visible:ring-[#A92626] active:scale-95"
|
|
>
|
|
<IconChevronRight size={24} />
|
|
</button>
|
|
</>
|
|
) : null}
|
|
</div>
|
|
|
|
<div className="grid grid-cols-2 gap-6 lg:grid-cols-1 lg:grid-rows-2">
|
|
<div className="overflow-hidden rounded-xl">
|
|
<GallerySlot
|
|
key={`thumb-1-${firstThumb ?? "empty"}`}
|
|
photo={firstThumb}
|
|
alt={`${messages.gallery.second} — ${cinemaName}`}
|
|
placeholder={<Logo size="sm" />}
|
|
className="fx-swap aspect-[387/290] w-full"
|
|
/>
|
|
</div>
|
|
<div className="relative overflow-hidden rounded-xl">
|
|
<GallerySlot
|
|
key={`thumb-2-${secondThumb ?? "empty"}`}
|
|
photo={secondThumb}
|
|
alt={`${messages.gallery.third} — ${cinemaName}`}
|
|
placeholder={<Logo size="sm" />}
|
|
className="fx-swap 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>
|
|
);
|
|
}
|