import { useEffect, useState } from "react"; import { useNavigate, useParams } from "react-router-dom"; import { ArrowLeft, Check } from "lucide-react"; import { getClipById, patchClip } from "../utils/api/clips.ts"; import Box from "../components/Box.tsx"; import PrimaryButton from "../components/buttons/PrimaryButton.tsx"; const inputClass = "border border-hairline bg-fields rounded-md w-full p-2 text-sm focus:outline-none focus:ring-2 focus:ring-muted transition-colors"; const EditClip = () => { const { id } = useParams(); const navigate = useNavigate(); const [title, setTitle] = useState(""); const [description, setDescription] = useState(""); const [loading, setLoading] = useState(true); const [saving, setSaving] = useState(false); const [saved, setSaved] = useState(false); const [error, setError] = useState(null); useEffect(() => { if (!id) return; getClipById(id) .then((clip) => { if (clip) { setTitle(clip.title ?? ""); setDescription(clip.description ?? ""); } }) .catch(() => setError("Failed to load clip.")) .finally(() => setLoading(false)); }, [id]); const handleSave = async () => { if (!id) return; setSaving(true); setError(null); try { await patchClip(Number(id), { title, description }); setSaved(true); setTimeout(() => setSaved(false), 2000); } catch (err) { setError(err instanceof Error ? err.message : "Failed to save."); } finally { setSaving(false); } }; return (

Edit Clip

{loading ? (
Loading...
) : (
setTitle(e.target.value)} placeholder="Enter title" className={inputClass} />