Skip to content

Commit

Permalink
refactor: improve reset achievements handling and modal state management
Browse files Browse the repository at this point in the history
  • Loading branch information
Hachi-R committed Jan 3, 2025
1 parent 8cf549f commit 93b86f8
Show file tree
Hide file tree
Showing 2 changed files with 16 additions and 9 deletions.
15 changes: 10 additions & 5 deletions src/renderer/src/pages/game-details/modals/game-options-modal.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -31,10 +31,10 @@ export function GameOptionsModal({

const [showDeleteModal, setShowDeleteModal] = useState(false);
const [showRemoveGameModal, setShowRemoveGameModal] = useState(false);
const [launchOptions, setLaunchOptions] = useState(game.launchOptions ?? "");
const [showResetAchievementsModal, setShowResetAchievementsModal] =
useState(false);

const [launchOptions, setLaunchOptions] = useState(game.launchOptions ?? "");
const [isDeleting, setIsDeleting] = useState(false);

const {
removeGameInstaller,
Expand Down Expand Up @@ -146,8 +146,13 @@ export function GameOptionsModal({
window.electron.platform === "linux";

const handleResetAchievements = async () => {
await window.electron.resetGameAchievements(game.id);
updateGame();
setIsDeleting(true);
try {
await window.electron.resetGameAchievements(game.id);
} finally {
await updateGame();
setIsDeleting(false);
}
};

const shouldShowLaunchOptionsConfiguration = false;
Expand Down Expand Up @@ -333,7 +338,7 @@ export function GameOptionsModal({
<Button
onClick={() => setShowResetAchievementsModal(true)}
theme="danger"
disabled={isGameDownloading || deleting}
disabled={isGameDownloading || deleting || isDeleting}
>
{t("reset_achievements")}
</Button>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,6 @@ import { useTranslation } from "react-i18next";
import { Button, Modal } from "@renderer/components";
import * as styles from "./remove-from-library-modal.css";
import type { Game } from "@types";

type ResetAchievementsModalProps = Readonly<{
visible: boolean;
game: Game;
Expand All @@ -19,18 +18,21 @@ export function ResetAchievementsModal({
const { t } = useTranslation("game_details");

const handleResetAchievements = async () => {
await resetAchievements();
onClose();
try {
await resetAchievements();
} finally {
onClose();
}
};

return (
<Modal
visible={visible}
onClose={onClose}
title={t("reset_achievements_title")}
description={t("reset_achievements_description", {
game: game.title,
})}
onClose={onClose}
>
<div className={styles.deleteActionsButtonsCtn}>
<Button onClick={handleResetAchievements} theme="outline">
Expand Down

0 comments on commit 93b86f8

Please sign in to comment.