- บทความจากหลังบ้าน: /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 ไฟล์)
116 lines
4.4 KiB
TypeScript
116 lines
4.4 KiB
TypeScript
import {
|
|
IconArrowRight,
|
|
IconBuildingCommunity,
|
|
IconMapPin,
|
|
} from "@tabler/icons-react";
|
|
import { Link } from "react-router";
|
|
|
|
import { ShareButton } from "@/components/site/ShareButton";
|
|
import { useNearMe } from "@/hooks/use-near-me";
|
|
import { useReveal } from "@/hooks/use-reveal";
|
|
import { trackEvent } from "@/lib/analytics-client";
|
|
import {
|
|
CARD_GRADIENTS,
|
|
cinemaCategoryLabel,
|
|
cinemaLocationLabel,
|
|
cinemaName,
|
|
type Cinema,
|
|
} from "@/lib/cinemas";
|
|
import { formatDistance } from "@/lib/geo";
|
|
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,
|
|
);
|
|
|
|
// ไล่จังหวะโผล่ทีละใบตามคอลัมน์ (เริ่มหลังหัวข้อ/หมวด เพื่อให้ดูเป็นลำดับ)
|
|
const { ref, revealed, style } = useReveal<HTMLElement>(
|
|
140 + (index % 4) * 70,
|
|
);
|
|
|
|
return (
|
|
<article
|
|
ref={ref}
|
|
data-reveal="zoom"
|
|
data-revealed={revealed ? "" : undefined}
|
|
style={style}
|
|
className={`group relative flex aspect-[3/4] flex-col justify-end overflow-hidden rounded-[20px] bg-gradient-to-br p-2 transition-[translate,box-shadow] duration-300 ease-out hover:-translate-y-1 hover:shadow-[0_18px_38px_-24px_rgba(143,8,8,0.75)] 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 transition-transform duration-700 ease-out group-hover:scale-[1.06]"
|
|
/>
|
|
{/* ไล่เงาเพื่อให้ตัวอักษรบนการ์ดอ่านได้ */}
|
|
<div
|
|
aria-hidden="true"
|
|
className="absolute inset-0 bg-gradient-to-t from-[#0D0D0D]/95 via-[#0D0D0D]/35 to-transparent"
|
|
/>
|
|
</>
|
|
) : null}
|
|
|
|
{/* ปุ่มแชร์ลอยมุมขวาบนของการ์ด */}
|
|
<div className="absolute right-3 top-3 z-10">
|
|
<ShareButton slug={cinema.slug} title={cinemaName(cinema, locale)} />
|
|
</div>
|
|
|
|
<div className="relative flex flex-col gap-1.5 rounded-2xl border border-white/10 bg-[#1B1B1B]/80 p-3 backdrop-blur-xl transition-colors duration-300 group-hover:border-[#A92626]/40">
|
|
<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>
|
|
);
|
|
}
|