import type { Torrent } from '../shared'; import { useEffect, useState } from 'react'; import { Button } from '@/components/ui/button'; import { Dialog, DialogContent, DialogDescription, DialogFooter, DialogHeader, DialogTitle, } from '@/components/ui/dialog'; import { Input } from '@/components/ui/input'; import { Label } from '@/components/ui/label'; import { useTorrentMutations } from '../useTransmissionData'; // torrent-set-location does two unrelated things depending on one boolean, so the dialog asks in words // rather than showing a checkbox called "move". // // move: true — physically relocate the data, then point the torrent at the new place // move: false — the data is ALREADY there; just re-point the torrent (this is how you recover after // moving files by hand, and it is also how you lose a torrent if you pick it by mistake) type MoveTorrentDialogProps = { open: boolean; onOpenChange: (open: boolean) => void; targets: Torrent[]; /** Every distinct download dir currently in use, offered as one-click destinations. */ knownDirs: string[]; }; export const MoveTorrentDialog = ({ open, onOpenChange, targets, knownDirs }: MoveTorrentDialogProps) => { const { setLocation } = useTorrentMutations(); const [location, setLocationValue] = useState(''); const [move, setMove] = useState(true); useEffect(() => { if (!open) return; // Seed with the current location when they all share one — the common case is a small edit to it. const dirs = new Set(targets.map((t) => t.downloadDir)); setLocationValue(dirs.size === 1 ? [...dirs][0]! : ''); setMove(true); }, [open, targets]); const submit = async () => { await setLocation.mutateAsync({ ids: targets.map((t) => t.id), location: location.trim(), move }); onOpenChange(false); }; return ( Set location {targets.length === 1 ? targets[0]!.name : `${targets.length} torrents`}
setLocationValue(ev.target.value)} placeholder="/downloads/complete" className="font-mono text-xs" />
{knownDirs.length > 0 && (
{knownDirs.map((dir) => ( ))}
)}
); };