import { useEffect, useState } from 'react' import { FolderOpen, LoaderCircle, Play, Square, X } from 'lucide-react' import { api, type BatchState } from '@/api' import { useStore } from '@/store' import { Button } from '@/components/ui/button' import { Field, Input, SwitchField, Textarea } from '@/components/ui/controls' /** A whole folder at once: every image in it gets the list of replacements, with the look and * the model settings of the editor, and goes into a new folder next to the host's outputs. */ export function Batch({ onClose }: { onClose: () => void }) { const options = useStore((state) => state.options) const look = useStore((state) => state.look) const model = useStore((state) => state.model) const [input, setInput] = useState(() => localStorage.getItem('textfix.batch.input') ?? '') const [lines, setLines] = useState(() => localStorage.getItem('textfix.batch.lines') ?? '') const [blend, setBlend] = useState(!!options?.canBlend) const [state, setState] = useState(null) const [error, setError] = useState('') const running = !!state?.running // While a folder is being worked on, ask how far it got once a second. useEffect(() => { let stop = false const tick = async () => { try { const now = await api.batch({ action: 'status' }) if (!stop) setState(now) } catch { // the next tick asks again } } void tick() const timer = window.setInterval(() => void tick(), 1000) return () => { stop = true window.clearInterval(timer) } }, []) const start = async () => { setError('') localStorage.setItem('textfix.batch.input', input) localStorage.setItem('textfix.batch.lines', lines) try { setState(await api.batch({ action: 'start', input, lines, blend, look, model })) } catch (failure) { setError(failure instanceof Error ? failure.message : String(failure)) } } const progress = state && state.total ? Math.round((state.done / state.total) * 100) : 0 return (
event.stopPropagation()} >

A whole folder at once

setInput(event.target.value)} />