import { useState } from 'react'; import { X } from 'lucide-react'; import type { WatchedItem } from '../types'; import { updateItem } from '../api/client'; interface Props { item: WatchedItem; onClose: () => void; onSaved: () => void; } function displayName(item: WatchedItem): string { if (item.name) return item.name; try { return new URL(item.url).pathname.split('/').filter(Boolean).pop() ?? item.url; } catch { return item.url; } } export default function EditItemModal({ item, onClose, onSaved }: Props) { const [interval, setInterval] = useState(String(item.check_interval)); const [loading, setLoading] = useState(false); const [error, setError] = useState(''); const handleSubmit = async (e: React.FormEvent) => { e.preventDefault(); setError(''); const secs = Math.max(30, parseInt(interval, 10) || item.check_interval); setLoading(true); try { await updateItem(item.id, { check_interval: secs }); onSaved(); } catch (e: unknown) { setError(e instanceof Error ? e.message : 'Failed to save changes'); } finally { setLoading(false); } }; return (
e.target === e.currentTarget && onClose()}>
Edit Item
{displayName(item)}
{error &&
{error}
}
setInterval(e.target.value)} autoFocus required />
Minimum 30 seconds. The scheduler will restart with the new interval immediately.
); }