Blocks / Upload queue

Upload queue

Each file uploading: progress in blocks, cancel, retry, minimise; the total sent.

import { UploadQueue, uploadSummary } from "@forgeron/ui";
/01 → Default
Uploading 3 of 41.1 MB / 2.1 MB
  • Dock plan.pdf
    Done
  • Gate B at night.jpg
    46%
  • Invoices 2025.zip
    Too large
  • Tariffs 2027.xlsx
    Waiting
To R2 · moreau-drive
import { UploadQueue } from "@forgeron/ui";

export default function Default() {
  return (
    <div style={{ width: "100%", maxWidth: 380 }}>
      <UploadQueue
        footer="To R2 · moreau-drive"
        onCancel={() => {}}
        onRetry={() => {}}
        onCancelAll={() => {}}
        items={[
          { id: "1", name: "Dock plan.pdf", size: 240_000, progress: 1, status: "done" },
          {
            id: "2",
            name: "Gate B at night.jpg",
            size: 1_840_000,
            progress: 0.46,
            status: "uploading",
          },
          {
            id: "3",
            name: "Invoices 2025.zip",
            size: 812_000_000,
            progress: 0,
            status: "failed",
            error: "Too large",
          },
          { id: "4", name: "Tariffs 2027.xlsx", size: 52_400, progress: 0, status: "queued" },
        ]}
      />
    </div>
  );
}
/02 → Live

Drop files to upload them

// Pick files: the queue follows them, three at a time, until they are done. Cancel one, cancel
// all, retry a cancelled one. The upload is simulated; yours calls your storage.
import { Button, DropZone, UploadQueue, type UploadItem } from "@forgeron/ui";
import { useEffect, useRef, useState } from "react";

export default function Live() {
  const [items, setItems] = useState<UploadItem[]>([]);
  const timer = useRef<ReturnType<typeof setInterval> | null>(null);
  useEffect(
    () => () => {
      if (timer.current) clearInterval(timer.current);
    },
    [],
  );

  const tick = () =>
    setItems((all) => {
      let slots = 3;
      const next = all.map((u): UploadItem => {
        if (u.status !== "uploading" && u.status !== "queued") return u;
        if (slots-- <= 0) return u;
        const progress = Math.min(1, u.progress + Math.max(0.05, 300_000 / (u.size ?? 1)));
        return { ...u, progress, status: progress >= 1 ? "done" : "uploading" };
      });
      if (next.every((u) => u.status !== "uploading" && u.status !== "queued") && timer.current) {
        clearInterval(timer.current);
        timer.current = null;
      }
      return next;
    });
  const start = () => {
    if (!timer.current) timer.current = setInterval(tick, 160);
  };
  const add = (files: File[]) => {
    setItems((all) => [
      ...all,
      ...files.map((f, i) => ({
        id: `${Date.now()}-${i}`,
        name: f.name,
        size: f.size || 50_000,
        progress: 0,
        status: "queued" as const,
      })),
    ]);
    start();
  };
  const set = (id: string, change: Partial<UploadItem>) =>
    setItems((all) => all.map((u) => (u.id === id ? { ...u, ...change } : u)));

  return (
    <div style={{ display: "grid", gap: 12, width: "100%", maxWidth: 420 }}>
      <DropZone onFiles={add} title="Drop files to upload them" />
      <Button
        size="sm"
        onClick={() =>
          add([
            new File(["x".repeat(900_000)], "Quarterly review.pdf"),
            new File(["x"], "notes.md"),
          ])
        }
      >
        Add two sample files
      </Button>
      <UploadQueue
        items={items}
        footer="To R2 · moreau-drive"
        onCancel={(id) => set(id, { status: "cancelled" })}
        onRetry={(id) => {
          set(id, { status: "queued", progress: 0 });
          start();
        }}
        onCancelAll={() =>
          setItems((all) =>
            all.map((u) => (u.status === "done" ? u : { ...u, status: "cancelled" })),
          )
        }
        onClear={() => setItems([])}
      />
    </div>
  );
}
API → Props
PropTypeDefaultDescription
items{ id, name, size?, progress, status, error? }[]—progress from 0 to 1; status queued, uploading, done, failed or cancelled.
onCancel / onRetry / onCancelAll / onClear(id) => void; () => void—Each button shows only when it is given and applies.
onOpen(id) => void—A done file's name is a button.
minimized / defaultMinimized / onMinimizedChangeboolean—Folded to its header.
footerReactNode—Where the files go.
placement"inline" | "corner""inline"In the flow, or fixed at the bottom right of the window.
classNamestring—Extra classes.