Skip to content

Commit

Permalink
feat: add setDirty parameter to AddHikeProgramDetails action
Browse files Browse the repository at this point in the history
Closes: #178
  • Loading branch information
petrot committed Apr 26, 2018
1 parent 93c5db0 commit 9c4be36
Show file tree
Hide file tree
Showing 5 changed files with 25 additions and 13 deletions.
18 changes: 13 additions & 5 deletions src/app/pages/hike-edit/components/hike-edit-general-info/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -42,14 +42,22 @@ export class HikeEditGeneralInfoComponent implements OnInit, OnDestroy {
this._initDescriptionFormConfig();

// Selectors
this.isRoundTrip$ = this._store.select(this._hikeEditRoutePlannerSelectors.getIsRoundTrip)
this.hikeProgramData$ = this._store.select(this._editedHikeProgramSelectors.getData)
this.remoteError$ = this._store.select(this._editedHikeProgramSelectors.getError)
this.isRoundTrip$ = this._store
.select(this._hikeEditRoutePlannerSelectors.getIsRoundTrip)
.takeUntil(this._destroy$);
this.hikeProgramData$ = this._store
.select(this._editedHikeProgramSelectors.getData)
.takeUntil(this._destroy$);
this.remoteError$ = this._store
.select(this._editedHikeProgramSelectors.getError)
.takeUntil(this._destroy$);

this.isRoundTrip$
.takeUntil(this._destroy$)
.subscribe((isRoundTrip: boolean) => {
this._store.dispatch(new editedHikeProgramActions.AddHikeProgramDetails({isRoundTrip: isRoundTrip}));
this._store.dispatch(new editedHikeProgramActions.AddHikeProgramDetails({
isRoundTrip: isRoundTrip
}, false));
});
}

Expand All @@ -62,7 +70,7 @@ export class HikeEditGeneralInfoComponent implements OnInit, OnDestroy {
translatableLabel: 'form.submit',
classList: ['btn', 'btn-sm', 'btn-fill', 'btn-success'],
submitFv: (formGroup: FormGroup) => {
return this._store.dispatch(new editedHikeProgramActions.AddHikeProgramDetails(formGroup.value));
return this._store.dispatch(new editedHikeProgramActions.AddHikeProgramDetails(formGroup.value, true));
}
},
fields: {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -85,7 +85,7 @@ export class HikeEditRoutePlannerComponent implements OnInit, OnDestroy {
.subscribe((route: any) => {
// Clear location
if (route.features.length === 1) {
this._store.dispatch(new editedHikeProgramActions.AddHikeProgramDetails({ location: '' }));
this._store.dispatch(new editedHikeProgramActions.AddHikeProgramDetails({ location: '' }, false));
// 1st segment added (line + 2 points)
} else if (route.features.length === 3) {
this._updateLocation(route.features[1].geometry.coordinates);
Expand All @@ -98,7 +98,7 @@ export class HikeEditRoutePlannerComponent implements OnInit, OnDestroy {
.subscribe((total: IHikeEditRoutePlannerTotalState) => {
this._store.dispatch(new editedHikeProgramActions.AddHikeProgramDetails(
_.pick(total, ['distance', 'uphill', 'downhill', 'time', 'score'])
));
), true);
});
}

Expand Down Expand Up @@ -146,9 +146,9 @@ export class HikeEditRoutePlannerComponent implements OnInit, OnDestroy {
lon: coords[0]
})
.then((location: string) => {
this._store.dispatch(new editedHikeProgramActions.AddHikeProgramDetails({ location: location }));
this._store.dispatch(new editedHikeProgramActions.AddHikeProgramDetails({ location: location }, false));
}, err => {
this._store.dispatch(new editedHikeProgramActions.AddHikeProgramDetails({ location: '' }));
this._store.dispatch(new editedHikeProgramActions.AddHikeProgramDetails({ location: '' }, false));
}
);
}
Expand Down
2 changes: 1 addition & 1 deletion src/app/store/actions/edited-hike-program.ts
Original file line number Diff line number Diff line change
Expand Up @@ -43,7 +43,7 @@ export interface IDetails {
export class AddHikeProgramDetails implements Action {
readonly type = ADD_HIKE_PROGRAM_DETAILS;

constructor(public details: IDetails) {}
constructor(public details: IDetails, public setDirty: boolean) {}
}

export class AddStop implements Action {
Expand Down
5 changes: 3 additions & 2 deletions src/app/store/actions/test/edited-hike-program.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -40,12 +40,13 @@ describe('EditedHikeProgram actions', () => {
});

it('should create AddHikeProgramDetails action', () => {
const action = new EditedHikeProgramActions.AddHikeProgramDetails({ distance: 10 });
const action = new EditedHikeProgramActions.AddHikeProgramDetails({ distance: 10 }, true);

expect(action).toBeDefined();
expect({ ...action }).toEqual({
type: EditedHikeProgramActions.ADD_HIKE_PROGRAM_DETAILS,
details: { distance: 10 }
details: { distance: 10 },
setDirty: true
});
});

Expand Down
5 changes: 4 additions & 1 deletion src/app/store/reducer/edited-hike-program.ts
Original file line number Diff line number Diff line change
Expand Up @@ -64,8 +64,11 @@ export const editedHikeProgramReducer: ActionReducer<IEditedHikeProgramState> =
}

case editedHikeProgramActions.ADD_HIKE_PROGRAM_DETAILS: {
newState.dirty = true;
newState.data = _.assign(newState.data, action.details);
if (action.setDirty) {
newState.dirty = true;
}

return newState;
}

Expand Down

0 comments on commit 9c4be36

Please sign in to comment.