Skip to content

Commit

Permalink
feat: handling hike save button state (enabled/disabled) based on nec…
Browse files Browse the repository at this point in the history
…essary data.
  • Loading branch information
petrot committed Mar 30, 2018
1 parent 66aeb43 commit 9012ba8
Show file tree
Hide file tree
Showing 3 changed files with 12 additions and 4 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -143,7 +143,7 @@ export class HikeEditGeneralInfoComponent implements OnInit, OnDestroy {
if (this.hikeForm.controls._selLang.value) {
(<FormArray>this.hikeForm.controls.langs).push(
this._createDescriptionItem({
id: this.hikeForm.controls._selLang.value,
id: this.hikeForm.controls._selLang.value,
title: '',
fullDescription: '',
summary: ''
Expand Down
2 changes: 1 addition & 1 deletion src/app/pages/hike-edit/hike-edit.component.html
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@
<button
class="btn btn-sm btn-fill btn-success"
(click)="saveHike()"
[disabled]="(hikePoiIds$ | async)?.length < 1 || (routeInfoData$ | async)?.segments.length < 1"
[disabled]="!(allowSave$ | async)"
>Save hike</button>
</div>
</div>
Expand Down
12 changes: 10 additions & 2 deletions src/app/pages/hike-edit/hike-edit.component.ts
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@ import * as uuid from 'uuid/v1';
styleUrls: ['./hike-edit.component.scss']
})
export class HikeEditComponent implements OnInit, OnDestroy {
public hikePoiIds$: Observable<string[]>;
public allowSave$: Observable<boolean>;
public routeInfoData$: Observable<IHikeEditRoutePlannerState>;
private _hikeId: string;
private _destroy$: Subject<boolean> = new Subject<boolean>();
Expand Down Expand Up @@ -85,9 +85,17 @@ export class HikeEditComponent implements OnInit, OnDestroy {
}
});

this.hikePoiIds$ = this._store.select(this._hikeEditGeneralInfoSelectors.getPois);
this.routeInfoData$ = this._store.select(this._hikeEditRoutePlannerSelectors.getRoutePlanner);

this.allowSave$ = Observable.combineLatest(
this._store.select(this._hikeEditGeneralInfoSelectors.getPois),
this.routeInfoData$
).map(data => {
const _pois = data[0];
const _segments = data[1].segments;
return _pois.length > 0 && (_segments && _segments.length > 0);
})

// Handling hike save
this._store.select(this._hikeEditGeneralInfoSelectors.getHikeId)
.takeUntil(this._destroy$)
Expand Down

0 comments on commit 9012ba8

Please sign in to comment.