mirror of
https://github.com/hydralauncher/hydra.git
synced 2026-01-21 01:53:57 +00:00
50 lines
1.4 KiB
TypeScript
50 lines
1.4 KiB
TypeScript
import { createSlice } from "@reduxjs/toolkit";
|
|
import type { PayloadAction } from "@reduxjs/toolkit";
|
|
import type { DownloadProgress } from "@types";
|
|
|
|
export interface DownloadState {
|
|
lastPacket: DownloadProgress | null;
|
|
gameId: string | null;
|
|
gamesWithDeletionInProgress: string[];
|
|
}
|
|
|
|
const initialState: DownloadState = {
|
|
lastPacket: null,
|
|
gameId: null,
|
|
gamesWithDeletionInProgress: [],
|
|
};
|
|
|
|
export const downloadSlice = createSlice({
|
|
name: "download",
|
|
initialState,
|
|
reducers: {
|
|
setLastPacket: (state, action: PayloadAction<DownloadProgress>) => {
|
|
state.lastPacket = action.payload;
|
|
if (!state.gameId) state.gameId = action.payload.gameId;
|
|
},
|
|
clearDownload: (state) => {
|
|
state.lastPacket = null;
|
|
state.gameId = null;
|
|
},
|
|
setGameDeleting: (state, action: PayloadAction<string>) => {
|
|
if (
|
|
!state.gamesWithDeletionInProgress.includes(action.payload) &&
|
|
action.payload
|
|
) {
|
|
state.gamesWithDeletionInProgress.push(action.payload);
|
|
}
|
|
},
|
|
removeGameFromDeleting: (state, action: PayloadAction<string>) => {
|
|
const index = state.gamesWithDeletionInProgress.indexOf(action.payload);
|
|
if (index >= 0) state.gamesWithDeletionInProgress.splice(index, 1);
|
|
},
|
|
},
|
|
});
|
|
|
|
export const {
|
|
setLastPacket,
|
|
clearDownload,
|
|
setGameDeleting,
|
|
removeGameFromDeleting,
|
|
} = downloadSlice.actions;
|