From 9c4be3684fc0bc73a76109dc9d7c9fd8a5b9449c Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Petro=CC=81=20Tama=CC=81s?= Date: Fri, 27 Apr 2018 01:40:16 +0200 Subject: [PATCH] feat: add setDirty parameter to AddHikeProgramDetails action Closes: #178 --- .../components/hike-edit-general-info/index.ts | 18 +++++++++++++----- .../hike-edit-route-planner/index.ts | 8 ++++---- src/app/store/actions/edited-hike-program.ts | 2 +- .../actions/test/edited-hike-program.spec.ts | 5 +++-- src/app/store/reducer/edited-hike-program.ts | 5 ++++- 5 files changed, 25 insertions(+), 13 deletions(-) diff --git a/src/app/pages/hike-edit/components/hike-edit-general-info/index.ts b/src/app/pages/hike-edit/components/hike-edit-general-info/index.ts index 3b3f1848..b9b3532b 100644 --- a/src/app/pages/hike-edit/components/hike-edit-general-info/index.ts +++ b/src/app/pages/hike-edit/components/hike-edit-general-info/index.ts @@ -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)); }); } @@ -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: { diff --git a/src/app/pages/hike-edit/components/hike-edit-route-planner/index.ts b/src/app/pages/hike-edit/components/hike-edit-route-planner/index.ts index 9ad873db..57c80a0f 100644 --- a/src/app/pages/hike-edit/components/hike-edit-route-planner/index.ts +++ b/src/app/pages/hike-edit/components/hike-edit-route-planner/index.ts @@ -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); @@ -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); }); } @@ -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)); } ); } diff --git a/src/app/store/actions/edited-hike-program.ts b/src/app/store/actions/edited-hike-program.ts index 52f48ca1..f711d30b 100644 --- a/src/app/store/actions/edited-hike-program.ts +++ b/src/app/store/actions/edited-hike-program.ts @@ -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 { diff --git a/src/app/store/actions/test/edited-hike-program.spec.ts b/src/app/store/actions/test/edited-hike-program.spec.ts index 2aa5c40a..0292fdab 100644 --- a/src/app/store/actions/test/edited-hike-program.spec.ts +++ b/src/app/store/actions/test/edited-hike-program.spec.ts @@ -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 }); }); diff --git a/src/app/store/reducer/edited-hike-program.ts b/src/app/store/reducer/edited-hike-program.ts index 7a479e57..884e7f33 100644 --- a/src/app/store/reducer/edited-hike-program.ts +++ b/src/app/store/reducer/edited-hike-program.ts @@ -64,8 +64,11 @@ export const editedHikeProgramReducer: ActionReducer = } case editedHikeProgramActions.ADD_HIKE_PROGRAM_DETAILS: { - newState.dirty = true; newState.data = _.assign(newState.data, action.details); + if (action.setDirty) { + newState.dirty = true; + } + return newState; }