import { Loader2 } from "lucide-react"; import { useId, useState } from "react"; import { getAllSourceCodes } from "../adapters/bestiary-index-adapter.js"; import { useBestiaryContext } from "../contexts/bestiary-context.js"; import { useBulkImportContext } from "../contexts/bulk-import-context.js"; import { useSidePanelContext } from "../contexts/side-panel-context.js"; import { Button } from "./ui/button.js"; import { Input } from "./ui/input.js"; const DEFAULT_BASE_URL = "https://raw.githubusercontent.com/5etools-mirror-3/5etools-src/main/data/bestiary/"; export function BulkImportPrompt() { const { fetchAndCacheSource, isSourceCached, refreshCache } = useBestiaryContext(); const { state: importState, startImport, reset } = useBulkImportContext(); const { dismissPanel } = useSidePanelContext(); const [baseUrl, setBaseUrl] = useState(DEFAULT_BASE_URL); const baseUrlId = useId(); const totalSources = getAllSourceCodes().length; const handleStart = (url: string) => { startImport(url, fetchAndCacheSource, isSourceCached, refreshCache); }; const handleDone = () => { dismissPanel(); reset(); }; if (importState.status === "complete") { return (
All sources loaded
); } if (importState.status === "partial-failure") { return (
Loaded {importState.completed}/{importState.total} sources ( {importState.failed} failed)
); } if (importState.status === "loading") { const processed = importState.completed + importState.failed; const pct = importState.total > 0 ? Math.round((processed / importState.total) * 100) : 0; return (
Loading sources... {processed}/{importState.total}
); } // idle state const isDisabled = !baseUrl.trim() || importState.status !== "idle"; return (

Import All Sources

Load stat block data for all {totalSources} sources at once.

setBaseUrl(e.target.value)} className="text-xs" />
); }