From 06b48efa4b5fd661e78d3785026eb09c9a438117 Mon Sep 17 00:00:00 2001 From: Evan Buss Date: Thu, 27 Jan 2022 03:46:54 +0000 Subject: [PATCH] Prevent double clicking. --- .../src/components/BooksGrid/BooksGrid.tsx | 38 ++++++++++++------- todo | 3 +- 2 files changed, 25 insertions(+), 16 deletions(-) diff --git a/server/app/src/components/BooksGrid/BooksGrid.tsx b/server/app/src/components/BooksGrid/BooksGrid.tsx index 7190aaf..24b3fb9 100644 --- a/server/app/src/components/BooksGrid/BooksGrid.tsx +++ b/server/app/src/components/BooksGrid/BooksGrid.tsx @@ -24,7 +24,6 @@ export interface Props { } export const BooksGrid: React.FC = ({ books }: Props) => { - const dispatch = useDispatch(); const { data: onlineServers, refetch } = useGetServersQuery(null); const [titleFilter, setTitleFilter] = useState(""); const [authorFilter, setAuthorFilter] = useState(""); @@ -114,19 +113,7 @@ export const BooksGrid: React.FC = ({ books }: Props) => { {book.size} - + )); @@ -186,3 +173,26 @@ export const BooksGrid: React.FC = ({ books }: Props) => { ); }; + +function DownloadButton({ book }: { book: string }) { + const dispatch = useDispatch(); + const [disabled, setDisabled] = useState(false); + + // Prevent hitting the same button multiple times + const onClick = () => { + if (disabled) return; + dispatch( + sendMessage({ + type: MessageType.DOWNLOAD, + payload: { book } + }) + ); + setDisabled(true); + }; + + return ( + + ); +} diff --git a/todo b/todo index e7aabbb..f6f6503 100644 --- a/todo +++ b/todo @@ -2,7 +2,7 @@ Future: - Show IRC logs in the browser - Show online servers in the CLI. -- Handle name collisions +- Handle IRC name collisions - Simplify dto model calling code in Go. Don't need as many types. - Allow reconnecting to same IRC connection if websocket disconnects. - Currently we immediately terminate the IRC connection and remove the client @@ -14,4 +14,3 @@ Future: - Improve message formats. - Don't need as many separate message types. Just have functions that create them with the appropriate status code. - Log the address to access it in the browser on startup -- Prevent double clicking the download button.