"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 Person = components["schemas"]["PersonRead"]; export default function TreeDetailPage() { const router = useRouter(); const params = useParams<{ id: string }>(); const treeId = params.id; const [persons, setPersons] = useState([]); const [given, setGiven] = useState(""); const [surname, setSurname] = useState(""); const [ready, setReady] = useState(false); const load = useCallback(async () => { const { data, response } = await api.GET("/api/v1/trees/{tree_id}/persons", { params: { path: { tree_id: treeId } }, }); if (response.status === 401) { router.push("/login"); return; } setPersons(data ?? []); setReady(true); }, [router, treeId]); useEffect(() => { load(); }, [load]); async function addPerson(e: React.FormEvent) { e.preventDefault(); if (!given.trim() && !surname.trim()) return; const { error } = await api.POST("/api/v1/trees/{tree_id}/persons", { params: { path: { tree_id: treeId } }, body: { given: given || null, surname: surname || null }, }); if (!error) { setGiven(""); setSurname(""); load(); } } if (!ready) return

Loading…

; return (
← All trees Sources →
Add a person
setGiven(e.target.value)} /> setSurname(e.target.value)} />

People

{persons.length === 0 ? (

No people yet.

) : (
    {persons.map((person) => (
  • {person.primary_name ?? ( Unnamed )}
  • ))}
)}
); }