Skip to content

Commit

Permalink
Fix game deletion flow to avoid locking the UI (#16)
Browse files Browse the repository at this point in the history
  • Loading branch information
Hayajiro authored Oct 12, 2022
1 parent 5853318 commit 4a01ccb
Show file tree
Hide file tree
Showing 3 changed files with 6 additions and 14 deletions.
10 changes: 4 additions & 6 deletions src/renderer/actions/game.action.ts
Original file line number Diff line number Diff line change
@@ -1,16 +1,14 @@
import { SetState } from "zustand/vanilla";
import Swal from "sweetalert2";
import useTranslation from "../i18n/I18nService";
import { invokeIpc } from "../utils";

const { t } = useTranslation();

export interface IGameAction {
deleteGameAction: (titleId: string, dataPath: string) => void,
deletedGame?: string,
deleteGameAction: (titleId: string, dataPath: string) => Promise<boolean>
}

const createGameSlice = (set: SetState<IGameAction>): IGameAction => ({
const createGameSlice = (): IGameAction => ({
deleteGameAction: async (titleId, dataPath) => {
const { isConfirmed } = await Swal.fire({
icon: "warning",
Expand All @@ -22,11 +20,11 @@ const createGameSlice = (set: SetState<IGameAction>): IGameAction => ({
});

if (!isConfirmed) {
return;
return false;
}

await invokeIpc("delete-game", titleId, dataPath);
return set({ deletedGame: titleId });
return true;
}
});

Expand Down
2 changes: 1 addition & 1 deletion src/renderer/actions/state.ts
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@ const useStore = create((set: SetState<any>, get: GetState<any>) => ({
...createAlertSlice(set),
...createEmulatorFilesSLice(set, get),
...createDownloadManagerSlice(set, get),
...createGameSlice(set),
...createGameSlice(),
...createDownloadSaveSlice(set),
...createDownloadModSlice(set),
...createShadersSlice(set),
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -58,7 +58,6 @@ const GameDetailComponent = () => {
needRefreshShaders,
shareShaders,
deleteGameAction,
deletedGame,
threshold,
shadersMinVersion
] = useStore(state => [
Expand All @@ -71,7 +70,6 @@ const GameDetailComponent = () => {
state.needRefreshShaders,
state.shareShaders,
state.deleteGameAction,
state.deletedGame,
state.threshold,
state.shadersMinVersion
]);
Expand All @@ -82,10 +80,6 @@ const GameDetailComponent = () => {
const { t } = useTranslation();
const navigate = useNavigate();

useEffect(() => {
deletedGame && navigate(-1);
}, [deletedGame]);

const extractCompatibilityLabels = (response: GithubIssue) => {
// Probably non 200 response from GitHub, so leave it as default value (null)
if (response == null) return;
Expand Down Expand Up @@ -165,7 +159,7 @@ const GameDetailComponent = () => {
<Button
variant="contained"
color="error"
onClick={() => deleteGameAction(metaData.id, dataPath)}
onClick={() => deleteGameAction(metaData.id, dataPath).then(confirmed => confirmed && navigate(-1))}
startIcon={<DeleteIcon />}
>
{t("deleteGame")}
Expand Down

0 comments on commit 4a01ccb

Please sign in to comment.