feat(admin): รองรับตัวกรองประเภทโรงหนังเต็มรูปแบบ

- ลิสต์โรงหนัง: ช่องค้นหา (ไทย/อังกฤษ/slug) + ชิปกรองประเภทพร้อมจำนวน (ทั้งหมด/ท้องถิ่น/อินดี้/กลุ่ม/ยังไม่จัด)
- ป้ายประเภทท้ายชื่อทุกแถว (ยังไม่จัด = ป้ายแดง) + empty state
- ตั้งประเภททีละกลุ่ม: "ตั้งประเภทให้ N โรงที่กรองอยู่" → เลือกประเภท → ใช้ (แล้วกดบันทึกทั้งหมด)
- หัวหลังบ้านสรุปจำนวนต่อประเภท
- แท็บคำศัพท์: ปุ่มลัดสร้าง key `venues.<ประเภท>` สำหรับแปลชื่อตัวกรอง
- ปิดลากสลับลำดับขณะกรอง + hint อธิบาย
- logic ย้ายไป lib: filterAdminCinemas / setVenueForSlugs / venueCounts + unit tests (169 ผ่าน)
- DESIGN.md / docs/admin-guide.md อัปเดต
This commit is contained in:
Bkk1234 committed 2026-11-16 01:54:15 +07:00
1 parent 1932098a1d
commit 1cf1398ba4
6 files changed
+377 -16

No files matched your search

+59
View File
@@ -373,6 +373,65 @@ export function hasVenue(cinema: Cinema, venue: VenueType | null): boolean {
return venue === null || cinema.venue_type === venue;
}
/** ตัวกรองประเภทในลิสต์หลังบ้าน — "all" = ทุกประเภท, "unset" = ยังไม่จัดประเภท */
export type VenueFilterValue = VenueType | "all" | "unset";
/** กรองรายชื่อโรงหนังในหลังบ้านตามประเภท (ชั้นกรองที่ 1) + คำค้นชื่อ/slug */
export function filterAdminCinemas(
cinemas: Cinema[],
{
venue,
query,
}: {
venue: VenueFilterValue;
query: string;
},
): Cinema[] {
const needle = query.trim().toLowerCase();
return cinemas.filter((cinema) => {
if (venue === "unset") {
if (cinema.venue_type) return false;
} else if (venue !== "all" && cinema.venue_type !== venue) {
return false;
}
if (!needle) return true;
return `${cinema.name} ${cinema.name_th ?? ""} ${cinema.slug}`
.toLowerCase()
.includes(needle);
});
}
/** ตั้งประเภทให้หลายโรงพร้อมกัน (คืนลิสต์ใหม่ ไม่แตะตัวเดิม) */
export function setVenueForSlugs(
cinemas: Cinema[],
slugs: string[],
venue: VenueType,
): Cinema[] {
if (slugs.length === 0) return cinemas;
const target = new Set(slugs);
return cinemas.map((cinema) =>
target.has(cinema.slug) ? { ...cinema, venue_type: venue } : cinema,
);
}
/** นับจำนวนโรงต่อประเภท (สำหรับสรุปในหลังบ้าน) */
export function venueCounts(
cinemas: Cinema[],
): Record<VenueFilterValue, number> {
const counts: Record<VenueFilterValue, number> = {
all: cinemas.length,
unset: 0,
โรงภาพยนตร์ท้องถิ่น: 0,
โรงภาพยนตร์อินดี้: 0,
กลุ่มคนฉายหนัง: 0,
};
for (const cinema of cinemas) {
if (cinema.venue_type) counts[cinema.venue_type] += 1;
else counts.unset += 1;
}
return counts;
}
export function findCinemaBySlug(
cinemas: Cinema[],
slug: string | undefined,