- แถบกรองสองชั้นในแถวเดียว: ทั้งหมด → 3 ประเภท │ ยอดนิยม → หมวดภาพยนตร์เดิม
- เก็บประเภทที่ฟิลด์เดี่ยว cinema.venue_type (ค่าเดียว) + hasVenue()/filterCinemas({ venue })
- ย้าย "กลุ่มคนฉายหนัง" จาก categories ขึ้นชั้น 1 (ไม่ให้ปุ่มซ้ำ) · tag ยังอยู่และยังค้นหาเจอ
- เลือกได้ทีละชั้น: กดประเภทล้างหมวด / กดหมวดล้างประเภท / ทั้งหมดล้างทั้งคู่
- ปิด popularity path เมื่อกรองด้วยประเภท (กันจัดอันดับข้ามประเภท)
- หลังบ้าน: ช่อง "ประเภทโรงหนัง" ในหมวดข้อมูลหลัก + sanitize เฉพาะค่าใน VENUE_TYPES
- i18n: messages.venues (TH/EN) · override ได้ผ่าน site.terms
- scripts/set-venue-types.mjs จัดประเภท 29 โรง (15 ท้องถิ่น / 11 อินดี้ / 3 กลุ่มคนฉายหนัง) พร้อมสำรอง content.json
- tests: hasVenue + filterCinemas (165 ผ่าน) · sw v2.0.5 · DESIGN/AGENTS/README/admin-guide/api อัปเดต
125 lines
4.3 KiB
TypeScript
125 lines
4.3 KiB
TypeScript
import { CinemaCard } from "@/components/site/CinemaCard";
|
|
import type { Cinema, CinemaCategory, VenueType } 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;
|
|
/** ชั้นกรองที่ 1 — ประเภทโรงหนัง (แสดงต่อจาก "ทั้งหมด") */
|
|
venues?: readonly VenueType[];
|
|
activeVenue?: VenueType | null;
|
|
onVenueChange?: (venue: VenueType | null) => void;
|
|
};
|
|
|
|
const chipClass = (isActive: boolean) =>
|
|
`relative rounded-[18px] border px-4 py-2 text-sm after:absolute after:-inset-y-1.5 after:inset-x-0 after:content-[''] ${
|
|
isActive
|
|
? "border-[#A92626] bg-gradient-to-b from-[#8F0808]/30 to-[#1B1B1B]/0 text-[#D47272]"
|
|
: "border-[#303030] bg-[#242424] text-[#B3B3B3] transition hover:border-[#A92626]/60"
|
|
}`;
|
|
|
|
/**
|
|
* แถบกรองสองชั้นในแถวเดียว
|
|
* 1) ประเภทโรงหนัง (ท้องถิ่น / อินดี้ / กลุ่มคนฉายหนัง) — แทรกหลัง "ทั้งหมด"
|
|
* 2) หมวดภาพยนตร์แบบเดิม (อาร์ตเฮาส์ / สารคดี / …)
|
|
* เลือกได้ทีละชั้น: กดประเภท → ล้างหมวด, กดหมวด → ล้างประเภท (กันการกรองซ้อนที่ผู้ใช้คาดไม่ถึง)
|
|
*/
|
|
export function CategoryFilter({
|
|
active,
|
|
categories,
|
|
onChange,
|
|
venues = [],
|
|
activeVenue = null,
|
|
onVenueChange,
|
|
}: CategoryFilterProps) {
|
|
const { messages } = useI18n();
|
|
const [allCategory, ...restCategories] = categories;
|
|
const hasVenues = venues.length > 0 && typeof onVenueChange === "function";
|
|
const allActive = active === allCategory && activeVenue === null;
|
|
|
|
return (
|
|
<div className="flex flex-wrap items-center gap-2">
|
|
<button
|
|
type="button"
|
|
onClick={() => {
|
|
onChange(allCategory);
|
|
onVenueChange?.(null);
|
|
}}
|
|
aria-pressed={allActive}
|
|
className={chipClass(allActive)}
|
|
>
|
|
{messages.categories[allCategory]}
|
|
</button>
|
|
|
|
{hasVenues
|
|
? venues.map((venue) => {
|
|
const isActive = activeVenue === venue;
|
|
return (
|
|
<button
|
|
key={venue}
|
|
type="button"
|
|
onClick={() => {
|
|
onChange(allCategory);
|
|
onVenueChange?.(isActive ? null : venue);
|
|
}}
|
|
aria-pressed={isActive}
|
|
className={chipClass(isActive)}
|
|
>
|
|
{messages.venues[venue]}
|
|
</button>
|
|
);
|
|
})
|
|
: null}
|
|
|
|
{hasVenues ? (
|
|
<span aria-hidden="true" className="mx-1 h-6 w-px bg-[#303030]" />
|
|
) : null}
|
|
|
|
{restCategories.map((category) => {
|
|
const isActive = category === active && activeVenue === null;
|
|
return (
|
|
<button
|
|
key={category}
|
|
type="button"
|
|
onClick={() => {
|
|
onChange(category);
|
|
onVenueChange?.(null);
|
|
}}
|
|
aria-pressed={isActive}
|
|
className={chipClass(isActive)}
|
|
>
|
|
{messages.categories[category]}
|
|
</button>
|
|
);
|
|
})}
|
|
</div>
|
|
);
|
|
}
|