import { useRef, useState } from "react"; import { Button } from "@/components/Button"; import { Icon, Icons } from "@/components/Icon"; import { DisplayError } from "@/components/player/display/displayInterface"; export function ErrorCard(props: { error: DisplayError | string }) { const [showErrorCard, setShowErrorCard] = useState(true); const [hasCopied, setHasCopied] = useState(false); const hasCopiedUnsetDebounce = useRef | null>( null ); const errorMessage = typeof props.error === "string" ? props.error : props.error.message; function copyError() { if (!props.error || !navigator.clipboard) return; navigator.clipboard.writeText(`\`\`\`${errorMessage}\`\`\``); setHasCopied(true); // Debounce unsetting the "has copied" label if (hasCopiedUnsetDebounce.current) clearTimeout(hasCopiedUnsetDebounce.current); hasCopiedUnsetDebounce.current = setTimeout(() => setHasCopied(false), 2e3); } if (!showErrorCard) return null; return ( // I didn't put a here because it'd fade out, then jump height weirdly
Error details
{errorMessage}
); }