mirror of
https://github.com/hydralauncher/hydra.git
synced 2025-01-23 13:34:54 +03:00
refactor: improve reset achievements handling and modal state management
This commit is contained in:
parent
8cf549ff05
commit
93b86f8c6c
@ -31,10 +31,10 @@ export function GameOptionsModal({
|
|||||||
|
|
||||||
const [showDeleteModal, setShowDeleteModal] = useState(false);
|
const [showDeleteModal, setShowDeleteModal] = useState(false);
|
||||||
const [showRemoveGameModal, setShowRemoveGameModal] = useState(false);
|
const [showRemoveGameModal, setShowRemoveGameModal] = useState(false);
|
||||||
|
const [launchOptions, setLaunchOptions] = useState(game.launchOptions ?? "");
|
||||||
const [showResetAchievementsModal, setShowResetAchievementsModal] =
|
const [showResetAchievementsModal, setShowResetAchievementsModal] =
|
||||||
useState(false);
|
useState(false);
|
||||||
|
const [isDeleting, setIsDeleting] = useState(false);
|
||||||
const [launchOptions, setLaunchOptions] = useState(game.launchOptions ?? "");
|
|
||||||
|
|
||||||
const {
|
const {
|
||||||
removeGameInstaller,
|
removeGameInstaller,
|
||||||
@ -146,8 +146,13 @@ export function GameOptionsModal({
|
|||||||
window.electron.platform === "linux";
|
window.electron.platform === "linux";
|
||||||
|
|
||||||
const handleResetAchievements = async () => {
|
const handleResetAchievements = async () => {
|
||||||
await window.electron.resetGameAchievements(game.id);
|
setIsDeleting(true);
|
||||||
updateGame();
|
try {
|
||||||
|
await window.electron.resetGameAchievements(game.id);
|
||||||
|
} finally {
|
||||||
|
await updateGame();
|
||||||
|
setIsDeleting(false);
|
||||||
|
}
|
||||||
};
|
};
|
||||||
|
|
||||||
const shouldShowLaunchOptionsConfiguration = false;
|
const shouldShowLaunchOptionsConfiguration = false;
|
||||||
@ -333,7 +338,7 @@ export function GameOptionsModal({
|
|||||||
<Button
|
<Button
|
||||||
onClick={() => setShowResetAchievementsModal(true)}
|
onClick={() => setShowResetAchievementsModal(true)}
|
||||||
theme="danger"
|
theme="danger"
|
||||||
disabled={isGameDownloading || deleting}
|
disabled={isGameDownloading || deleting || isDeleting}
|
||||||
>
|
>
|
||||||
{t("reset_achievements")}
|
{t("reset_achievements")}
|
||||||
</Button>
|
</Button>
|
||||||
|
@ -2,7 +2,6 @@ import { useTranslation } from "react-i18next";
|
|||||||
import { Button, Modal } from "@renderer/components";
|
import { Button, Modal } from "@renderer/components";
|
||||||
import * as styles from "./remove-from-library-modal.css";
|
import * as styles from "./remove-from-library-modal.css";
|
||||||
import type { Game } from "@types";
|
import type { Game } from "@types";
|
||||||
|
|
||||||
type ResetAchievementsModalProps = Readonly<{
|
type ResetAchievementsModalProps = Readonly<{
|
||||||
visible: boolean;
|
visible: boolean;
|
||||||
game: Game;
|
game: Game;
|
||||||
@ -19,18 +18,21 @@ export function ResetAchievementsModal({
|
|||||||
const { t } = useTranslation("game_details");
|
const { t } = useTranslation("game_details");
|
||||||
|
|
||||||
const handleResetAchievements = async () => {
|
const handleResetAchievements = async () => {
|
||||||
await resetAchievements();
|
try {
|
||||||
onClose();
|
await resetAchievements();
|
||||||
|
} finally {
|
||||||
|
onClose();
|
||||||
|
}
|
||||||
};
|
};
|
||||||
|
|
||||||
return (
|
return (
|
||||||
<Modal
|
<Modal
|
||||||
visible={visible}
|
visible={visible}
|
||||||
|
onClose={onClose}
|
||||||
title={t("reset_achievements_title")}
|
title={t("reset_achievements_title")}
|
||||||
description={t("reset_achievements_description", {
|
description={t("reset_achievements_description", {
|
||||||
game: game.title,
|
game: game.title,
|
||||||
})}
|
})}
|
||||||
onClose={onClose}
|
|
||||||
>
|
>
|
||||||
<div className={styles.deleteActionsButtonsCtn}>
|
<div className={styles.deleteActionsButtonsCtn}>
|
||||||
<Button onClick={handleResetAchievements} theme="outline">
|
<Button onClick={handleResetAchievements} theme="outline">
|
||||||
|
Loading…
Reference in New Issue
Block a user