import { repertoireCache, User } from "@/cache"; import { client } from "@/client"; import { Button } from "@/components/ui/button"; import { Dialog, DialogContent, DialogFooter, DialogHeader, DialogTitle, DialogTrigger } from "@/components/ui/dialog"; import { Input } from "@/components/ui/input"; import { Label } from "@/components/ui/label"; import { Table, TableBody, TableCell, TableHead, TableHeader, TableRow } from "@/components/ui/table"; import { useLoadingEffect } from "@/hooks/useLoading"; import { RepertoireId } from "common"; import { Cause, Clock, Duration, Effect, Option } from "effect"; import { Loader2, Plus } from "lucide-react"; import { FormEventHandler, ReactNode, useId, useState } from "react"; import { Link, useNavigate } from "react-router-dom"; export function Repertoires() { const [name, setName] = useState(""); const { isLoading, error, data: repertoireIds } = useLoadingEffect(Effect.gen(function* () { yield* Clock.sleep(Duration.millis(500)); const { error, data } = yield* Effect.promise((signal) => client.repertoire.get({ query: { ...(name !== "" ? { name } : undefined), }, fetch: { signal }, })); if (error !== null) { return yield* Effect.fail(error); } else { return data; } }), [name]); return (
setName(e.target.value)} />
Nazwa Utwory Dodano Zmodyfikowano {isLoading ? (
Ładowanie…
) : error !== null ? ( {Cause.isUnknownException(error) ? "Wystąpił nieznany błąd" : `Wystąpił błąd: ${error.value}`} ) : ( repertoireIds.map((repertoireId) => ) )}
); } namespace RepertoireRow { export interface Props { readonly repertoireId: RepertoireId; } } function RepertoireRow(props: RepertoireRow.Props) { const { isLoading, error, data: repertoire } = useLoadingEffect(Effect.uninterruptible(repertoireCache.get(props.repertoireId)), [props.repertoireId]); if (isLoading) { return ( Ładowanie… ); } if (error !== null) { return ( Wystąpił błąd: {error.value} ); } const piecesParts: ReactNode[] = []; if (repertoire.entries.length === 0) { piecesParts.push(Brak); } else { const CUTOFF = 10; let text = repertoire.entries.slice(0, CUTOFF).map(({ name }) => name).join(", "); if (repertoire.entries.length > CUTOFF) { text += ", …"; } piecesParts.push(text); } return ( {repertoire.name} {...piecesParts} {repertoire.createdAt} {Option.isSome(repertoire.createdBy) && <>
przez {repertoire.createdBy.value.username}}
{Option.isNone(repertoire.modifiedAt) && Option.isNone(repertoire.modifiedBy) ? "\u2014" : Option.isSome(repertoire.modifiedAt) && Option.isNone(repertoire.modifiedBy) ? repertoire.modifiedAt.value : Option.isNone(repertoire.modifiedAt) ? `przez ${(repertoire.modifiedBy as Option.Some).value.username}` : <>{repertoire.modifiedAt.value}
przez {(repertoire.modifiedBy as Option.Some).value.username}}
); } function AddRepertoireDialogContent() { const navigate = useNavigate(); const [name, setName] = useState(""); const nameId = useId(); const [isLoading, setIsLoading] = useState(false); const onSubmit: FormEventHandler = async (e) => { e.preventDefault(); try { setIsLoading(true); const { data, error } = await client.repertoire.post({ name, entries: [], }); if (error !== null) { console.error(error.value); return; } navigate(data.repertoireId); } finally { setIsLoading(false); } }; return (
Utwórz repertuar
setName(e.target.value)} />
); }