diff --git a/frontend/components/installed-games/add-game-button.tsx b/frontend/components/installed-games/add-game-button.tsx index 63f6ce29..95dca019 100644 --- a/frontend/components/installed-games/add-game-button.tsx +++ b/frontend/components/installed-games/add-game-button.tsx @@ -6,11 +6,18 @@ import { addGame } from "@api/bindings"; import { dialog } from "@tauri-apps/api"; import { useAtomValue } from "jotai"; import { loadingAtom } from "@hooks/use-data"; +import { useAsyncCommand } from "@hooks/use-async-command"; export function AddGame() { const [isOpen, setIsOpen] = useState(false); const isLoading = useAtomValue(loadingAtom); + const handleSuccess = useCallback(() => { + setIsOpen(false); + }, []); + + const [executeAddGame] = useAsyncCommand(addGame, handleSuccess); + const handleClick = useCallback(async () => { const result = await dialog.open({ multiple: false, @@ -28,8 +35,8 @@ export function AddGame() { }); if (!result || Array.isArray(result)) return; - await addGame(result); - }, []); + await executeAddGame(result); + }, [executeAddGame]); useEffect(() => { if (isLoading) setIsOpen(false);