- บทความจากหลังบ้าน: /for-film-lovers, /for-cinemas (ArticlePage + ArticleEditor แบบบล็อกย่อหน้า/รูป) - แชร์: ปุ่มบนการ์ดและท้ายหน้ารายละเอียด · ลิงก์ย่อ /c/<slug> (302) · ธีมแก้วตาม DESIGN.md - PWA: manifest/sw/offline + ถอดการล็อกซูม (WCAG 1.4.4) + touch target ≥44px - แอนิเมชัน reveal: IntersectionObserver + gate ด้วย html.fx-motion · เคารพ prefers-reduced-motion - ค้นหา: normalize/ตัดวรรณยุกต์ + AND หลายคำ + จัดอันดับ · รองรับ /?q= จาก SearchAction - SEO: pageMeta (canonical/OG/Twitter) + JSON-LD (WebSite/Organization/BreadcrumbList/MovieTheater/Article) - ไม่ฝังโดเมนในโค้ด: origin มาจาก request (x-forwarded-host/proto) ทั้ง canonical, sitemap, robots, ลิงก์แชร์ - กัน AI: robots.txt (Nitro route, บล็อก AI 21 ตัว) + ai.txt + OG image 1200x630 - เอกสาร: README สรุปโปรเจกต์, DESIGN.md (motion/PWA/SEO/ข้อมูล), architecture.html, admin-guide - tests: 135 ผ่าน (16 ไฟล์)
130 lines
4.9 KiB
TypeScript
130 lines
4.9 KiB
TypeScript
import {
|
|
compactButtonClass,
|
|
inputClass,
|
|
labelClass,
|
|
} from "@/components/admin/form-styles";
|
|
import type { ArticleBlock } from "@/lib/content-types";
|
|
|
|
type ArticleBlockCardProps = {
|
|
block: ArticleBlock;
|
|
/** ตำแหน่งของบล็อก (0-based) — ใช้แสดงเลขและปิดปุ่มที่เกินขอบ */
|
|
index: number;
|
|
/** จำนวนบล็อกทั้งหมด — ใช้ปิดปุ่ม "เลื่อนลง" ที่บล็อกสุดท้าย */
|
|
total: number;
|
|
/** ส่งบล็อกที่แก้แล้วกลับไปทั้งก้อน (ชนิดถูกต้องตาม type ของบล็อก) */
|
|
onChange: (next: ArticleBlock) => void;
|
|
onMove: (direction: -1 | 1) => void;
|
|
onRemove: () => void;
|
|
};
|
|
|
|
/**
|
|
* การ์ดแก้ไขบทความหนึ่งบล็อก — ย่อหน้าหรือรูป
|
|
* แยกออกมาจาก ArticleEditor เพื่อให้แต่ละไฟล์มีขนาดอ่านไหว
|
|
*/
|
|
export function ArticleBlockCard({
|
|
block,
|
|
index,
|
|
total,
|
|
onChange,
|
|
onMove,
|
|
onRemove,
|
|
}: ArticleBlockCardProps) {
|
|
return (
|
|
<div className="rounded-xl border border-[#242424] bg-[#141414] p-4">
|
|
<div className="mb-3 flex flex-wrap items-center justify-between gap-2">
|
|
<span className="text-xs uppercase tracking-wide text-[#999]">
|
|
{block.type === "image" ? `รูปที่ ${index + 1}` : `ย่อหน้าที่ ${index + 1}`}
|
|
</span>
|
|
<div className="flex items-center gap-1.5">
|
|
<button
|
|
type="button"
|
|
className={compactButtonClass}
|
|
aria-label={`เลื่อนขึ้น (บล็อกที่ ${index + 1})`}
|
|
onClick={() => onMove(-1)}
|
|
disabled={index === 0}
|
|
>
|
|
↑
|
|
</button>
|
|
<button
|
|
type="button"
|
|
className={compactButtonClass}
|
|
aria-label={`เลื่อนลง (บล็อกที่ ${index + 1})`}
|
|
onClick={() => onMove(1)}
|
|
disabled={index === total - 1}
|
|
>
|
|
↓
|
|
</button>
|
|
<button
|
|
type="button"
|
|
className={compactButtonClass}
|
|
aria-label={`ลบบล็อกที่ ${index + 1}`}
|
|
onClick={onRemove}
|
|
>
|
|
ลบ
|
|
</button>
|
|
</div>
|
|
</div>
|
|
|
|
{block.type === "paragraph" ? (
|
|
<textarea
|
|
value={block.text}
|
|
onChange={(event) =>
|
|
onChange({ type: "paragraph", text: event.target.value })
|
|
}
|
|
rows={4}
|
|
placeholder="พิมพ์ย่อหน้าที่นี่ — เว้นบรรทัดใหม่ได้ ระบบจะแสดงตามที่พิมพ์"
|
|
className={inputClass}
|
|
/>
|
|
) : (
|
|
<div className="grid gap-3 md:grid-cols-[minmax(0,1fr)_180px]">
|
|
<div className="flex flex-col gap-3">
|
|
<label className={labelClass}>
|
|
ลิงก์รูป (URL หรือ /images/…)
|
|
<input
|
|
value={block.src}
|
|
onChange={(event) =>
|
|
onChange({ ...block, src: event.target.value })
|
|
}
|
|
placeholder="/images/house-cinema.jpg"
|
|
className={inputClass}
|
|
/>
|
|
</label>
|
|
<label className={labelClass}>
|
|
คำอธิบายรูป (alt) — จำเป็นต่อการเข้าถึง
|
|
<input
|
|
value={block.alt}
|
|
onChange={(event) =>
|
|
onChange({ ...block, alt: event.target.value })
|
|
}
|
|
placeholder="บรรยากาศภายในโรงหนัง"
|
|
className={inputClass}
|
|
/>
|
|
</label>
|
|
<label className={labelClass}>
|
|
คำบรรยายใต้รูป (ไม่ใส่ก็ได้)
|
|
<input
|
|
value={block.caption}
|
|
onChange={(event) =>
|
|
onChange({ ...block, caption: event.target.value })
|
|
}
|
|
className={inputClass}
|
|
/>
|
|
</label>
|
|
</div>
|
|
<div className="flex items-start justify-center rounded-lg border border-[#242424] bg-[#0D0D0D] p-2">
|
|
{block.src.trim() !== "" ? (
|
|
<img
|
|
src={block.src}
|
|
alt=""
|
|
className="max-h-[140px] w-full rounded-md object-cover"
|
|
/>
|
|
) : (
|
|
<span className="py-8 text-xs text-[#666]">ยังไม่ได้ใส่ลิงก์รูป</span>
|
|
)}
|
|
</div>
|
|
</div>
|
|
)}
|
|
</div>
|
|
);
|
|
}
|