import { CaseReducer, PayloadAction } from '@reduxjs/toolkit'; import { Data } from '@app/types'; import { ServerState } from './server.interfaces'; export const replayReducers = { replayList: ((state, action) => { const replays: { [gameId: number]: Data.ServerInfo_ReplayMatch } = {}; for (const match of action.payload.matchList) { replays[match.gameId] = match; } state.replays = replays; }) as CaseReducer>, replayAdded: ((state, action) => { const { matchInfo } = action.payload; state.replays[matchInfo.gameId] = matchInfo; }) as CaseReducer>, replayModifyMatch: ((state, action) => { const { gameId, doNotHide } = action.payload; const existing = state.replays[gameId]; if (!existing) { return; } existing.doNotHide = doNotHide; }) as CaseReducer>, replayDeleteMatch: ((state, action) => { delete state.replays[action.payload.gameId]; }) as CaseReducer>, replayDownloaded: ((state, action) => { state.downloadedReplay = action.payload; }) as CaseReducer>, };