Files
Bkk1234 251932e548 fix(photos): รูปโรงหนังแตก — mirror รูปภายนอกมาเก็บในโปรเจกต์ + fallback
สาเหตุ: photos[] อ้างลิงก์ hotlink (googleusercontent/gstatic/fbcdn ฯลฯ)
ซึ่งตอบ 200 แต่ 0 ไบต์เมื่อลิงก์หมดอายุ/ถูกจำกัด rate → รูปแตกเงียบ ๆ
เช่น /cinema/phahol-theatre

- scripts/mirror-photos.mjs: ดาวน์โหลด 20 รูปจาก 12 โรง มาเก็บ public/images/cinemas
  แล้วแก้ content.json ชี้ path ในโปรเจกต์ (สำรอง .bak-photos-* ก่อนเขียน) → เหลือรูปภายนอก 0
- บีบอัดรูปใหญ่ (<=1600px, q82): 6.12 MB → 2.91 MB
- PhotoImage: img + onError fallback เป็นโลโก้ (ใช้ใน CinemaCard/Gallery) กันรูปแตกทุกกรณี
- scripts/audit-photos.mjs: ตรวจรูปเสีย exit 1
- DESIGN.md: กฎรูปภาพ (ห้าม hotlink, ต้องใช้ PhotoImage, เพดานขนาด)
2026-11-15 22:32:52 +07:00

116 lines
4.5 KiB
TypeScript

import {
IconArrowRight,
IconBuildingCommunity,
IconMapPin,
} from "@tabler/icons-react";
import { Link } from "react-router";
import { PhotoImage } from "@/components/site/PhotoImage";
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 ? (
<>
<PhotoImage
src={cover}
alt=""
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>
);
}