feat(home): ชั้นกรองที่ 1 — ประเภทโรงหนัง (ท้องถิ่น / อินดี้ / กลุ่มคนฉายหนัง)

- แถบกรองสองชั้นในแถวเดียว: ทั้งหมด → 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 อัปเดต
This commit is contained in:
Bkk1234 committed 2026-11-16 01:46:59 +07:00
1 parent 2e794cd365
commit 1932098a1d
15 files changed
+362 -26

No files matched your search

+18 -3
View File
@@ -11,9 +11,11 @@ import { APP_TITLE } from "@/lib/app-config";
import {
CINEMA_CATEGORIES,
DEFAULT_CATEGORY,
VENUE_TYPES,
publiclyVisible,
type Cinema,
type CinemaCategory,
type VenueType,
} from "@/lib/cinemas";
import { useContent } from "@/lib/content-context";
import { dailyOrder, dayKey } from "@/lib/daily-order";
@@ -67,6 +69,8 @@ export default function HomeRoute() {
const { cinemas } = useContent();
const { status: nearMeStatus, distances, requestLocation } = useNearMe();
const [category, setCategory] = useState<CinemaCategory>(DEFAULT_CATEGORY);
/** ชั้นกรองที่ 1 — ประเภทโรงหนัง (null = ทุกประเภท) */
const [venue, setVenue] = useState<VenueType | null>(null);
// รองรับลิงก์ค้นหาตรง ๆ (/?q=...) — ให้ SearchAction ใน JSON-LD ทำงานจริง
const [searchParams] = useSearchParams();
const [query, setQuery] = useState(() => searchParams.get("q") ?? "");
@@ -82,16 +86,24 @@ export default function HomeRoute() {
orderKey,
);
const byStats =
category === "ยอดนิยม" && popularity.ready && query.trim() === "";
category === "ยอดนิยม" &&
venue === null &&
popularity.ready &&
query.trim() === "";
if (!byStats)
return filterCinemas(base, { category, query, tagLabels: messages.tags });
return filterCinemas(base, {
category,
query,
venue,
tagLabels: messages.tags,
});
// ใช้เฉพาะโรงที่ยังไม่ถูกซ่อน และเรียงตามอันดับสถิติ
const bySlug = new Map(base.map((cinema) => [cinema.slug, cinema]));
return popularity.slugs
.map((slug) => bySlug.get(slug))
.filter((cinema): cinema is Cinema => cinema !== undefined);
}, [cinemas, category, query, popularity, orderKey, messages.tags]);
}, [cinemas, category, query, venue, popularity, orderKey, messages.tags]);
// เรียงจากใกล้สุดไปไกลสุดเมื่อทราบตำแหน่งแล้ว (ไม่กรองตามรัศมี — ไกลแค่ไหนก็ยังแสดง)
const ordered =
nearMeStatus === "ready" ? sortByDistance(matched, distances) : matched;
@@ -163,6 +175,9 @@ export default function HomeRoute() {
active={category}
categories={CINEMA_CATEGORIES}
onChange={setCategory}
venues={VENUE_TYPES}
activeVenue={venue}
onVenueChange={setVenue}
/>
</Reveal>