ISSUE-032 - Defined a great number of new state types for use with the race event's state, the broadcast director's controls, and the broadcast graphics states.
Taking a second to make a commit to save my progress so far.
This commit is contained in:
1 parent
ef0b58e98b
commit
5d009a3d70
12 files changed
+254
-21
No files matched your search
@@ -0,0 +1,3 @@
|
||||
import { RootState } from "../../../types/state";
|
||||
|
||||
export const broadcastDirectorSelector = (state: RootState) => state.broadcastDirector;
|
||||
@@ -0,0 +1,46 @@
|
||||
import { createSlice, PayloadAction } from "@reduxjs/toolkit";
|
||||
import { findIndex } from "lodash";
|
||||
|
||||
import { RootState, Car } from "../../../types/state";
|
||||
|
||||
const initialState: RootState["broadcastDirector"] = {
|
||||
selectedCars: [],
|
||||
};
|
||||
|
||||
const carMatch = (targetCar: Car) => (checkedCar: Car) =>
|
||||
checkedCar.driver.id === targetCar.driver.id;
|
||||
|
||||
export const broadcastDirectorSlice = createSlice({
|
||||
name: "broadcastDirector",
|
||||
initialState,
|
||||
reducers: {
|
||||
selectedCarsAdd: (state, action: PayloadAction<Car>) => {
|
||||
const index = findIndex(state.selectedCars, carMatch(action.payload));
|
||||
if (index === -1) {
|
||||
state.selectedCars = state.selectedCars.concat(action.payload);
|
||||
}
|
||||
},
|
||||
selectedCarsSet: (state, action: PayloadAction<Car>) => { // Might be removed.
|
||||
state.selectedCars = [action.payload];
|
||||
},
|
||||
selectedCarsRemove: (state, action: PayloadAction<Car | number>) => {
|
||||
const index = typeof action.payload === "number"
|
||||
? action.payload
|
||||
: findIndex(state.selectedCars, carMatch(action.payload));
|
||||
state.selectedCars = state.selectedCars.slice(0, index).concat(
|
||||
state.selectedCars.slice(index + 1),
|
||||
);
|
||||
},
|
||||
selectedCarsClear: (state) => {
|
||||
state.selectedCars = [];
|
||||
},
|
||||
},
|
||||
});
|
||||
|
||||
export const {
|
||||
selectedCarsAdd,
|
||||
selectedCarsSet,
|
||||
selectedCarsRemove,
|
||||
selectedCarsClear,
|
||||
} = broadcastDirectorSlice.actions;
|
||||
export default broadcastDirectorSlice.reducer;
|
||||
Reference in new issue
Block a user