From 93b86f8c6c1df579eb9586cb254361134f2269a0 Mon Sep 17 00:00:00 2001 From: Hachi-R Date: Fri, 3 Jan 2025 12:38:06 -0300 Subject: [PATCH] refactor: improve reset achievements handling and modal state management --- .../game-details/modals/game-options-modal.tsx | 15 ++++++++++----- .../modals/reset-achievements-modal.tsx | 10 ++++++---- 2 files changed, 16 insertions(+), 9 deletions(-) diff --git a/src/renderer/src/pages/game-details/modals/game-options-modal.tsx b/src/renderer/src/pages/game-details/modals/game-options-modal.tsx index 5289870ef..346f47000 100644 --- a/src/renderer/src/pages/game-details/modals/game-options-modal.tsx +++ b/src/renderer/src/pages/game-details/modals/game-options-modal.tsx @@ -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, @@ -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; @@ -333,7 +338,7 @@ export function GameOptionsModal({ diff --git a/src/renderer/src/pages/game-details/modals/reset-achievements-modal.tsx b/src/renderer/src/pages/game-details/modals/reset-achievements-modal.tsx index b053060f1..642d32baa 100644 --- a/src/renderer/src/pages/game-details/modals/reset-achievements-modal.tsx +++ b/src/renderer/src/pages/game-details/modals/reset-achievements-modal.tsx @@ -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; @@ -19,18 +18,21 @@ export function ResetAchievementsModal({ const { t } = useTranslation("game_details"); const handleResetAchievements = async () => { - await resetAchievements(); - onClose(); + try { + await resetAchievements(); + } finally { + onClose(); + } }; return (