diff --git a/frontend/src/components/Demo.tsx b/frontend/src/components/Demo.tsx index e71358e..0298aeb 100644 --- a/frontend/src/components/Demo.tsx +++ b/frontend/src/components/Demo.tsx @@ -3,21 +3,36 @@ import DownloadButton from "@/components/DownloadButton"; import Emboldened from "@/components/Emboldened"; import useSocket from "@/components/useSocket"; import { cn, plural, toHex, type ClassValue } from "@/util"; -import { useRef, useState } from "react"; +import { useEffect, useRef, useState } from "react"; type DemoProps = { class?: ClassValue; }; const Demo = ({ class: className }: DemoProps) => { - const { id, downloads, executables } = useSocket(); + const audioRef = useRef(null); + + const { id, downloads, executables, deleteDownload } = useSocket({ + notify: (token) => { + audioRef.current!.play(); + highlight(token); + }, + }); // TODO: Toasts - const [highlightedIndex, setHighlightedIndex] = useState(null); + const [highlightedToken, setHighlightedToken] = useState(null); const highlightedTimeoutRef = useRef(null); - function highlight(index: number) { - setHighlightedIndex(index); + useEffect(() => { + audioRef.current = new Audio("/notify.wav"); + audioRef.current.volume = 1; + return () => { + audioRef.current!.remove(); + }; + }, []); + + function highlight(token: number) { + setHighlightedToken(token); if (highlightedTimeoutRef.current != null) { clearTimeout(highlightedTimeoutRef.current); @@ -25,7 +40,7 @@ const Demo = ({ class: className }: DemoProps) => { highlightedTimeoutRef.current = setTimeout(() => { highlightedTimeoutRef.current = null; - setHighlightedIndex(null); + setHighlightedToken(null); }, 1250); } @@ -46,25 +61,25 @@ const Demo = ({ class: className }: DemoProps) => { {" "} known {plural("download", downloads?.length ?? 0)}.

-
+
{downloads?.map((download, i) => ( { + deleteDownload(download.token); }} > {toHex(download.token)}