diff --git a/frontend/src/pages/EditVod.tsx b/frontend/src/pages/EditVod.tsx new file mode 100644 index 0000000..45b895d --- /dev/null +++ b/frontend/src/pages/EditVod.tsx @@ -0,0 +1,108 @@ +import { useEffect, useState } from "react"; +import { useNavigate, useParams } from "react-router-dom"; +import { ArrowLeft, Check } from "lucide-react"; +import { getVodById, patchVod } from "../utils/endpoints.ts"; +import Box from "../components/Box.tsx"; +import BlueButton from "../components/buttons/BlueButton.tsx"; + +const inputClass = "border border-gray-300 bg-white rounded-md w-full p-2 text-sm focus:outline-none focus:ring-2 focus:ring-primary/20 focus:border-primary transition-colors"; + +const EditVod = () => { + 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; + getVodById(id) + .then((vod) => { + if (vod) { + setTitle(vod.title ?? ""); + setDescription(vod.description ?? ""); + } + }) + .catch(() => setError("Failed to load vod.")) + .finally(() => setLoading(false)); + }, [id]); + + const handleSave = async () => { + if (!id) return; + setSaving(true); + setError(null); + try { + await patchVod(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 VoD

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