Permalink
Browse files

Add logic for tracking the currently selected pilot

  • Loading branch information...
markerikson committed Dec 8, 2016
1 parent 7a5b756 commit c42c5bdecc1469481089c2b83273930cb9bd2781
@@ -3,11 +3,13 @@ import {combineReducers} from "redux";
import entitiesReducer from "./entitiesReducer";
import tabReducer from "features/tabs/tabReducer";
import unitInfoReducer from "features/unitInfo/unitInfoReducer";
import pilotsReducer from "features/pilots/pilotsReducer";
const rootReducer = combineReducers({
entities : entitiesReducer,
unitInfo : unitInfoReducer,
pilots : pilotsReducer,
tabs : tabReducer,
});
@@ -0,0 +1,8 @@
import {PILOT_SELECT} from "./pilotsConstants";
export function selectPilot(pilotID) {
return {
type : PILOT_SELECT,
payload : {currentPilot : pilotID},
};
}
@@ -0,0 +1 @@
export const PILOT_SELECT = "PILOT_SELECT";
@@ -0,0 +1,25 @@
import {createReducer} from "common/utils/reducerUtils";
import {PILOT_SELECT} from "./pilotsConstants";
const initialState = {
currentPilot : null
};
export function selectPilot(state, payload) {
const prevSelectedPilot = state.currentPilot;
const newSelectedPilot = payload.currentPilot;
const isSamePilot = prevSelectedPilot === newSelectedPilot;
return {
// Deselect entirely if it's a second click on the same pilot,
// otherwise go ahead and select the one that was clicked
currentPilot : isSamePilot ? null : newSelectedPilot,
};
}
export default createReducer(initialState, {
[PILOT_SELECT] : selectPilot,
});
@@ -0,0 +1,8 @@
import {createSelector} from "reselect";
export const selectPilots = state => state.pilots;
export const selectCurrentPilot = createSelector(
selectPilots,
pilots => pilots.currentPilot,
);

0 comments on commit c42c5bd

Please sign in to comment.