import { useState } from "react"; import { useNavigate, Navigate } from "react-router-dom"; import { useQuery, useMutation, useQueryClient } from "@tanstack/react-query"; import { listBands, createBand } from "../api/bands"; export function HomePage() { const navigate = useNavigate(); const qc = useQueryClient(); const [name, setName] = useState(""); const [slug, setSlug] = useState(""); const [ncBasePath, setNcBasePath] = useState(""); const [error, setError] = useState(null); const { data: bands, isLoading } = useQuery({ queryKey: ["bands"], queryFn: listBands, }); const createMutation = useMutation({ mutationFn: () => createBand({ name, slug, ...(ncBasePath ? { nc_base_path: ncBasePath } : {}) }), onSuccess: (band) => { qc.invalidateQueries({ queryKey: ["bands"] }); navigate(`/bands/${band.id}`); }, onError: (err) => setError(err instanceof Error ? err.message : "Failed to create band"), }); // Redirect to the first band once bands are loaded if (!isLoading && bands && bands.length > 0) { return ; } const inputStyle: React.CSSProperties = { width: "100%", padding: "8px 12px", background: "var(--bg-inset)", border: "1px solid var(--border)", borderRadius: 7, color: "var(--text)", marginBottom: 12, fontSize: 14, }; const labelStyle: React.CSSProperties = { display: "block", color: "var(--text-muted)", fontSize: 11, marginBottom: 6, }; return (
{isLoading ? (

Loading…

) : ( <>

Create your first band

Give your band a name to get started. You can add members and connect storage after.

{error && (

{error}

)} { setName(e.target.value); setSlug( e.target.value .toLowerCase() .replace(/\s+/g, "-") .replace(/[^a-z0-9-]/g, "") ); }} style={inputStyle} autoFocus /> setSlug(e.target.value)} style={{ ...inputStyle, fontFamily: "monospace", marginBottom: 16 }} /> setNcBasePath(e.target.value)} placeholder={`bands/${slug || "my-band"}/`} style={{ ...inputStyle, fontSize: 13, fontFamily: "monospace", marginBottom: 4 }} />

Path relative to your Nextcloud root. Leave blank to use{" "} bands/{slug || "slug"}/

)}
); }