-
Notifications
You must be signed in to change notification settings - Fork 3.2k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #1301 from hydralauncher/feature/reset-achievements
feat: add reset achievements modal
- Loading branch information
Showing
8 changed files
with
171 additions
and
6 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,56 @@ | ||
import { gameAchievementRepository, gameRepository } from "@main/repository"; | ||
import { registerEvent } from "../register-event"; | ||
import { findAchievementFiles } from "@main/services/achievements/find-achivement-files"; | ||
import fs from "fs"; | ||
import { achievementsLogger, HydraApi, WindowManager } from "@main/services"; | ||
import { getUnlockedAchievements } from "../user/get-unlocked-achievements"; | ||
|
||
const resetGameAchievements = async ( | ||
_event: Electron.IpcMainInvokeEvent, | ||
gameId: number | ||
) => { | ||
try { | ||
const game = await gameRepository.findOne({ where: { id: gameId } }); | ||
|
||
if (!game) return; | ||
|
||
const achievementFiles = findAchievementFiles(game); | ||
|
||
if (achievementFiles.length) { | ||
for (const achievementFile of achievementFiles) { | ||
achievementsLogger.log(`deleting ${achievementFile.filePath}`); | ||
await fs.promises.rm(achievementFile.filePath); | ||
} | ||
} | ||
|
||
await gameAchievementRepository.update( | ||
{ objectId: game.objectID }, | ||
{ | ||
unlockedAchievements: null, | ||
} | ||
); | ||
|
||
await HydraApi.delete(`/profile/games/achievements/${game.remoteId}`).then( | ||
() => | ||
achievementsLogger.log( | ||
`Deleted achievements from ${game.remoteId} - ${game.objectID} - ${game.title}` | ||
) | ||
); | ||
|
||
const gameAchievements = await getUnlockedAchievements( | ||
game.objectID, | ||
game.shop, | ||
true | ||
); | ||
|
||
WindowManager.mainWindow?.webContents.send( | ||
`on-update-achievements-${game.objectID}-${game.shop}`, | ||
gameAchievements | ||
); | ||
} catch (error) { | ||
achievementsLogger.error(error); | ||
throw error; | ||
} | ||
}; | ||
|
||
registerEvent("resetGameAchievements", resetGameAchievements); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
48 changes: 48 additions & 0 deletions
48
src/renderer/src/pages/game-details/modals/reset-achievements-modal.tsx
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,48 @@ | ||
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; | ||
onClose: () => void; | ||
resetAchievements: () => Promise<void>; | ||
}>; | ||
|
||
export function ResetAchievementsModal({ | ||
onClose, | ||
game, | ||
visible, | ||
resetAchievements, | ||
}: ResetAchievementsModalProps) { | ||
const { t } = useTranslation("game_details"); | ||
|
||
const handleResetAchievements = async () => { | ||
try { | ||
await resetAchievements(); | ||
} finally { | ||
onClose(); | ||
} | ||
}; | ||
|
||
return ( | ||
<Modal | ||
visible={visible} | ||
onClose={onClose} | ||
title={t("reset_achievements_title")} | ||
description={t("reset_achievements_description", { | ||
game: game.title, | ||
})} | ||
> | ||
<div className={styles.deleteActionsButtonsCtn}> | ||
<Button onClick={handleResetAchievements} theme="outline"> | ||
{t("reset_achievements")} | ||
</Button> | ||
|
||
<Button onClick={onClose} theme="primary"> | ||
{t("cancel")} | ||
</Button> | ||
</div> | ||
</Modal> | ||
); | ||
} |