Téléchargmeent des mises à jour de solde
This commit is contained in:
43
client/utils/features/moneyUpdates/moneyUpdatesSlice.ts
Normal file
43
client/utils/features/moneyUpdates/moneyUpdatesSlice.ts
Normal 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
|
Reference in New Issue
Block a user