refactor: change game delete to soft delete

This commit is contained in:
JackEnx 2024-04-21 16:36:34 -03:00
parent 1395cd40a9
commit a947b93669
17 changed files with 115 additions and 44 deletions

View file

@ -62,7 +62,8 @@ declare global {
openGameInstaller: (gameId: number) => Promise<boolean>;
openGame: (gameId: number, executablePath: string) => Promise<void>;
closeGame: (gameId: number) => Promise<boolean>;
removeGame: (gameId: number) => Promise<void>;
removeGameFromLibrary: (gameId: number) => Promise<void>;
removeGameFromDownload: (gameId: number) => Promise<vodi>;
deleteGameFolder: (gameId: number) => Promise<unknown>;
getGameByObjectID: (objectID: string) => Promise<Game | null>;
onPlaytime: (cb: (gameId: number) => void) => () => Electron.IpcRenderer;

View file

@ -57,8 +57,8 @@ export function useDownload() {
deleteGame(gameId);
});
const removeGame = (gameId: number) =>
window.electron.removeGame(gameId).then(() => {
const removeGameFromDownload = (gameId: number) =>
window.electron.removeGameFromDownload(gameId).then(() => {
updateLibrary();
});
@ -123,7 +123,7 @@ export function useDownload() {
pauseDownload,
resumeDownload,
cancelDownload,
removeGame,
removeGameFromDownload,
deleteGame,
isGameDeleting,
clearDownload: () => dispatch(clearDownload()),

View file

@ -12,5 +12,10 @@ export function useLibrary() {
.then((updatedLibrary) => dispatch(setLibrary(updatedLibrary)));
}, [dispatch]);
return { library, updateLibrary };
const removeGameFromLibrary = (gameId: number) =>
window.electron.removeGameFromLibrary(gameId).then(() => {
updateLibrary();
});
return { library, updateLibrary, removeGameFromLibrary };
}

View file

@ -52,8 +52,8 @@ export function Downloads() {
updateLibrary();
});
const removeGame = (gameId: number) =>
window.electron.removeGame(gameId).then(() => {
const removeGameFromDownload = (gameId: number) =>
window.electron.removeGameFromDownload(gameId).then(() => {
updateLibrary();
});
@ -194,7 +194,7 @@ export function Downloads() {
</Button>
<Button
onClick={() => removeGame(game.id)}
onClick={() => removeGameFromDownload(game.id)}
theme="outline"
disabled={deleting}
>

View file

@ -32,11 +32,11 @@ export function HeroPanelActions({
resumeDownload,
pauseDownload,
cancelDownload,
removeGame,
removeGameFromDownload,
isGameDeleting,
} = useDownload();
const { updateLibrary } = useLibrary();
const { updateLibrary, removeGameFromLibrary } = useLibrary();
const { t } = useTranslation("game_details");
@ -63,7 +63,7 @@ export function HeroPanelActions({
try {
if (game) {
await removeGame(game.id);
await removeGameFromLibrary(game.id);
} else {
const gameExecutablePath = await selectGameExecutable();
@ -101,6 +101,9 @@ export function HeroPanelActions({
}
const gameExecutablePath = await selectGameExecutable();
if (!gameExecutablePath) return;
window.electron.openGame(game.id, gameExecutablePath);
};
@ -187,7 +190,7 @@ export function HeroPanelActions({
{t("open_download_options")}
</Button>
<Button
onClick={() => removeGame(game.id).then(getGame)}
onClick={() => removeGameFromDownload(game.id).then(getGame)}
theme="outline"
disabled={deleting}
>