Skip to content

Commit

Permalink
refactor: Update hike initialization logic
Browse files Browse the repository at this point in the history
  • Loading branch information
petrot committed Feb 17, 2018
1 parent 9904f20 commit 60094f1
Show file tree
Hide file tree
Showing 9 changed files with 30 additions and 69 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,6 @@ const LANGS = {
styleUrls: ['./hike-edit-general-info.component.scss']
})
export class HikeEditGeneralInfoComponent implements OnInit, OnDestroy {
@Input() initialDescription: any;
public textualDescriptions$: Observable<ITextualDescriptionItem[]>;
public existingLangKeys$: Observable<string[] | number[]>;
public existingLangKeys: string[] | number[] = [];
Expand All @@ -48,7 +47,6 @@ export class HikeEditGeneralInfoComponent implements OnInit, OnDestroy {
this._hikeEditGeneralInfoSelectors.getAllDescriptions
);

this._initDescriptionsState();
this._initDescriptionsForm();

// Watch form changes and save values to store
Expand Down Expand Up @@ -84,23 +82,6 @@ export class HikeEditGeneralInfoComponent implements OnInit, OnDestroy {
});
}

/**
* Fill the store with the initial values
*/
private _initDescriptionsState() {
let descriptions: ITextualDescriptionItem[] = [];

for (let langKey in this.initialDescription) {
descriptions.push(Object.assign(this.initialDescription[langKey], {
id: langKey
}));
}

this._store.dispatch(new hikeEditGeneralInfoActions.SetDescriptions({
descriptions: descriptions
}));
}

