Permalink
Browse files

Extract common "stop editing pilot" logic

  • Loading branch information...
markerikson committed Dec 29, 2017
1 parent 179cc52 commit 8ceeece28aa08abe84f12264626afb0b5a807e0e
Showing with 26 additions and 7 deletions.
  1. +26 −7 src/features/pilots/pilotsActions.js
@@ -14,7 +14,7 @@ import {
} from "./pilotsConstants";
import {selectCurrentPilot, selectIsEditingPilot} from "./pilotsSelectors";
import {getUnsharedEntitiesSession} from "features/entities/entitySelectors";
import {getEntitiesSession, getUnsharedEntitiesSession} from "features/entities/entitySelectors";
export function selectPilot(pilotID) {
return (dispatch, getState) => {
@@ -42,22 +42,41 @@ export function startEditingPilot() {
}
}
export function stopEditingPilot() {
export function handleStopEditingPilot(applyEdits = true) {
return (dispatch, getState) => {
const currentPilot = selectCurrentPilot(getState());
// Determine if it's a new pilot based on the "current" slice contents
const session = getEntitiesSession(getState());
const {Pilot} = session;
const isNewPilot = !Pilot.hasId(currentPilot);
dispatch({type : PILOT_EDIT_STOP});
dispatch(applyItemEdits("Pilot", currentPilot));
if(applyEdits) {
dispatch(applyItemEdits("Pilot", currentPilot));
}
dispatch(stopEditingItem("Pilot", currentPilot));
if(isNewPilot) {
dispatch({type : PILOT_SELECT, payload : {currentPilot : null}});
}
}
}
export function cancelEditingPilot() {
export function stopEditingPilot() {
return (dispatch, getState) => {
const currentPilot = selectCurrentPilot(getState());
dispatch(handleStopEditingPilot(true));
}
}
dispatch({type : PILOT_EDIT_STOP});
dispatch(stopEditingItem("Pilot", currentPilot));
export function cancelEditingPilot() {
return (dispatch, getState) => {
dispatch(handleStopEditingPilot(false));
}
}

0 comments on commit 8ceeece

Please sign in to comment.