Téléchargmeent des mises à jour de solde

This commit is contained in:
2024-12-13 23:07:37 +01:00
parent 4a33963c12
commit 02304527d3
7 changed files with 82 additions and 4 deletions

View File

@ -0,0 +1,43 @@
import { createSlice, PayloadAction } from '@reduxjs/toolkit'
import { PaginationMeta } from '../common'
export interface MoneyUpdate {
id: number
playerId: number
reason: 'START' | 'NEW_RUN' | 'BUY_TRAIN' | 'WIN_CHALLENGE'
timestamp: number
runId: number | null
actionId: number | null
tripId: number | null
}
export interface MoneyUpdatesState {
moneyUpdates: MoneyUpdate[]
}
const initialState: MoneyUpdatesState = {
moneyUpdates: []
}
export interface MoneyUpdatesPayload {
data: MoneyUpdate[]
meta: PaginationMeta
}
export const moneyUpdatesSlice = createSlice({
name: 'moneyUpdates',
initialState: initialState,
reducers: {
downloadMoneyUpdates(state, action: PayloadAction<MoneyUpdatesPayload>) {
state.moneyUpdates = state.moneyUpdates.filter(moneyUpdate => action.payload.data.filter(dlMU => dlMU.id === moneyUpdate.id) === null)
for (const dlMU of action.payload.data) {
state.moneyUpdates.push(dlMU)
}
state.moneyUpdates.sort((mu1, mu2) => mu2.id - mu1.id)
},
},
})
export const { downloadMoneyUpdates } = moneyUpdatesSlice.actions
export default moneyUpdatesSlice.reducer

View File

@ -4,6 +4,7 @@ import challengesReducer from './features/challenges/challengesSlice'
import challengeActionsReducer from './features/challengeActions/challengeActionsSlice'
import gameReducer from './features/game/gameSlice'
import locationReducer from './features/location/locationSlice'
import moneyUpdatesReducer from './features/moneyUpdates/moneyUpdatesSlice'
import trainReducer from './features/train/trainSlice'
const store = configureStore({
@ -13,6 +14,7 @@ const store = configureStore({
challengeActions: challengeActionsReducer,
game: gameReducer,
location: locationReducer,
moneyUpdates: moneyUpdatesReducer,
train: trainReducer,
},
})