Show milestone progress bar for post generation queue jobs
Add percentage-by-stage progress in the queue UI, a progress rendering test script, and clearer Chrome focus error details in the ChatGPT worker. Co-Authored-By: Claude Sonnet 5.5 <noreply@anthropic.com>
This commit is contained in:
@@ -3,7 +3,7 @@
|
||||
import { useEffect, useRef, useState } from "react";
|
||||
import Link from "next/link";
|
||||
import { withBase } from "@/lib/base-path";
|
||||
import { POST_JOB_STAGE, POST_JOB_STATUS, type PostJobView } from "@/lib/ai/post-queue-shared";
|
||||
import { POST_JOB_STAGE, POST_JOB_STATUS, postJobProgress, type PostJobView } from "@/lib/ai/post-queue-shared";
|
||||
import { Icon } from "./Icon";
|
||||
import { Notice } from "./ui";
|
||||
|
||||
@@ -93,12 +93,17 @@ export function PostGenerationQueue({ pageId, targets, plannedDay, initialTopic
|
||||
{pollError && <p role="status" className="text-[12px] text-ink-2">ยังอัปเดตคิวไม่ได้ ระบบกำลังลองเชื่อมต่อใหม่ งานที่รับไว้ยังอยู่ในคิว</p>}
|
||||
{jobs.length > 0 && <>
|
||||
<h4 className="font-semibold text-[13px] pt-2">งานล่าสุดของเพจนี้</h4>
|
||||
<p className="text-[12px] text-ink-2">เปอร์เซ็นต์อิงตามขั้นตอน อาจคงที่ระหว่างรอสร้างภาพ</p>
|
||||
<ul className="divide-y divide-line" aria-label="รายการคิวสร้างโพสต์">
|
||||
{jobs.map((job) => <li key={job.id} className="py-3 flex flex-col gap-1.5">
|
||||
<div className="flex flex-wrap items-start gap-2">
|
||||
<span className="font-medium text-[13px] flex-1 min-w-0 break-words">{job.topic}</span>
|
||||
<span role="status" className="text-[12px] text-ink-2">{POST_JOB_STATUS[job.status]}</span>
|
||||
</div>
|
||||
{job.status !== "CANCELLED" && job.status !== "FAILED" && <div className="flex items-center gap-3">
|
||||
<progress className="h-2 w-full flex-1 min-w-0 appearance-none overflow-hidden rounded-full bg-line [&::-webkit-progress-bar]:bg-line [&::-webkit-progress-value]:bg-blue [&::-moz-progress-bar]:bg-blue" value={postJobProgress(job)} max={100} aria-label={`ความคืบหน้าของ ${job.topic}`} aria-valuetext={`${postJobProgress(job)}% · ${POST_JOB_STAGE[job.stage] || POST_JOB_STATUS[job.status]}`} />
|
||||
<span className="text-[12px] font-semibold num text-ink-2">{postJobProgress(job)}%</span>
|
||||
</div>}
|
||||
{job.status === "RUNNING" && <p role="status" className="text-[12px] text-ink-2">{POST_JOB_STAGE[job.stage] || "กำลังทำงาน"}</p>}
|
||||
{job.error && <p className="text-[12px] text-danger-ink">{job.error}</p>}
|
||||
{job.status === "COMPLETED" && <div className="flex flex-wrap items-center gap-3">
|
||||
|
||||
@@ -7,7 +7,7 @@ export const POST_JOB_STATUS = {
|
||||
} as const;
|
||||
|
||||
export const POST_JOB_STAGE: Record<string, string> = {
|
||||
queued: "รอ worker รับงาน",
|
||||
queued: "รอเริ่มสร้างโพสต์",
|
||||
content: "Codex กำลังเขียนเนื้อหาและพรอมต์ภาพ",
|
||||
image: "ChatGPT กำลังสร้างภาพ",
|
||||
saving: "กำลังบันทึกฉบับร่าง",
|
||||
@@ -24,3 +24,10 @@ export interface PostJobView {
|
||||
startedAt: string | null;
|
||||
finishedAt: string | null;
|
||||
}
|
||||
|
||||
/** Milestones, not an estimate of the image model's internal rendering progress. */
|
||||
export function postJobProgress(job: Pick<PostJobView, "status" | "stage">): number {
|
||||
if (job.status === "COMPLETED") return 100;
|
||||
if (job.status === "QUEUED" || job.status === "CANCELLED") return 0;
|
||||
return ({ content: 10, image: 50, saving: 90 } as Record<string, number>)[job.stage] ?? 0;
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user