diff --git a/src/pages/parts/errors/ErrorCard.tsx b/src/pages/parts/errors/ErrorCard.tsx new file mode 100644 index 00000000..55cc81cd --- /dev/null +++ b/src/pages/parts/errors/ErrorCard.tsx @@ -0,0 +1,68 @@ +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} +
+
+ ); +} diff --git a/src/pages/parts/player/PlaybackErrorPart.tsx b/src/pages/parts/player/PlaybackErrorPart.tsx index 519f8eb8..88ab8af0 100644 --- a/src/pages/parts/player/PlaybackErrorPart.tsx +++ b/src/pages/parts/player/PlaybackErrorPart.tsx @@ -1,33 +1,15 @@ -import { useRef, useState } from "react"; - import { Button } from "@/components/Button"; -import { Icon, Icons } from "@/components/Icon"; +import { Icons } from "@/components/Icon"; import { IconPill } from "@/components/layout/IconPill"; import { Paragraph } from "@/components/text/Paragraph"; import { Title } from "@/components/text/Title"; import { ErrorContainer, ErrorLayout } from "@/pages/layouts/ErrorLayout"; import { usePlayerStore } from "@/stores/player/store"; +import { ErrorCard } from "../errors/ErrorCard"; + export function PlaybackErrorPart() { const playbackError = usePlayerStore((s) => s.interface.error); - const [showErrorCard, setShowErrorCard] = useState(true); - const [hasCopied, setHasCopied] = useState(false); - const hasCopiedUnsetDebounce = useRef | null>( - null - ); - - function copyError() { - if (!playbackError || !navigator.clipboard) return; - navigator.clipboard.writeText(playbackError.message); - - setHasCopied(true); - - // Debounce unsetting the "has copied" label - if (hasCopiedUnsetDebounce.current) - clearTimeout(hasCopiedUnsetDebounce.current); - hasCopiedUnsetDebounce.current = setTimeout(() => setHasCopied(false), 2e3); - console.log(hasCopiedUnsetDebounce); - } return ( @@ -51,43 +33,7 @@ export function PlaybackErrorPart() { {/* Error */} - {playbackError && showErrorCard ? ( - // I didn't put a here because it'd fade out, then jump height weirdly -
-
- Error details -
- - -
-
-
- {playbackError.message} -
-
- ) : null} + {playbackError ? : null}
); diff --git a/src/pages/parts/player/ScrapeErrorPart.tsx b/src/pages/parts/player/ScrapeErrorPart.tsx index e2625180..16c2afe9 100644 --- a/src/pages/parts/player/ScrapeErrorPart.tsx +++ b/src/pages/parts/player/ScrapeErrorPart.tsx @@ -1,13 +1,15 @@ import { useMemo } from "react"; import { Button } from "@/components/Button"; -import { Icon, Icons } from "@/components/Icon"; +import { Icons } from "@/components/Icon"; import { IconPill } from "@/components/layout/IconPill"; import { Paragraph } from "@/components/text/Paragraph"; import { Title } from "@/components/text/Title"; import { ScrapingItems, ScrapingSegment } from "@/hooks/useProviderScrape"; import { ErrorContainer, ErrorLayout } from "@/pages/layouts/ErrorLayout"; +import { ErrorCard } from "../errors/ErrorCard"; + export interface ScrapeErrorPartProps { data: { sources: Record; @@ -53,25 +55,7 @@ export function ScrapeErrorPart(props: ScrapeErrorPartProps) { {/* Error */} - {error ? ( -
-
- Error details -
- - -
-
-
- {error} -
-
- ) : null} + {error ? : null}
);