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

+68 -10
View File
@@ -1,5 +1,5 @@
import { CinemaCard } from "@/components/site/CinemaCard";
import type { Cinema, CinemaCategory } from "@/lib/cinemas";
import type { Cinema, CinemaCategory, VenueType } from "@/lib/cinemas";
import { useI18n } from "@/lib/i18n";
/** กริดการ์ดโรงหนัง — ใช้ทั้งหน้าแรกและส่วน "โรงหนังอิสระอื่นๆ" */
@@ -32,30 +32,88 @@ 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 gap-2">
{categories.map((category) => {
const isActive = category === active;
<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)}
onClick={() => {
onChange(category);
onVenueChange?.(null);
}}
aria-pressed={isActive}
className={`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"
}`}
className={chipClass(isActive)}
>
{messages.categories[category]}
</button>
+73 -2
View File
@@ -1,10 +1,13 @@
import { describe, expect, it } from "vitest";
import {
findCinemaBySlug,
listOtherCinemas,
CINEMAS,
findCinemaBySlug,
hasVenue,
listOtherCinemas,
type Cinema,
} from "./cinemas";
import { filterCinemas } from "./search";
describe("findCinemaBySlug", () => {
it("คืน undefined เมื่อไม่ได้ส่ง slug", () => {
@@ -27,3 +30,71 @@ describe("listOtherCinemas", () => {
);
});
});
describe("hasVenue / filterCinemas (ชั้นกรองประเภทโรงหนัง)", () => {
const base = {
slug: "x",
name: "X",
tags: ["อาร์ตเฮาส์"],
location_label: "",
coordinates: null,
description: "",
map_url: null,
address_lines: [],
transport: [],
contacts: [],
payments: [],
photos: [],
} as Cinema;
const local: Cinema = {
...base,
slug: "local",
venue_type: "โรงภาพยนตร์ท้องถิ่น",
};
const indie: Cinema = { ...base, slug: "indie", venue_type: "โรงภาพยนตร์อินดี้" };
const group: Cinema = { ...base, slug: "group", venue_type: "กลุ่มคนฉายหนัง" };
const unset: Cinema = { ...base, slug: "unset" };
it("hasVenue: null = ไม่กรอง", () => {
expect(hasVenue(local, null)).toBe(true);
expect(hasVenue(unset, null)).toBe(true);
});
it("hasVenue: ตรงประเภทเท่านั้น", () => {
expect(hasVenue(local, "โรงภาพยนตร์ท้องถิ่น")).toBe(true);
expect(hasVenue(local, "โรงภาพยนตร์อินดี้")).toBe(false);
expect(hasVenue(unset, "โรงภาพยนตร์อินดี้")).toBe(false);
});
it("filterCinemas กรองตามประเภทได้", () => {
const all = [local, indie, group, unset];
expect(
filterCinemas(all, {
category: "ทั้งหมด",
query: "",
venue: "โรงภาพยนตร์อินดี้",
}),
).toEqual([indie]);
expect(
filterCinemas(all, {
category: "ทั้งหมด",
query: "",
venue: "กลุ่มคนฉายหนัง",
}),
).toEqual([group]);
expect(filterCinemas(all, { category: "ทั้งหมด", query: "" })).toHaveLength(
4,
);
});
it("กรองประเภท + หมวดซ้อนกันได้ (AND)", () => {
expect(
filterCinemas([local, indie], {
category: "อาร์ตเฮาส์",
query: "",
venue: "โรงภาพยนตร์ท้องถิ่น",
}),
).toEqual([local]);
});
});
+22 -1
View File
@@ -51,6 +51,11 @@ export type Cinema = {
>;
/** ซ่อนจากหน้าเว็บ (ยังเปิดดูได้ด้วย URL ตรง) — ไม่แสดงในรายการ/ค้นหา/โรงอื่นๆ */
hidden?: boolean;
/**
* ชั้นกรองที่ 1 — ประเภทโรงหนัง (ค่าเดียว): โรงภาพยนตร์ท้องถิ่น / โรงภาพยนตร์อินดี้ / กลุ่มคนฉายหนัง
* ไม่กรอก = ยังไม่จัดประเภท (จะไม่ปรากฏเมื่อกรองด้วยประเภทใด ๆ)
*/
venue_type?: VenueType | null;
/** หัวข้อการ์ดติดต่อ/จองตั๋ว เฉพาะโรงนี้ (ว่าง = ใช้ค่าเริ่มต้นจาก messages) */
contact_heading?: string;
/** รูปโรงหนัง เรียงตามลำดับที่ใช้ในแกลเลอรี — ว่างได้ถ้ายังไม่มีรูป */
@@ -68,12 +73,23 @@ export const CINEMA_CATEGORIES = [
"หนังนอกกระแส",
"หนังในกระแส",
"หนังฝรั่งเศส",
"กลุ่มคนฉายหนัง",
"หนังไทย",
] as const;
export type CinemaCategory = (typeof CINEMA_CATEGORIES)[number];
/**
* ชั้นกรองที่ 1 — "ประเภทโรงหนัง" (เลือกได้ทีละอย่าง)
* ข้อมูลเก็บที่ `cinema.venue_type` (คนละฟิลด์กับ tags เพราะโรงหนึ่งเป็นได้ประเภทเดียว)
*/
export const VENUE_TYPES = [
"โรงภาพยนตร์ท้องถิ่น",
"โรงภาพยนตร์อินดี้",
"กลุ่มคนฉายหนัง",
] as const;
export type VenueType = (typeof VENUE_TYPES)[number];
export const DEFAULT_CATEGORY: CinemaCategory = "ทั้งหมด";
/** ลำดับ gradient ของการ์ด ใช้ร่วมกันทุกหน้าเพื่อให้สีคงที่ */
@@ -352,6 +368,11 @@ export function hasCategory(cinema: Cinema, category: CinemaCategory): boolean {
return category === DEFAULT_CATEGORY || cinema.tags.includes(category);
}
/** ชั้นกรองที่ 1: ประเภทโรงหนัง — null = ไม่กรอง */
export function hasVenue(cinema: Cinema, venue: VenueType | null): boolean {
return venue === null || cinema.venue_type === venue;
}
export function findCinemaBySlug(
cinemas: Cinema[],
slug: string | undefined,
+4 -1
View File
@@ -9,7 +9,7 @@ import { mkdir, readFile, rename, writeFile } from "node:fs/promises";
import path from "node:path";
import { sanitizeArticleBlocks } from "@/lib/article";
import type { Cinema } from "@/lib/cinemas";
import { VENUE_TYPES, type Cinema, type VenueType } from "@/lib/cinemas";
import { contactHref } from "@/lib/contact-link";
import {
seedAbout,
@@ -142,6 +142,9 @@ export function sanitizeCinemas(input: unknown): Cinema[] {
facilities: sanitizeFacilities(raw.facilities),
facility_details: sanitizeFacilityDetails(raw.facility_details),
hidden: raw.hidden === true,
venue_type: VENUE_TYPES.includes(raw.venue_type as VenueType)
? (raw.venue_type as VenueType)
: null,
contact_heading: asString(raw.contact_heading),
photos: asStringList(raw.photos),
};
+13 -3
View File
@@ -1,4 +1,4 @@
import type { CinemaCategory } from "@/lib/cinemas";
import type { CinemaCategory, VenueType } from "@/lib/cinemas";
export type Locale = "th" | "en";
@@ -138,6 +138,8 @@ export type Messages = {
};
/** ป้ายของหมวดหมู่ — คีย์ยังเป็นไทยเพื่อใช้กรองข้อมูล */
categories: Record<CinemaCategory, string>;
/** ชั้นกรองที่ 1 — ประเภทโรงหนัง (คีย์ไทย ใช้กรองข้อมูล) */
venues: Record<VenueType, string>;
/** ป้ายของ tag ในข้อมูลโรงหนัง */
tags: Record<string, string>;
facilities: Record<FacilityKey, { title: string; sub: string }>;
@@ -281,9 +283,13 @@ const TH: Messages = {
หนังนอกกระแส: "หนังนอกกระแส",
หนังในกระแส: "หนังในกระแส",
หนังฝรั่งเศส: "หนังฝรั่งเศส",
กลุ่มคนฉายหนัง: "กลุ่มคนฉายหนัง",
หนังไทย: "หนังไทย",
},
venues: {
โรงภาพยนตร์ท้องถิ่น: "โรงภาพยนตร์ท้องถิ่น",
โรงภาพยนตร์อินดี้: "โรงภาพยนตร์อินดี้",
กลุ่มคนฉายหนัง: "กลุ่มคนฉายหนัง",
},
tags: {
ยอดนิยม: "ยอดนิยม",
อาร์ตเฮาส์: "อาร์ตเฮาส์",
@@ -451,9 +457,13 @@ const EN: Messages = {
หนังนอกกระแส: "Independent",
หนังในกระแส: "Mainstream",
หนังฝรั่งเศส: "French films",
กลุ่มคนฉายหนัง: "Film collectives",
หนังไทย: "Thai films",
},
venues: {
โรงภาพยนตร์ท้องถิ่น: "Local cinemas",
โรงภาพยนตร์อินดี้: "Indie cinemas",
กลุ่มคนฉายหนัง: "Film collectives",
},
tags: {
ยอดนิยม: "Popular",
อาร์ตเฮาส์: "Arthouse",
+13 -2
View File
@@ -11,7 +11,13 @@
* 4) matchLevel + FIELD_WEIGHTS — ให้คะแนนความตรง
* 5) scoreCinema / filterCinemas — รวมผลและเรียงจากตรงที่สุด
*/
import { hasCategory, type Cinema, type CinemaCategory } from "@/lib/cinemas";
import {
hasCategory,
hasVenue,
type Cinema,
type CinemaCategory,
type VenueType,
} from "@/lib/cinemas";
/** อักขระล่องหนที่ติดมากับการคัดลอกข้อความ (zero-width, BOM) */
const ZERO_WIDTH = /[\u200B-\u200D\u2060\uFEFF]/g;
@@ -187,15 +193,20 @@ export function filterCinemas(
{
category,
query,
venue = null,
tagLabels = {},
}: {
category: CinemaCategory;
query: string;
/** ชั้นกรองที่ 1 — ประเภทโรงหนัง (null = ทุกประเภท) */
venue?: VenueType | null;
/** ป้ายหมวดตามภาษาที่แสดงบนการ์ด (messages.tags) */
tagLabels?: Record<string, string>;
},
): Cinema[] {
const inCategory = cinemas.filter((cinema) => hasCategory(cinema, category));
const inCategory = cinemas
.filter((cinema) => hasVenue(cinema, venue))
.filter((cinema) => hasCategory(cinema, category));
const tokens = searchTokens(query);
if (tokens.length === 0) return inCategory;
+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>
+29 -1
View File
@@ -14,7 +14,12 @@ import { SlugInput, suggestSlug } from "@/components/admin/SlugInput";
import { TransportEditor } from "@/components/admin/TransportEditor";
import { FOOTER_ICON_NAMES } from "@/components/site/footer-icons";
import type { AnalyticsSummary } from "@/lib/analytics-types";
import { ASSIGNABLE_CATEGORIES, type Cinema } from "@/lib/cinemas";
import {
ASSIGNABLE_CATEGORIES,
VENUE_TYPES,
type Cinema,
type VenueType,
} from "@/lib/cinemas";
import {
seedAbout,
seedForCinemas,
@@ -380,6 +385,29 @@ export default function AdminRoute() {
}
/>
</label>
<label className={labelClass}>
ประเภทโรงหนัง (ตัวกรองชั้นแรกบนหน้าแรก)
<select
className={inputClass}
value={cinema.venue_type ?? ""}
onChange={(event) =>
updateCinema({
...cinema,
venue_type:
event.target.value === ""
? null
: (event.target.value as VenueType),
})
}
>
<option value="">— ยังไม่จัดประเภท —</option>
{VENUE_TYPES.map((venue) => (
<option key={venue} value={venue}>
{venue}
</option>
))}
</select>
</label>
<label className={labelClass}>
slug (ใช้ใน URL)
<SlugInput