Permalink
Browse files

Rework pilot logic to explicitly stop editing on selection

  • Loading branch information...
markerikson committed Jan 25, 2017
1 parent 4bd028d commit 485104998e13fe58366d6a9539a883dd6e431566
@@ -98,12 +98,12 @@ export class PilotDetails extends Component {
onStartEditingClicked = () => {
const {id} = this.props.pilot;
this.props.startEditingPilot(id);
this.props.startEditingPilot();
}
onStopEditingClicked = () => {
const {id} = this.props.pilot;
this.props.stopEditingPilot(id);
this.props.stopEditingPilot();
}
@@ -9,24 +9,39 @@ import {
PILOT_EDIT_STOP,
} from "./pilotsConstants";
import {selectCurrentPilot, selectIsEditingPilot} from "./pilotsSelectors";
export function selectPilot(pilotID) {
return {
type : PILOT_SELECT,
payload : {currentPilot : pilotID},
};
return (dispatch, getState) => {
const state = getState();
const isEditing = selectIsEditingPilot(state);
if(isEditing) {
dispatch(stopEditingPilot())
}
dispatch({
type : PILOT_SELECT,
payload : {currentPilot : pilotID},
});
}
}
export function startEditingPilot(pilotID) {
export function startEditingPilot() {
return (dispatch, getState) => {
dispatch(editExistingItem("Pilot", pilotID));
const currentPilot = selectCurrentPilot(getState());
dispatch(editExistingItem("Pilot", currentPilot));
dispatch({type : PILOT_EDIT_START});
}
}
export function stopEditingPilot(pilotID) {
export function stopEditingPilot() {
return (dispatch, getState) => {
const currentPilot = selectCurrentPilot(getState());
dispatch({type : PILOT_EDIT_STOP});
dispatch(stopEditingItem("Pilot", pilotID));
dispatch(stopEditingItem("Pilot", currentPilot));
}
}
@@ -26,8 +26,6 @@ export function selectPilot(state, payload) {
// 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,
};
}

0 comments on commit 4851049

Please sign in to comment.