"use client"; import { useState, useEffect } from "react"; import { Trash2 } from "lucide-react"; import { Button } from "@/components/ui/button"; import { Dialog, DialogContent, DialogHeader, DialogTitle, DialogFooter, } from "@/components/ui/dialog"; import { Input } from "@/components/ui/input"; import { Label } from "@/components/ui/label"; import { useTranscodeSettings, useUpdateTranscodeSettings, useTranscodeStats, useClearTranscodeCache, } from "@/hooks/use-transcode"; import { toast } from "sonner"; interface Props { open: boolean; onOpenChange: (open: boolean) => void; } function fmtBytes(bytes: number): string { if (bytes < 1024) return `${bytes} B`; if (bytes < 1024 * 1024) return `${(bytes / 1024).toFixed(1)} KB`; if (bytes < 1024 * 1024 * 1024) return `${(bytes / (1024 * 1024)).toFixed(1)} MB`; return `${(bytes / (1024 * 1024 * 1024)).toFixed(2)} GB`; } export function TranscodeSettingsDialog({ open, onOpenChange }: Props) { const { data: settings } = useTranscodeSettings(); const { data: stats } = useTranscodeStats(); const updateSettings = useUpdateTranscodeSettings(); const clearCache = useClearTranscodeCache(); const [ttl, setTtl] = useState(24); const [confirmClear, setConfirmClear] = useState(false); useEffect(() => { // Initialise controlled input from async data — intentional setState in effect // eslint-disable-next-line react-hooks/set-state-in-effect if (settings) setTtl(settings.cleanup_ttl_hours); }, [settings]); const handleSave = () => { updateSettings.mutate( { cleanup_ttl_hours: ttl }, { onSuccess: () => toast.success("Settings saved"), onError: () => toast.error("Failed to save settings"), }, ); }; const handleClear = () => { if (!confirmClear) { setConfirmClear(true); return; } clearCache.mutate(undefined, { onSuccess: () => { toast.success("Transcode cache cleared"); setConfirmClear(false); }, onError: () => toast.error("Failed to clear cache"), }); }; return ( Transcode Settings
{/* TTL */}
setTtl(Number(e.target.value))} className="w-32 bg-zinc-800 border-zinc-700 text-zinc-100" />

Transcoded segments older than this are removed automatically.

{/* Stats */}

Cache

{stats ? fmtBytes(stats.cache_size_bytes) : "—"}{" "} ({stats ? stats.item_count : "—"} items)

{/* Clear cache */} {confirmClear && (

setConfirmClear(false)} > Cancel

)}
); }