Permalink
Browse files

Add logic to track if a pilot is being edited

  • Loading branch information...
markerikson committed Jan 7, 2017
1 parent 745eda8 commit 09fda20959bdcad88252320e2874664c43b3e7a9
@@ -1,8 +1,24 @@
import {PILOT_SELECT} from "./pilotsConstants";
import {
PILOT_SELECT,
PILOT_EDIT_START,
PILOT_EDIT_STOP,
} from "./pilotsConstants";
export function selectPilot(pilotID) {
return {
type : PILOT_SELECT,
payload : {currentPilot : pilotID},
};
}
export function startEditingPilot() {
return {
type : PILOT_EDIT_START,
};
}
export function stopEditingPilot() {
return {
type : PILOT_EDIT_STOP,
};
}
@@ -1 +1,3 @@
export const PILOT_SELECT = "PILOT_SELECT";
export const PILOT_SELECT = "PILOT_SELECT";
export const PILOT_EDIT_START = "PILOT_EDIT_START";
export const PILOT_EDIT_STOP = "PILOT_EDIT_STOP";
@@ -1,9 +1,14 @@
import {createReducer} from "common/utils/reducerUtils";
import {PILOT_SELECT} from "./pilotsConstants";
import {
PILOT_SELECT,
PILOT_EDIT_START,
PILOT_EDIT_STOP,
} from "./pilotsConstants";
const initialState = {
currentPilot : null
currentPilot : null,
isEditing : false,
};
export function selectPilot(state, payload) {
@@ -13,13 +18,32 @@ export function selectPilot(state, payload) {
const isSamePilot = prevSelectedPilot === newSelectedPilot;
return {
...state,
// 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,
// Any time we select a different pilot, we stop editing
isEditing : false,
};
}
export function startEditingPilot(state, payload) {
return {
...state,
isEditing : true,
};
}
export function stopEditingPilot(state, payload) {
return {
...state,
isEditing : false,
};
}
export default createReducer(initialState, {
[PILOT_SELECT] : selectPilot,
[PILOT_EDIT_START] : startEditingPilot,
[PILOT_EDIT_STOP] : stopEditingPilot,
});
@@ -5,4 +5,9 @@ export const selectPilots = state => state.pilots;
export const selectCurrentPilot = createSelector(
selectPilots,
pilots => pilots.currentPilot,
);
export const selectIsEditingPilot = createSelector(
selectPilots,
pilots => pilots.isEditing
);

0 comments on commit 09fda20

Please sign in to comment.