private _createDescriptionItem(desc) {
return this._formBuilder.group({
id: [desc.id || ''],
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -42,6 +42,7 @@ export class HikeEditPoisExternalComponent implements OnInit, OnDestroy {

ngOnInit() {
this._store.select(this._hikeEditMapSelectors.getHikeEditMapMapIdSelector())
.take(1)
.subscribe((mapId: string) => {
this._map = this._adminMapService.getMapById(mapId);
});
Expand Down Expand Up @@ -72,10 +73,12 @@ export class HikeEditPoisExternalComponent implements OnInit, OnDestroy {
this.pois$
.takeUntil(this._destroy$)
.subscribe((pois) => {
// Refresh markers when the poi list has been changed
this._store.dispatch(new hikeEditPoiActions.GenerateSubdomainPoiMarkers({
subdomain: this.poiType.subdomain
}));
if (pois.length > 0) {
// Refresh markers when the poi list has been changed
this._store.dispatch(new hikeEditPoiActions.GenerateSubdomainPoiMarkers({
subdomain: this.poiType.subdomain
}));
}
});

this.markers$
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -32,6 +32,7 @@ export class HikeEditPoisGTrackComponent implements OnInit, OnDestroy {

ngOnInit() {
this._store.select(this._hikeEditMapSelectors.getHikeEditMapMapIdSelector())
.take(1)
.subscribe((mapId: string) => {
this._map = this._adminMapService.getMapById(mapId);
});
Expand Down
4 changes: 1 addition & 3 deletions src/app/pages/hike-edit/hike-edit.component.html
Original file line number Diff line number Diff line change
Expand Up @@ -16,9 +16,7 @@
<h4 class="card-title">General info</h4>
</div>
<div class="card-body">
<gt-hike-edit-general-info
[initialDescription]="hikeData.description"
></gt-hike-edit-general-info>
<gt-hike-edit-general-info></gt-hike-edit-general-info>
</div>
</div>
</div>
Expand Down
33 changes: 19 additions & 14 deletions src/app/pages/hike-edit/hike-edit.component.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ import { Title } from '@angular/platform-browser';
import { ActivatedRoute } from '@angular/router';
import { Subject } from 'rxjs/Subject';
import { Store } from '@ngrx/store';
import { State, hikeEditActions } from 'app/store';
import { State, hikeEditActions, hikeEditGeneralInfoActions } from 'app/store';

import { HikeDataService } from 'app/shared/services';
import { IMockHikeElement } from 'app/shared/interfaces';
Expand All @@ -17,7 +17,7 @@ import * as uuid from 'uuid/v4';
styleUrls: ['./hike-edit.component.scss']
})
export class HikeEditComponent implements OnInit, OnDestroy {
public hikeData: IMockHikeElement;
public hikeData: IMockHikeElement = {};
private _hikeId: string;
private _destroy$: Subject<boolean> = new Subject<boolean>();

Expand All @@ -34,28 +34,35 @@ export class HikeEditComponent implements OnInit, OnDestroy {
.subscribe(params => {
// Load hike data from mock DB
if (params && params.id) {
this._hikeId = params.id;
// Generate hike id
this._store.dispatch(new hikeEditGeneralInfoActions.SetHikeId({
hikeId: params.id
}));

// Set page title
this._title.setTitle('Edit hike');

// todo: load from db
this.hikeData = this._hikeDataService.getHike(params.id);
// Create new hike
} else {
this._hikeId = uuid();
// Generate hike id
this._store.dispatch(new hikeEditGeneralInfoActions.SetHikeId({
hikeId: uuid()
}));

// Set page title
this._title.setTitle('New hike');

// todo: from store
this.hikeData = {
description: {
'en_US': {
// Create initial language block
this._store.dispatch(new hikeEditGeneralInfoActions.SetDescriptions({
descriptions: [{
id: 'en_US',
title: '',
fullDescription: '',
summary: ''
}
}
};
}]
}));
}
});
}
Expand All @@ -66,8 +73,6 @@ export class HikeEditComponent implements OnInit, OnDestroy {
}

public saveHike() {
this._store.dispatch(new hikeEditActions.CollectHikeData({
hikeId: this._hikeId
}));
this._store.dispatch(new hikeEditActions.CollectHikeData());
}
}
1 change: 1 addition & 0 deletions src/app/shared/services/index.ts
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
export * from './hike-data/hike-data.service';
export * from './hike-data/reverse-geocoding.service';
export * from './admin-map/admin-map.service';
export * from './poi';
22 changes: 0 additions & 22 deletions src/app/shared/services/poi/google-poi.service.ts
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,6 @@ export class GooglePoiService {
public get(bounds, lng = 'en') {
return this._googleMapsService.map
.then(() => {
this._createFakeMapInstance();
this._hasNextPage$.next(true);

const _map = new google.maps.Map(document.getElementById('fakeMap'));
Expand Down Expand Up @@ -79,27 +78,6 @@ export class GooglePoiService {
});
}

/**
* get() submethod
*/
private _createFakeMapInstance() {
let fakeDiv: HTMLDivElement = document.createElement('div');
fakeDiv.id = 'fakeMap';
fakeDiv.style.display = 'none';
document.body.appendChild(fakeDiv);
}

/**
* get() submethod
*/
private _removeFakeMapInstance() {
let fakeDiv: HTMLElement | null = document.getElementById('fakeMap');

if (fakeDiv !== null) {
document.body.removeChild(fakeDiv);
}
}

/**
* get() submethod
*/
Expand Down
4 changes: 0 additions & 4 deletions src/app/shared/services/poi/poi-editor.service.ts
Original file line number Diff line number Diff line change
Expand Up @@ -384,10 +384,6 @@ export class PoiEditorService {
}
});

// 1. Típusnak megfelelő markereket levenni a térképről
// 2. Markerek generálása és az entity lista lecserélése (addMany)
// 3. Láthatóság frissítése entity

const _onRoutePois = this._getOnroutePois(_filteredPois);
const _offRoutePois = this._getOffroutePois(_filteredPois);

Expand Down
4 changes: 1 addition & 3 deletions src/app/store/actions/hike-edit.ts
Original file line number Diff line number Diff line change
Expand Up @@ -4,9 +4,7 @@ export const COLLECT_HIKE_DATA = '[HikeEdit] Collect hike data';

export class CollectHikeData implements Action {
readonly type = COLLECT_HIKE_DATA;
constructor(public payload: {
hikeId: string
}) { /* EMPTY */ }
constructor() { /* EMPTY */ }
}

export type AllHikeEditActions =
Expand Down

0 comments on commit 60094f1

Please sign in to comment.