"use client"; import Link from "next/link"; import { useParams, useRouter } from "next/navigation"; import { useCallback, useEffect, useState } from "react"; import { api } from "@/lib/api/client"; import type { components } from "@/lib/api/schema"; import { Button } from "@/components/ui/button"; import { Card, CardContent, CardHeader, CardTitle } from "@/components/ui/card"; import { Input } from "@/components/ui/input"; type Source = components["schemas"]["SourceRead"]; export default function SourcesPage() { const router = useRouter(); const params = useParams<{ id: string }>(); const treeId = params.id; const [sources, setSources] = useState([]); const [ready, setReady] = useState(false); const [title, setTitle] = useState(""); const [repository, setRepository] = useState(""); const [url, setUrl] = useState(""); const load = useCallback(async () => { const { data, response } = await api.GET("/api/v1/trees/{tree_id}/sources", { params: { path: { tree_id: treeId } }, }); if (response.status === 401) { router.push("/login"); return; } setSources(data ?? []); setReady(true); }, [router, treeId]); useEffect(() => { load(); }, [load]); async function add(e: React.FormEvent) { e.preventDefault(); if (!title.trim()) return; const { error } = await api.POST("/api/v1/trees/{tree_id}/sources", { params: { path: { tree_id: treeId } }, body: { title, repository: repository || null, url: url || null }, }); if (!error) { setTitle(""); setRepository(""); setUrl(""); load(); } } async function remove(id: string) { await api.DELETE("/api/v1/trees/{tree_id}/sources/{source_id}", { params: { path: { tree_id: treeId, source_id: id } }, }); load(); } if (!ready) return

Loading…

; return (
← Back to tree

Sources

New source
setTitle(e.target.value)} /> setRepository(e.target.value)} /> setUrl(e.target.value)} />
{sources.length === 0 ? (

No sources yet — add one above, then cite it on facts.

) : ( )}
); }