diff --git a/src/app/router/router.component.ts b/src/app/router/router.component.ts index 0edbf38d..e40a1beb 100644 --- a/src/app/router/router.component.ts +++ b/src/app/router/router.component.ts @@ -11,7 +11,7 @@ import { ActivatedRoute, Router } from '@angular/router'; import { combineLatest, of } from 'rxjs/index'; import { SubscriptionService } from '../core/subscription.service'; import { CityService } from '../city/city.service'; -import { RouteValidatorService } from '../services/route-validator.service'; +import { RoutingService } from '../services/routing.service'; import { switchMap } from 'rxjs/operators'; @Component({ @@ -25,7 +25,7 @@ export class RouterComponent implements OnInit { private subscriptionService: SubscriptionService, private route: ActivatedRoute, private router: Router, - private routeValidator: RouteValidatorService, + private routeValidator: RoutingService, private cityService: CityService ) {} diff --git a/src/app/services/route-validator.service.ts b/src/app/services/routing.service.ts similarity index 94% rename from src/app/services/route-validator.service.ts rename to src/app/services/routing.service.ts index d117e5aa..e29d480b 100644 --- a/src/app/services/route-validator.service.ts +++ b/src/app/services/routing.service.ts @@ -16,9 +16,8 @@ import { DataService, lookupFountainAlias } from '../data.service'; import { FountainService } from '../fountain/fountain.service'; import { City } from '../locations'; import { CityService, defaultCity } from '../city/city.service'; -import { illegalState } from '../shared/illegalState'; -import { Database, FountainSelector, isDatabase, LngLat } from '../types'; -import { getSingleNumericParam, getSingleStringParam, isNumeric } from './utils'; +import { Database, FountainSelector, LngLat } from '../types'; +import { getSingleStringParam, isNumeric } from './utils'; import { catchError, filter, first } from 'rxjs/operators'; import { MapConfig } from '../map/map.config'; @@ -41,7 +40,7 @@ export interface QueryParams { @Injectable({ providedIn: 'root', }) -export class RouteValidatorService { +export class RoutingService { // Validates route names constructor( @@ -329,22 +328,18 @@ export class RouteValidatorService { getShortenedQueryParams(): Observable { return this.fountainService.fountainSelector.map(fountainSelector => { // Get query parameter values from app state. use short query params by default for #159 - const queryParams: QueryParams = { - l: this.languageService.currentLang, // use short language by default// mode: state.mode, - }; - if (fountainSelector !== undefined) { - if (fountainSelector.queryType === 'byCoords') { - // if selection by coordinates - queryParams.lat = fountainSelector.lat; - queryParams.lng = fountainSelector.lng; - } else if (fountainSelector.queryType === 'byId') { - // if selection by id - queryParams.i = fountainSelector.idval; - } - } + const queryParams: QueryParams = fountainSelector ? this.getQueryParamsForSelector(fountainSelector) : {}; + queryParams.l = this.languageService.currentLang; return queryParams; }); } + + private getQueryParamsForSelector(fountainSelector: FountainSelector): QueryParams { + switch (fountainSelector.queryType) { + case 'byId': + return { l: this.languageService.currentLang }; + } + } } function isWikidataId(id: string): boolean { diff --git a/src/app/types.ts b/src/app/types.ts index 5d7b1cc8..8f735c10 100644 --- a/src/app/types.ts +++ b/src/app/types.ts @@ -285,7 +285,7 @@ export function isDatabase(s: string): s is Database { } export interface FountainSelector { - queryType: 'byCoords' | 'byId'; + queryType: 'byId'; lat?: number; lng?: number; radius?: number;