File size: 1,770 Bytes
2eb87e3
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
import { CheckCircle2, Clock, Loader2 } from "lucide-react";
import type { ScanJobState } from "@/shared/types";
import { formatRelativeTime } from "../shared/lib/format";

export function StatusBadge({
  state,
  finishedAt,
}: {
  state: ScanJobState | null | undefined;
  finishedAt?: string | null;
}) {
  if (state === "completed") {
    return (
      <span className="inline-flex items-center gap-1 rounded-full bg-success-bg px-2 py-0.5 text-xs font-medium text-success-ink">
        <CheckCircle2 size={12} />
        {finishedAt ? `Scanned ${formatRelativeTime(finishedAt)}` : "Completed"}
      </span>
    );
  }
  if (state === "scanning" || state === "dispatching") {
    return (
      <span className="inline-flex items-center gap-1.5 rounded-full bg-running-bg px-2 py-0.5 text-xs font-medium text-running-ink">
        <span className="relative flex h-1.5 w-1.5">
          <span className="absolute inline-flex h-full w-full animate-ping rounded-full bg-running opacity-60 motion-reduce:animate-none" />
          <span className="relative inline-flex h-1.5 w-1.5 rounded-full bg-running" />
        </span>
        Scanning
      </span>
    );
  }
  // queued / failed / null → Waiting(fish No.491:scanning 独立展示,failed 仍归 waiting)
  return (
    <span className="inline-flex items-center gap-1.5 rounded-full bg-surface-sunken px-2 py-0.5 text-xs font-medium text-ink-secondary">
      <Clock size={12} /> Waiting to be scanned
    </span>
  );
}

export function ScanningSpinner({ label = "Loading…" }: { label?: string }) {
  return (
    <div className="flex items-center gap-2 text-sm text-ink-secondary" role="status">
      <Loader2 size={16} className="animate-spin text-accent-600" />
      {label}
    </div>
  );
}