Skip to content

Commit

Permalink
Show error messages on adding game via browsing for file
Browse files Browse the repository at this point in the history
  • Loading branch information
Raicuparta committed Nov 23, 2023
1 parent b1e6823 commit 943281b
Showing 1 changed file with 9 additions and 2 deletions.
11 changes: 9 additions & 2 deletions frontend/components/installed-games/add-game-button.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand All @@ -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);
Expand Down

0 comments on commit 943281b

Please sign in to comment.