mirror of
https://github.com/Crosstalk-Solutions/project-nomad.git
synced 2026-06-01 09:06:48 +02:00
useEmbedJobs already polls every 2s while jobs are active (and 30s when idle) and auto-invalidates Stored Files when the queue drains. The manual Refresh button was a no-op signal — it just confuses users who click it and see no change. Per-job 'last activity Xs ago' lines remain as the live-recency indicator. Stacks on feat/kb-job-status-pill (#893) since the Refresh button only exists in that branch.
91 lines
3.0 KiB
TypeScript
91 lines
3.0 KiB
TypeScript
import { useEffect, useState } from 'react'
|
|
import useEmbedJobs from '~/hooks/useEmbedJobs'
|
|
import HorizontalBarChart from './HorizontalBarChart'
|
|
import StyledSectionHeader from './StyledSectionHeader'
|
|
import {
|
|
JOB_HEALTH_DISPLAY,
|
|
computeJobHealth,
|
|
formatTimeAgo,
|
|
} from '~/lib/kb_job_health_display'
|
|
|
|
interface ActiveEmbedJobsProps {
|
|
withHeader?: boolean
|
|
}
|
|
|
|
const ActiveEmbedJobs = ({ withHeader = false }: ActiveEmbedJobsProps) => {
|
|
const { data: jobs } = useEmbedJobs()
|
|
|
|
// Re-render every 5s to keep per-job "last activity Xs ago" timestamps fresh.
|
|
const [tick, setTick] = useState(() => Date.now())
|
|
useEffect(() => {
|
|
const id = setInterval(() => setTick(Date.now()), 5000)
|
|
return () => clearInterval(id)
|
|
}, [])
|
|
|
|
return (
|
|
<>
|
|
{withHeader && (
|
|
<StyledSectionHeader title="Processing Queue" className="mt-12 mb-4" />
|
|
)}
|
|
|
|
<div className="space-y-4">
|
|
{jobs && jobs.length > 0 ? (
|
|
jobs.map((job) => {
|
|
const health = computeJobHealth({
|
|
status: job.status,
|
|
progress: job.progress,
|
|
lastBatchAt: job.lastBatchAt,
|
|
startedAt: job.startedAt,
|
|
now: tick,
|
|
})
|
|
const display = JOB_HEALTH_DISPLAY[health]
|
|
const lastActivityMs = job.lastBatchAt ?? job.startedAt
|
|
return (
|
|
<div
|
|
key={job.jobId}
|
|
className="bg-desert-white rounded-lg p-4 border border-desert-stone-light shadow-sm hover:shadow-lg transition-shadow"
|
|
>
|
|
<div className="flex items-center gap-3 mb-2">
|
|
<span
|
|
className={`inline-block w-2.5 h-2.5 rounded-full ${display.dot}`}
|
|
aria-label={display.ariaLabel}
|
|
title={display.ariaLabel}
|
|
/>
|
|
<span className="text-sm font-medium text-text-primary">
|
|
{display.label}
|
|
</span>
|
|
{lastActivityMs !== undefined && (
|
|
<span className="text-xs text-text-muted">
|
|
· last activity {formatTimeAgo(lastActivityMs, tick)}
|
|
</span>
|
|
)}
|
|
{typeof job.chunks === 'number' && job.chunks > 0 && (
|
|
<span className="text-xs text-text-muted">
|
|
· {job.chunks.toLocaleString()} chunks
|
|
</span>
|
|
)}
|
|
</div>
|
|
<HorizontalBarChart
|
|
items={[
|
|
{
|
|
label: job.fileName,
|
|
value: job.progress,
|
|
total: '100%',
|
|
used: `${job.progress}%`,
|
|
type: job.status,
|
|
},
|
|
]}
|
|
/>
|
|
</div>
|
|
)
|
|
})
|
|
) : (
|
|
<p className="text-text-muted">No files are currently being processed</p>
|
|
)}
|
|
</div>
|
|
</>
|
|
)
|
|
}
|
|
|
|
export default ActiveEmbedJobs
|