Permalink
Browse files

Add logic for tracking the currently selected mech

  • Loading branch information...
markerikson committed Dec 8, 2016
1 parent 19c3c3a commit 54794acd672238117943aec309ab5ff75e5ceb7c
@@ -4,12 +4,14 @@ import entitiesReducer from "./entitiesReducer";
import tabReducer from "features/tabs/tabReducer";
import unitInfoReducer from "features/unitInfo/unitInfoReducer";
import pilotsReducer from "features/pilots/pilotsReducer";
import mechsReducer from "features/mechs/mechsReducer";
const rootReducer = combineReducers({
entities : entitiesReducer,
unitInfo : unitInfoReducer,
pilots : pilotsReducer,
mechs : mechsReducer,
tabs : tabReducer,
});
@@ -1,4 +1,4 @@
import {createSelector} from "reselect";
const WEIGHT_CLASSES = [
{name : "Light", weights : [20, 25, 30, 35]},
@@ -11,3 +11,11 @@ export function getWeightClass(weight) {
const weightClass = WEIGHT_CLASSES.find(wc => wc.weights.includes(weight)) || {name : "Unknown"};
return weightClass.name;
}
const selectMechs = state => state.mechs;
export const selectCurrentMech = createSelector(
selectMechs,
mechs => mechs.currentMech,
);
@@ -0,0 +1,8 @@
import {MECH_SELECT} from "./mechsConstants";
export function selectMech(mechID) {
return {
type : MECH_SELECT,
payload : {currentMech : mechID},
};
}
@@ -0,0 +1 @@
export const MECH_SELECT = "MECH_SELECT";
@@ -0,0 +1,25 @@
import {createReducer} from "common/utils/reducerUtils";
import {MECH_SELECT} from "./mechsConstants";
const initialState = {
currentMech : null
};
export function selectMech(state, payload) {
const prevSelectedMech = state.currentMech;
const newSelectedMech = payload.currentMech;
const isSameMech = prevSelectedMech === newSelectedMech;
return {
// Deselect entirely if it's a second click on the same mech,
// otherwise go ahead and select the one that was clicked
currentMech : isSameMech ? null : newSelectedMech,
};
}
export default createReducer(initialState, {
[MECH_SELECT] : selectMech,
});

0 comments on commit 54794ac

Please sign in to comment.