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:
1 parent
1932098a1d
commit
1cf1398ba4
6 files changed
+377
-16
No files matched your search
@@ -237,6 +237,8 @@ Single source of truth per concern — do not duplicate these:
|
||||
- **เลือกได้ทีละชั้น**: กดประเภท → ล้างหมวดเป็น `ทั้งหมด`; กดหมวด → ล้างประเภทเป็น `null`; `ทั้งหมด` ล้างทั้งสอง (กันการกรองซ้อนที่คนใช้คาดไม่ถึง)
|
||||
- ตัวกรองจริงอยู่ใน `filterCinemas(..., { venue })` ทำงานแบบ AND กับหมวดและคำค้น (เผื่ออนาคตจะเปิดให้ซ้อน) — `venue = null` คือไม่กรอง
|
||||
- โรงที่ยังไม่ตั้ง `venue_type` จะไม่โผล่เมื่อกรองด้วยประเภทใด ๆ · ตั้งค่าได้ที่หลังบ้าน → แท็บโรงหนัง → ข้อมูลหลัก → **ประเภทโรงหนัง** (sanitize ใน `content.server.ts` เท่านั้น)
|
||||
- หลังบ้านต้องรองรับพร้อมกัน: ลิสต์ซ้ายมีช่องค้นหา + ชิปกรอง `ทั้งหมด/ท้องถิ่น/อินดี้/กลุ่ม/ยังไม่จัด` พร้อมจำนวน, ป้ายประเภทท้ายชื่อทุกแถว, กล่อง **ตั้งประเภททีละกลุ่ม** (`setVenueForSlugs`) และสรุปจำนวนในหัวหลังบ้าน · logic อยู่ใน `filterAdminCinemas` / `venueCounts` (`app/lib/cinemas.ts`) ไม่ใช่ใน component (มี unit test)
|
||||
- ลากสลับลำดับถูกปิดเมื่อกรองอยู่ (`draggable={mode === "manual" && !isFiltered}`) เพราะลำดับของผลที่กรองแล้วไม่มีความหมาย
|
||||
- `venue_type` เป็นข้อมูล ไม่ใช่ข้อความ: ห้าม hardcode ป้ายใน component ต้องอ่าน `messages.venues` (คีย์ไทย) และ override ได้ผ่าน `site.terms` (`venues.<คีย์>`)
|
||||
- Popularity path (`category === "ยอดนิยม"`) ถูกปิดเมื่อมี `venue` — กันการจัดอันดับข้ามประเภท
|
||||
|
||||
|
||||
@@ -6,7 +6,23 @@ import {
|
||||
} from "@tabler/icons-react";
|
||||
import { useMemo, useState } from "react";
|
||||
|
||||
import type { Cinema } from "@/lib/cinemas";
|
||||
import {
|
||||
VENUE_TYPES,
|
||||
filterAdminCinemas,
|
||||
venueCounts as countByVenue,
|
||||
type Cinema,
|
||||
type VenueType,
|
||||
type VenueFilterValue,
|
||||
} from "@/lib/cinemas";
|
||||
|
||||
/** ตัวกรองประเภทโรงหนังในลิสต์หลังบ้าน — "all" = ทุกประเภท, "unset" = ยังไม่จัดประเภท */
|
||||
type VenueFilter = VenueFilterValue;
|
||||
|
||||
const venueShort: Record<VenueType, string> = {
|
||||
โรงภาพยนตร์ท้องถิ่น: "ท้องถิ่น",
|
||||
โรงภาพยนตร์อินดี้: "อินดี้",
|
||||
กลุ่มคนฉายหนัง: "กลุ่ม",
|
||||
};
|
||||
|
||||
/**
|
||||
* รายชื่อโรงหนังในหลังบ้าน — เรียง ก-ฮ และสลับตำแหน่งได้
|
||||
@@ -28,7 +44,9 @@ function sortKey(cinema: Cinema): string {
|
||||
|
||||
/** เรียงชื่อโรงหนังภาษาไทยตามพจนานุกรม ก-ฮ */
|
||||
export function sortCinemasByName(cinemas: Cinema[]): Cinema[] {
|
||||
return [...cinemas].sort((a, b) => thaiCollator.compare(sortKey(a), sortKey(b)));
|
||||
return [...cinemas].sort((a, b) =>
|
||||
thaiCollator.compare(sortKey(a), sortKey(b)),
|
||||
);
|
||||
}
|
||||
|
||||
/** เทียบว่าสองลิสต์มี slug เรียงเหมือนกันหรือยัง */
|
||||
@@ -58,7 +76,11 @@ export function moveCinema(
|
||||
}
|
||||
|
||||
/** เลื่อนขึ้น/ลงทีละหนึ่งตำแหน่ง (สำหรับปุ่มลูกศร) */
|
||||
export function shiftCinema(cinemas: Cinema[], slug: string, delta: number): Cinema[] {
|
||||
export function shiftCinema(
|
||||
cinemas: Cinema[],
|
||||
slug: string,
|
||||
delta: number,
|
||||
): Cinema[] {
|
||||
const from = cinemas.findIndex((item) => item.slug === slug);
|
||||
const to = from + delta;
|
||||
if (from < 0 || to < 0 || to >= cinemas.length) return cinemas;
|
||||
@@ -79,6 +101,8 @@ type CinemaListProps = {
|
||||
onSelect: (slug: string) => void;
|
||||
onReorder: (next: Cinema[]) => void;
|
||||
onSaveOrder: () => void;
|
||||
/** ตั้งประเภทให้หลายโรงพร้อมกัน (slug ที่กรองอยู่, ประเภทใหม่) */
|
||||
onBulkVenue?: (slugs: string[], venue: VenueType) => void;
|
||||
};
|
||||
|
||||
const modeButtonClass = (active: boolean) =>
|
||||
@@ -97,14 +121,27 @@ export function CinemaList({
|
||||
onSelect,
|
||||
onReorder,
|
||||
onSaveOrder,
|
||||
onBulkVenue,
|
||||
}: CinemaListProps) {
|
||||
const [mode, setMode] = useState<SortMode>("manual");
|
||||
const [venueFilter, setVenueFilter] = useState<VenueFilter>("all");
|
||||
const [query, setQuery] = useState("");
|
||||
const [bulkVenue, setBulkVenue] = useState<VenueType>(VENUE_TYPES[0]);
|
||||
const [dragSlug, setDragSlug] = useState<string | null>(null);
|
||||
const [overSlug, setOverSlug] = useState<string | null>(null);
|
||||
|
||||
const venueCounts = useMemo(() => countByVenue(cinemas), [cinemas]);
|
||||
|
||||
const filtered = useMemo(
|
||||
() => filterAdminCinemas(cinemas, { venue: venueFilter, query }),
|
||||
[cinemas, venueFilter, query],
|
||||
);
|
||||
|
||||
const isFiltered = venueFilter !== "all" || query.trim() !== "";
|
||||
|
||||
const visible = useMemo(
|
||||
() => (mode === "thai" ? sortCinemasByName(cinemas) : cinemas),
|
||||
[cinemas, mode],
|
||||
() => (mode === "thai" ? sortCinemasByName(filtered) : filtered),
|
||||
[filtered, mode],
|
||||
);
|
||||
|
||||
function handleDrop(event: React.DragEvent<HTMLLIElement>, toSlug: string) {
|
||||
@@ -139,6 +176,85 @@ export function CinemaList({
|
||||
</button>
|
||||
</div>
|
||||
|
||||
{/* ค้นหา + กรองตามประเภทโรงหนัง (ชั้นกรองที่ 1 บนหน้าแรก) */}
|
||||
<input
|
||||
type="search"
|
||||
value={query}
|
||||
onChange={(event) => setQuery(event.target.value)}
|
||||
placeholder="ค้นชื่อหรือ slug…"
|
||||
aria-label="ค้นหาโรงหนัง"
|
||||
className="w-full rounded-lg border border-[#303030] bg-[#141414] px-2 py-1.5 text-[12px] text-[#E5E5E5] placeholder:text-[#666] focus:border-[#A92626] focus:outline-none"
|
||||
/>
|
||||
<div className="flex flex-wrap gap-1">
|
||||
{(
|
||||
[
|
||||
["all", "ทั้งหมด", cinemas.length],
|
||||
...VENUE_TYPES.map(
|
||||
(venue) =>
|
||||
[venue, venueShort[venue], venueCounts[venue]] as const,
|
||||
),
|
||||
["unset", "ยังไม่จัด", venueCounts.unset] as const,
|
||||
] as const
|
||||
).map(([value, label, count]) => {
|
||||
const active = venueFilter === value;
|
||||
return (
|
||||
<button
|
||||
key={value}
|
||||
type="button"
|
||||
aria-pressed={active}
|
||||
onClick={() => setVenueFilter(value as VenueFilter)}
|
||||
className={`rounded-md border px-1.5 py-0.5 text-[10px] transition ${
|
||||
active
|
||||
? "border-[#A92626] bg-[#242424] text-[#D47272]"
|
||||
: "border-[#303030] text-[#999] hover:border-[#A92626]/60 hover:text-white"
|
||||
}`}
|
||||
>
|
||||
{label} {count}
|
||||
</button>
|
||||
);
|
||||
})}
|
||||
</div>
|
||||
|
||||
{onBulkVenue && isFiltered ? (
|
||||
<div className="rounded-lg border border-[#303030] bg-[#141414] p-2">
|
||||
<p className="text-[11px] leading-[1.6] text-[#999]">
|
||||
ตั้งประเภทให้ {visible.length} โรงที่กรองอยู่
|
||||
</p>
|
||||
<div className="mt-1 flex items-center gap-1">
|
||||
<select
|
||||
value={bulkVenue}
|
||||
aria-label="เลือกประเภทที่จะตั้งให้ทั้งกลุ่ม"
|
||||
onChange={(event) =>
|
||||
setBulkVenue(event.target.value as VenueType)
|
||||
}
|
||||
className="min-w-0 flex-1 rounded-md border border-[#303030] bg-[#1B1B1B] px-1.5 py-1 text-[11px] text-[#E5E5E5] focus:border-[#A92626] focus:outline-none"
|
||||
>
|
||||
{VENUE_TYPES.map((venue) => (
|
||||
<option key={venue} value={venue}>
|
||||
{venue}
|
||||
</option>
|
||||
))}
|
||||
</select>
|
||||
<button
|
||||
type="button"
|
||||
disabled={visible.length === 0}
|
||||
onClick={() =>
|
||||
onBulkVenue(
|
||||
visible.map((cinema) => cinema.slug),
|
||||
bulkVenue,
|
||||
)
|
||||
}
|
||||
className="rounded-md bg-[#8F0808] px-2 py-1 text-[11px] transition hover:bg-[#a30a0a] disabled:opacity-50"
|
||||
>
|
||||
ใช้
|
||||
</button>
|
||||
</div>
|
||||
<p className="mt-1 text-[10px] leading-[1.5] text-[#777]">
|
||||
ต้องกด "บันทึกทั้งหมด" อีกครั้งเพื่อบันทึกลงไฟล์
|
||||
</p>
|
||||
</div>
|
||||
) : null}
|
||||
|
||||
{mode === "thai" ? (
|
||||
<div className="rounded-lg border border-[#303030] bg-[#141414] p-2 text-[11px] leading-[1.7] text-[#999]">
|
||||
เรียงตามชื่อไทย ก-ฮ · โหมดนี้ลากสลับไม่ได้
|
||||
@@ -155,7 +271,9 @@ export function CinemaList({
|
||||
</div>
|
||||
) : (
|
||||
<p className="px-1 text-[11px] leading-[1.6] text-[#777]">
|
||||
ลากชื่อเพื่อสลับตำแหน่ง หรือกด ↑ ↓ ทีละขั้น
|
||||
{isFiltered
|
||||
? "กำลังกรองอยู่ — ล้างตัวกรองก่อนจึงจะลาก/เลื่อนลำดับได้"
|
||||
: "ลากชื่อเพื่อสลับตำแหน่ง หรือกด ↑ ↓ ทีละขั้น"}
|
||||
</p>
|
||||
)}
|
||||
|
||||
@@ -178,7 +296,7 @@ export function CinemaList({
|
||||
return (
|
||||
<li
|
||||
key={item.slug}
|
||||
draggable={mode === "manual"}
|
||||
draggable={mode === "manual" && !isFiltered}
|
||||
onDragStart={(event) => {
|
||||
setDragSlug(item.slug);
|
||||
event.dataTransfer.effectAllowed = "move";
|
||||
@@ -191,7 +309,9 @@ export function CinemaList({
|
||||
setOverSlug(item.slug);
|
||||
}}
|
||||
onDragLeave={() => {
|
||||
setOverSlug((current) => (current === item.slug ? null : current));
|
||||
setOverSlug((current) =>
|
||||
current === item.slug ? null : current,
|
||||
);
|
||||
}}
|
||||
onDrop={(event) => handleDrop(event, item.slug)}
|
||||
onDragEnd={() => {
|
||||
@@ -201,13 +321,17 @@ export function CinemaList({
|
||||
className={`group flex items-center gap-1 rounded-lg pr-1 transition ${
|
||||
isSelected ? "bg-[#242424]" : "hover:bg-[#1B1B1B]"
|
||||
} ${isDragging ? "opacity-40" : ""} ${
|
||||
isOver ? "outline outline-2 outline-offset-[-2px] outline-[#A92626]" : ""
|
||||
isOver
|
||||
? "outline outline-2 outline-offset-[-2px] outline-[#A92626]"
|
||||
: ""
|
||||
} ${mode === "manual" ? "cursor-grab active:cursor-grabbing" : ""}`}
|
||||
>
|
||||
<span
|
||||
aria-hidden="true"
|
||||
className={`pl-1 ${
|
||||
mode === "manual" ? "text-[#555] group-hover:text-[#999]" : "text-transparent"
|
||||
mode === "manual"
|
||||
? "text-[#555] group-hover:text-[#999]"
|
||||
: "text-transparent"
|
||||
}`}
|
||||
>
|
||||
<IconGripVertical size={14} />
|
||||
@@ -216,20 +340,39 @@ export function CinemaList({
|
||||
type="button"
|
||||
onClick={() => onSelect(item.slug)}
|
||||
className={`min-w-0 flex-1 py-2 text-left text-sm transition ${
|
||||
isSelected ? "text-[#D47272]" : "text-[#B3B3B3] hover:text-white"
|
||||
isSelected
|
||||
? "text-[#D47272]"
|
||||
: "text-[#B3B3B3] hover:text-white"
|
||||
}`}
|
||||
>
|
||||
<span className="block truncate">{item.name_th || item.name}</span>
|
||||
<span className="block truncate text-[10px] text-[#777]">{item.slug}</span>
|
||||
<span className="block truncate">
|
||||
{item.name_th || item.name}
|
||||
</span>
|
||||
<span className="flex items-center gap-1">
|
||||
<span className="block min-w-0 flex-1 truncate text-[10px] text-[#777]">
|
||||
{item.slug}
|
||||
</span>
|
||||
<span
|
||||
className={`shrink-0 rounded border px-1 text-[9px] ${
|
||||
item.venue_type
|
||||
? "border-[#303030] text-[#999]"
|
||||
: "border-[#8F0808]/60 text-[#D47272]"
|
||||
}`}
|
||||
>
|
||||
{item.venue_type ? venueShort[item.venue_type] : "ยังไม่จัด"}
|
||||
</span>
|
||||
</span>
|
||||
</button>
|
||||
{mode === "manual" ? (
|
||||
{mode === "manual" && !isFiltered ? (
|
||||
<span className="flex flex-col">
|
||||
<button
|
||||
type="button"
|
||||
className={arrowButtonClass}
|
||||
aria-label={`เลื่อน ${item.name_th || item.name} ขึ้น`}
|
||||
disabled={index === 0}
|
||||
onClick={() => onReorder(shiftCinema(cinemas, item.slug, -1))}
|
||||
onClick={() =>
|
||||
onReorder(shiftCinema(cinemas, item.slug, -1))
|
||||
}
|
||||
>
|
||||
<IconArrowUp size={13} />
|
||||
</button>
|
||||
@@ -238,7 +381,9 @@ export function CinemaList({
|
||||
className={arrowButtonClass}
|
||||
aria-label={`เลื่อน ${item.name_th || item.name} ลง`}
|
||||
disabled={index === visible.length - 1}
|
||||
onClick={() => onReorder(shiftCinema(cinemas, item.slug, 1))}
|
||||
onClick={() =>
|
||||
onReorder(shiftCinema(cinemas, item.slug, 1))
|
||||
}
|
||||
>
|
||||
<IconArrowDown size={13} />
|
||||
</button>
|
||||
@@ -247,6 +392,11 @@ export function CinemaList({
|
||||
</li>
|
||||
);
|
||||
})}
|
||||
{visible.length === 0 ? (
|
||||
<li className="px-2 py-3 text-center text-[11px] text-[#777]">
|
||||
ไม่พบโรงหนังตามตัวกรองนี้
|
||||
</li>
|
||||
) : null}
|
||||
</ul>
|
||||
</div>
|
||||
);
|
||||
|
||||
@@ -6,6 +6,9 @@ import {
|
||||
hasVenue,
|
||||
listOtherCinemas,
|
||||
type Cinema,
|
||||
filterAdminCinemas,
|
||||
setVenueForSlugs,
|
||||
venueCounts,
|
||||
} from "./cinemas";
|
||||
import { filterCinemas } from "./search";
|
||||
|
||||
@@ -98,3 +101,87 @@ describe("hasVenue / filterCinemas (ชั้นกรองประเภท
|
||||
).toEqual([local]);
|
||||
});
|
||||
});
|
||||
|
||||
describe("หลังบ้าน: ตัวกรองประเภทโรงหนัง", () => {
|
||||
const base = {
|
||||
slug: "base",
|
||||
name: "X",
|
||||
tags: [],
|
||||
location_label: "",
|
||||
coordinates: null,
|
||||
description: "",
|
||||
map_url: null,
|
||||
address_lines: [],
|
||||
transport: [],
|
||||
contacts: [],
|
||||
payments: [],
|
||||
photos: [],
|
||||
} as Cinema;
|
||||
const list: Cinema[] = [
|
||||
{
|
||||
...base,
|
||||
slug: "a-local",
|
||||
name: "Alpha",
|
||||
name_th: "อัลฟา",
|
||||
venue_type: "โรงภาพยนตร์ท้องถิ่น",
|
||||
},
|
||||
{ ...base, slug: "b-indie", name: "Beta", venue_type: "โรงภาพยนตร์อินดี้" },
|
||||
{ ...base, slug: "c-group", name: "Gamma", venue_type: "กลุ่มคนฉายหนัง" },
|
||||
{ ...base, slug: "d-none", name: "Delta" },
|
||||
];
|
||||
|
||||
it("กรอง all / unset / แต่ละประเภท", () => {
|
||||
expect(filterAdminCinemas(list, { venue: "all", query: "" })).toHaveLength(
|
||||
4,
|
||||
);
|
||||
expect(
|
||||
filterAdminCinemas(list, { venue: "unset", query: "" }).map(
|
||||
(c) => c.slug,
|
||||
),
|
||||
).toEqual(["d-none"]);
|
||||
expect(
|
||||
filterAdminCinemas(list, { venue: "โรงภาพยนตร์อินดี้", query: "" }).map(
|
||||
(c) => c.slug,
|
||||
),
|
||||
).toEqual(["b-indie"]);
|
||||
});
|
||||
|
||||
it("ค้นด้วยชื่อไทย/อังกฤษ/slug ร่วมกับตัวกรอง", () => {
|
||||
expect(
|
||||
filterAdminCinemas(list, { venue: "all", query: "อัลฟา" }).map(
|
||||
(c) => c.slug,
|
||||
),
|
||||
).toEqual(["a-local"]);
|
||||
expect(
|
||||
filterAdminCinemas(list, { venue: "โรงภาพยนตร์ท้องถิ่น", query: "beta" }),
|
||||
).toHaveLength(0);
|
||||
expect(
|
||||
filterAdminCinemas(list, { venue: "all", query: " GAMMA " })[0]?.slug,
|
||||
).toBe("c-group");
|
||||
});
|
||||
|
||||
it("setVenueForSlugs ตั้งค่าเฉพาะ slug ที่ระบุ และไม่แก้ตัวเดิม", () => {
|
||||
const next = setVenueForSlugs(list, ["d-none", "b-indie"], "กลุ่มคนฉายหนัง");
|
||||
expect(next.find((c) => c.slug === "d-none")?.venue_type).toBe(
|
||||
"กลุ่มคนฉายหนัง",
|
||||
);
|
||||
expect(next.find((c) => c.slug === "b-indie")?.venue_type).toBe(
|
||||
"กลุ่มคนฉายหนัง",
|
||||
);
|
||||
expect(next.find((c) => c.slug === "a-local")?.venue_type).toBe(
|
||||
"โรงภาพยนตร์ท้องถิ่น",
|
||||
);
|
||||
expect(list.find((c) => c.slug === "d-none")?.venue_type).toBeUndefined();
|
||||
expect(setVenueForSlugs(list, [], "โรงภาพยนตร์อินดี้")).toBe(list);
|
||||
});
|
||||
|
||||
it("venueCounts นับครบทุกช่อง", () => {
|
||||
expect(venueCounts(list)).toEqual({
|
||||
all: 4,
|
||||
unset: 1,
|
||||
โรงภาพยนตร์ท้องถิ่น: 1,
|
||||
โรงภาพยนตร์อินดี้: 1,
|
||||
กลุ่มคนฉายหนัง: 1,
|
||||
});
|
||||
});
|
||||
});
|
||||
@@ -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,
|
||||
|
||||
@@ -264,6 +264,18 @@ export default function AdminRoute() {
|
||||
<p className="text-xs text-[#999]">
|
||||
{store.cinemas.length} โรงหนัง · {terms.length} คำศัพท์ ·{" "}
|
||||
{store.site.footer.length} ไอคอน footer
|
||||
{" · "}
|
||||
{VENUE_TYPES.map((venue) => {
|
||||
const count = store.cinemas.filter(
|
||||
(item) => item.venue_type === venue,
|
||||
).length;
|
||||
return `${count} ${venue.replace("โรงภาพยนตร์", "")}${
|
||||
venue === VENUE_TYPES[VENUE_TYPES.length - 1] ? "" : " · "
|
||||
}`;
|
||||
}).join("")}
|
||||
{" · "}
|
||||
{store.cinemas.filter((item) => !item.venue_type).length}{" "}
|
||||
ยังไม่จัดประเภท
|
||||
</p>
|
||||
</div>
|
||||
<div className="flex items-center gap-2">
|
||||
@@ -335,6 +347,16 @@ export default function AdminRoute() {
|
||||
onSelect={setSelected}
|
||||
onReorder={updateCinemas}
|
||||
onSaveOrder={() => void save({ cinemas: store.cinemas })}
|
||||
onBulkVenue={(slugs, venue) => {
|
||||
const target = new Set(slugs);
|
||||
updateCinemas(
|
||||
store.cinemas.map((item) =>
|
||||
target.has(item.slug)
|
||||
? { ...item, venue_type: venue }
|
||||
: item,
|
||||
),
|
||||
);
|
||||
}}
|
||||
/>
|
||||
</aside>
|
||||
|
||||
@@ -933,6 +955,37 @@ export default function AdminRoute() {
|
||||
>
|
||||
+ เพิ่มคำศัพท์
|
||||
</button>
|
||||
{VENUE_TYPES.map((venue) => {
|
||||
const key = `venues.${venue}`;
|
||||
const exists = store.site.terms.some((term) => term.key === key);
|
||||
return (
|
||||
<button
|
||||
key={key}
|
||||
type="button"
|
||||
disabled={exists}
|
||||
className={`${buttonClass} disabled:opacity-40`}
|
||||
onClick={() =>
|
||||
updateSite({
|
||||
...store.site,
|
||||
terms: [
|
||||
...store.site.terms,
|
||||
{
|
||||
key,
|
||||
values: Object.fromEntries(
|
||||
locales.map((locale) => [
|
||||
locale.code,
|
||||
locale.code === "th" ? venue : "",
|
||||
]),
|
||||
),
|
||||
},
|
||||
],
|
||||
})
|
||||
}
|
||||
>
|
||||
{exists ? "มีแล้ว" : "+ คำแปลตัวกรอง"}: {venue}
|
||||
</button>
|
||||
);
|
||||
})}
|
||||
</div>
|
||||
|
||||
<div className="overflow-x-auto rounded-xl border border-[#242424]">
|
||||
|
||||
@@ -39,6 +39,16 @@
|
||||
โหมดเรียง ก-ฮ เป็นแค่การดู — กด **ใช้ลำดับ ก-ฮ นี้** เพื่อเอาลำดับนั้นมาใช้จริง
|
||||
เมื่อลำดับเปลี่ยนจะมีปุ่ม **บันทึกลำดับใหม่** (หรือกด "บันทึกทั้งหมด" ก็ได้)
|
||||
|
||||
### กรอง/ค้นหาโรงหนังในลิสต์ (ตัวกรองชั้นแรก)
|
||||
|
||||
เหนือรายการมี **ช่องค้นหา** (ชื่อไทย/อังกฤษ/slug) และ **ชิปกรองประเภท** พร้อมจำนวน:
|
||||
`ทั้งหมด · ท้องถิ่น · อินดี้ · กลุ่ม · ยังไม่จัด`
|
||||
|
||||
- แต่ละแถวมี **ป้ายประเภท** ท้ายชื่อ · โรงที่ยังไม่ตั้งประเภทจะเป็นป้ายแดง "ยังไม่จัด"
|
||||
- **ตั้งประเภททีละกลุ่ม**: กรอง/ค้นหาให้เหลือเฉพาะโรงที่ต้องการ → กล่อง *"ตั้งประเภทให้ N โรงที่กรองอยู่"* → เลือกประเภท → **ใช้** → แล้วกด **บันทึกทั้งหมด** (ถ้าไม่บันทึกแล้วออกจากหน้า การเปลี่ยนจะหาย)
|
||||
- ตอนกรองอยู่จะ **ลากสลับลำดับไม่ได้** (กันเรียงผิด) — ล้างตัวกรองก่อนจึงจะลากได้
|
||||
- คำแปลชื่อประเภทแก้ได้ที่แท็บ **คำศัพท์หลายภาษา** → ปุ่มลัด `+ คำแปลตัวกรอง: <ประเภท>` (สร้างคีย์ `venues.<ประเภท>` ให้)
|
||||
|
||||
> **หน้าแรกสลับการ์ดเองทุกวัน** — ลำดับที่จัดไว้จะถูกใช้เป็น "ลำดับฐาน" แล้วระบบหมุน/สลับให้อัตโนมัติ
|
||||
> เพื่อไม่ให้โรงใดอยู่ตำแหน่งเดิมสองวันติดกัน (ทุกคนเห็นเหมือนกันในวันเดียวกัน) — รายละเอียดดู DESIGN.md หัวข้อ "ลำดับการ์ดหน้าแรก"
|
||||
|
||||
|
||||
Reference in new issue
Block a user