Add image art direction, Thai date picker on week board, sturdier image download

- Share IMAGE_ART_DIRECTION between editable image prompts and queued post drafts
- Use ThaiDateTimePicker for week board planning; a11y, clear action, mobile layout
- Show planned day in Thai format in the generation queue
- Wait longer for ChatGPT image download and handle the download menu item

Co-Authored-By: Claude Sonnet 5.5 <noreply@anthropic.com>
This commit is contained in:
Loma Bot Ops
2026-11-23 23:14:13 +07:00
parent 7d6f42b964
commit 7f1a9face1
8 changed files with 52 additions and 18 deletions
+7 -1
View File
@@ -13,6 +13,12 @@ function duration(job: PostJobView): string {
return `${Math.floor(seconds / 60)} นาที ${seconds % 60} วินาที`;
}
function formatPlannedDay(value: string): string {
const [year, month, day] = value.split("-").map(Number);
if (!year || !month || !day) return value;
return new Intl.DateTimeFormat("th-TH", { day: "numeric", month: "long", year: "numeric", timeZone: "Asia/Bangkok" }).format(new Date(Date.UTC(year, month - 1, day, -7)));
}
/** Server-persisted jobs are rediscovered after reload; the browser never executes the pipeline. */
export function PostGenerationQueue({ pageId, targets, plannedDay, initialTopic }: {
pageId: string; targets: ("FACEBOOK" | "INSTAGRAM")[]; plannedDay: string; initialTopic: string;
@@ -81,7 +87,7 @@ export function PostGenerationQueue({ pageId, targets, plannedDay, initialTopic
<span>หัวข้อโพสต์ที่จะเข้าคิว</span>
<textarea className="textarea" rows={2} value={topic} disabled={busy} maxLength={1000} onChange={(event) => { setTopic(event.target.value); requestKey.current = null; }} placeholder="เช่น แนะนำเมนูใหม่ พร้อมราคาและจุดเด่นที่ต้องการสื่อ" />
</label>
<p className="text-[12px] text-ink-2">ฉบับร่างสำหรับ {targets.length ? targets.map((target) => target === "FACEBOOK" ? "Facebook" : "Instagram").join(" + ") : "ยังไม่ได้เลือกช่องทาง"}{plannedDay ? ` · วันวางแผน ${plannedDay}` : " · ยังไม่วางวัน"}</p>
<p className="text-[12px] text-ink-2">ฉบับร่างสำหรับ {targets.length ? targets.map((target) => target === "FACEBOOK" ? "Facebook" : "Instagram").join(" + ") : "ยังไม่ได้เลือกช่องทาง"}{plannedDay ? ` · วันวางแผน ${formatPlannedDay(plannedDay)}` : " · ยังไม่วางวัน"}</p>
<div className="flex flex-wrap gap-2 items-center">
<button type="button" className="btn btn-primary btn-sm" disabled={busy || !topic.trim() || targets.length === 0} onClick={enqueue}>
<Icon name="sparkle" size={15} /> {busy ? "กำลังรับงาน…" : "เข้าคิวสร้างโพสต์"}
+10 -5
View File
@@ -20,6 +20,7 @@ function bangkokToday() {
export function ThaiDateTimePicker({ value, onChange, dateOnly = false, disabled = false, label = "เลือกวันและเวลา" }: { value: string; onChange: (value: string) => void; dateOnly?: boolean; disabled?: boolean; label?: string }) {
const id = useId();
const headingId = `${id}-heading`;
const rootRef = useRef<HTMLDivElement>(null);
const selected = parseValue(value);
const [today] = useState(() => bangkokToday());
@@ -66,16 +67,20 @@ export function ThaiDateTimePicker({ value, onChange, dateOnly = false, disabled
setOpen((current) => !current);
}
return <div className="thai-picker" ref={rootRef}>
<button type="button" className="thai-picker-trigger num" disabled={disabled} aria-expanded={open} aria-controls={id} onClick={togglePicker}>
return <div className="thai-picker" ref={rootRef} lang="th">
<button type="button" className="thai-picker-trigger num" disabled={disabled} aria-expanded={open} aria-controls={id} aria-haspopup="dialog" aria-label={label} onClick={togglePicker}>
<span className={selected ? "" : "text-ink-4"}>{display}</span><Icon name="calendar" size={19} />
</button>
{open && <div className="thai-picker-popover" id={id} role="dialog" aria-label={label}>
<div className="thai-picker-head"><button type="button" aria-label="เดือนก่อนหน้า" onClick={() => moveMonth(-1)}>‹</button><strong>{THAI_MONTHS[view.month]} {view.year + 543}</strong><button type="button" aria-label="เดือนถัดไป" onClick={() => moveMonth(1)}>›</button></div>
{open && <div className="thai-picker-popover" id={id} role="dialog" aria-modal="false" aria-labelledby={headingId}>
<div className="thai-picker-head"><button type="button" aria-label="เดือนก่อนหน้า" onClick={() => moveMonth(-1)}>‹</button><strong id={headingId}>{THAI_MONTHS[view.month]} {view.year + 543}</strong><button type="button" aria-label="เดือนถัดไป" onClick={() => moveMonth(1)}>›</button></div>
<div className="thai-picker-week" aria-hidden="true">{THAI_DAYS.map((day) => <span key={day}>{day}</span>)}</div>
<div className="thai-picker-grid">{days.map((day, index) => day ? <button type="button" key={index} aria-label={`${day} ${THAI_MONTHS[view.month]} ${view.year + 543}`} aria-pressed={selected?.year === view.year && selected.month === view.month && selected.day === day} data-today={today.year === view.year && today.month === view.month && today.day === day || undefined} onClick={() => pickDay(day)}>{day}</button> : <span key={index} />)}</div>
{!dateOnly && <div className="thai-picker-time"><Icon name="clock" size={17} /><span>เวลาไทย</span><select aria-label="ชั่วโมง" value={selected?.hour ?? 9} onChange={(event) => changeTime("hour", +event.target.value)}>{Array.from({ length: 24 }, (_, hour) => <option key={hour} value={hour}>{pad(hour)}</option>)}</select><span>:</span><select aria-label="นาที" value={selected?.minute ?? 0} onChange={(event) => changeTime("minute", +event.target.value)}>{Array.from({ length: 60 }, (_, minute) => <option key={minute} value={minute}>{pad(minute)}</option>)}</select><span>น.</span></div>}
<div className="thai-picker-foot"><button type="button" onClick={pickToday}>วันนี้</button>{!dateOnly && <button type="button" className="btn btn-primary btn-sm" onClick={() => setOpen(false)}>เรียบร้อย</button>}</div>
<div className="thai-picker-foot">
<button type="button" className="thai-picker-text-action" onClick={pickToday}>วันนี้</button>
{selected && <button type="button" className="thai-picker-text-action" onClick={() => { onChange(""); setOpen(false); }}>ล้างวันที่</button>}
{!dateOnly && <button type="button" className="btn btn-primary btn-sm" onClick={() => setOpen(false)}>เรียบร้อย</button>}
</div>
</div>}
</div>;
}
+2 -1
View File
@@ -9,6 +9,7 @@ import { addDays, bkkMidnight } from "@/lib/board";
import { Icon } from "./Icon";
import { POST_STATUS_META, StatusPill } from "./ui";
import { useToast } from "./Toast";
import { ThaiDateTimePicker } from "./ThaiDateTimePicker";
interface BoardPost {
id: string;
@@ -74,7 +75,7 @@ export function WeekBoard({ week, today, posts, tray, editablePageIds, nextId }:
{movable && <details className="plan-date">
<summary><Icon name="calendar" size={13} /><span>{p.day ? "เปลี่ยนวัน" : "เลือกวัน"}</span><Icon name="chevron" size={12} /></summary>
<div className="plan-date-popover">
<label className="field"><span>วันวางแผน</span><input aria-label={`วางวัน ${p.title}`} type="date" className="input" value={p.day ?? ""} disabled={busy} onChange={e => void plan(p.id, e.target.value || null)} /></label>
<div className="field"><span>วันวางแผน</span><ThaiDateTimePicker dateOnly label={`วางวัน ${p.title}`} value={p.day ?? ""} disabled={busy} onChange={(day) => void plan(p.id, day || null)} /></div>
{p.day && <button type="button" className="text-[12px] text-ink-3 mt-3 hover:text-blue" disabled={busy} onClick={() => void plan(p.id, null)}>ย้ายกลับคิวที่ยังไม่วางแผน</button>}
</div>
</details>}