Files
boocode/apps/web/src/hooks/useArtifactDownload.ts
indifferentketchup abe1a311d0 refactor: codebase audit cleanup — dead code, dedup, module splits
Multi-agent audit + aggressive cleanup across server/web/coder/booterm,
delivered behind a DEFER discipline so none of the in-flight files were
touched. Removes dead code/deps/columns, dedups server + coder helpers,
and splits the oversized modules (tools.ts, opencode-server.ts,
sentinel-summaries, turn.ts, TerminalPane.tsx) behind stable contracts.
Adds 78 parity/unit tests (server 587, coder 323); fixes two latent bugs
(ChatPane queue keys, FileViewerOverlay blank-line parity).

Intended tag: v2.7.12-audit-cleanup.
2026-06-02 21:12:29 +00:00

27 lines
782 B
TypeScript

import { useState } from 'react';
import { toast } from 'sonner';
import { api } from '@/api/client';
export function useArtifactDownload(chatId: string, messageId: string, format: 'md' | 'html') {
const [downloading, setDownloading] = useState(false);
async function download() {
if (downloading) return;
setDownloading(true);
try {
const { url, path } = await api.messages.downloadArtifact(chatId, messageId, format);
const a = document.createElement('a');
a.href = url;
a.rel = 'noopener';
a.click();
toast.success(`Saved to ${path}`);
} catch (err) {
toast.error(err instanceof Error ? err.message : 'download failed');
} finally {
setDownloading(false);
}
}
return { downloading, download };
}