Skip to content

Commit

Permalink
fix forceReload for byId and cleanup eslint unused-vars
Browse files Browse the repository at this point in the history
selectFountainBySelector did not send the `refresh` query param to the
server

moreover:
- fix eslint setup regarding unused-vars, remove suppression in
  map.service.ts and language.service.ts
  • Loading branch information
robstoll committed Dec 20, 2021
1 parent 81671bf commit 22ed17c
Show file tree
Hide file tree
Showing 7 changed files with 23 additions and 19 deletions.
3 changes: 1 addition & 2 deletions .eslintrc.js
Original file line number Diff line number Diff line change
Expand Up @@ -41,7 +41,7 @@ module.exports = {
'prettier',
],
rules: {
'no-unused-vars': 'off', // same as "@typescript-eslint/no-unused-vars": "off",
'@typescript-eslint/no-unused-vars': 'off',
'unused-imports/no-unused-imports': 'error',
'unused-imports/no-unused-vars': [
'warn',
Expand All @@ -64,7 +64,6 @@ module.exports = {
},
],

'@typescript-eslint/no-unused-vars': ['error', { argsIgnorePattern: '^_' }],
'@typescript-eslint/explicit-module-boundary-types': 'error',

'@typescript-eslint/array-type': 'error',
Expand Down
2 changes: 0 additions & 2 deletions src/app/city/map.service.ts
Original file line number Diff line number Diff line change
Expand Up @@ -86,9 +86,7 @@ type Overlaps<T extends any[]> = {
: ['Elements at indices', K | L, 'both contain', T[K] & T[L]];
}[number];
}[number];
// eslint-disable-next-line @typescript-eslint/no-unused-vars
type ExpectNever<_T extends never> = void;
// eslint-disable-next-line @typescript-eslint/no-unused-vars
type _CheckCityAndFountainDoNotOverlapp = ExpectNever<Overlaps<[AllCityRelatedIdentifiers, FountainAliases]>>;

export interface MapState {
Expand Down
4 changes: 1 addition & 3 deletions src/app/core/language.service.ts
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ import { BehaviorSubject, Observable } from 'rxjs';
import { Config, ConfigBasedParserService } from './config-based-parser.service';
import { Translated } from '../locations';

// TODO @ralf.hauser this types, const should be shared with datablue/shared-constans.ts
// TODO @ralf.hauser this types, const should be shared with datablue/shared-constants.ts
export const AVAILABLE_LANGS = ['en', 'de', 'fr', 'it', 'tr' /*, 'sr'*/] as const;
export type Lang = typeof AVAILABLE_LANGS[number];

Expand Down Expand Up @@ -45,9 +45,7 @@ const internalLanguageConfig = [
] as const;
const languageConfig: readonly Config<Lang>[] = internalLanguageConfig;

// check that we cover all Lang which are defined in Translated and vice versa
const _checkLangAndTranslatedInSync1: Lang = 'en' as keyof Translated<unknown>;
// eslint-disable-next-line @typescript-eslint/no-unused-vars
const _checkLangAndTranslatedInSync2: keyof Translated<unknown> = _checkLangAndTranslatedInSync1;

const _checkConfigAndAvailableLangInSync1: Pick<typeof internalLanguageConfig[number], 'code'> = { code: defaultLang };
Expand Down
13 changes: 8 additions & 5 deletions src/app/data.service.ts
Original file line number Diff line number Diff line change
Expand Up @@ -767,15 +767,15 @@ export class DataService {
const cached = this.findCachedFountain(fountainSelector);
// If not forced reload and data cached is complete, then don't call API but use cached fountain instead
if (!forceReload && cached && this.isCachedDataComplete(cached, fountainSelector.idval)) {
this.getCachedFountainDetails(cached, fountainSelector);
this.switchToCachedFountainDetail(cached, fountainSelector);
console.log(
'data.service.ts selectFountainBySelector: got fountain_detail from cache - ' +
fountainSelector.idval +
' ' +
new Date().toISOString()
);
} else {
this.getFountainDetailsFromServer(fountainSelector, forceReload);
this.switchToServerFountainDetail(fountainSelector, forceReload);
}
} else {
console.log(
Expand Down Expand Up @@ -874,7 +874,7 @@ export class DataService {
}
}

private getFountainDetailsFromServer(fountainSelector: FountainSelector, forceReload: boolean) {
private switchToServerFountainDetail(fountainSelector: FountainSelector, forceReload: boolean) {
// use selector criteria to create api call
this.mapService.state
.pipe(first())
Expand All @@ -895,6 +895,9 @@ export class DataService {
} else {
params += this.toRequestParams(state.bounds);
}
if (forceReload) {
params += '&refresh=true';
}

const url = `${this.apiUrl}api/v1/fountain?${params}`;
if (!environment.production) {
Expand Down Expand Up @@ -1003,7 +1006,7 @@ export class DataService {
}

// Get fountain data from local cache.
private getCachedFountainDetails(fountainData: Fountain, selectorData: FountainSelector): void {
private switchToCachedFountainDetail(fountainData: Fountain, selectorData: FountainSelector): void {
const fountain = fountainData;
const selector = selectorData;
try {
Expand Down Expand Up @@ -1085,7 +1088,7 @@ export class DataService {
forceRefreshForCurrentFountain(): void {
this.fountainService.fountainSelector.subscribeOnce(currentFountainSelector => {
if (currentFountainSelector !== undefined) {
this.selectFountainBySelector(currentFountainSelector, true);
this.selectFountainBySelector(currentFountainSelector, /* forceReload= */ true);
}
});
}
Expand Down
10 changes: 7 additions & 3 deletions src/app/router/router.component.ts
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@

import '../shared/importAllExtensions';
import { Component, OnInit } from '@angular/core';
import { ActivatedRoute, NavigationStart, ParamMap, Router } from '@angular/router';
import { ActivatedRoute, NavigationStart, Router } from '@angular/router';
import { combineLatest, of } from 'rxjs/index';
import { SubscriptionService } from '../core/subscription.service';
import { MapService, MapState } from '../city/map.service';
Expand Down Expand Up @@ -43,7 +43,7 @@ export class RouterComponent implements OnInit {
this.router.events
.pipe(filter((e): e is NavigationStart => e instanceof NavigationStart && e.navigationTrigger === 'popstate'))
.subscribe((_: NavigationStart) => {
const state = this.router.getCurrentNavigation()?.extras?.state;
const state = this.getRouterState();
if (state !== undefined) {
state[programmaticRouting] = false;
}
Expand Down Expand Up @@ -73,7 +73,7 @@ export class RouterComponent implements OnInit {
distinctUntilChanged((x, y) => _.isEqual(x, y))
)
.subscribe(([city, queryParams]) => {
const state: Record<string, any> = {};
const state: Record<string, any> = this.router.getCurrentNavigation() ?? {};
state[programmaticRouting] = true;

this.router.navigate([`/${city ? city : ''}`], {
Expand All @@ -84,6 +84,10 @@ export class RouterComponent implements OnInit {
);
}

private getRouterState(): Record<string, any> | undefined {
return this.router.getCurrentNavigation()?.extras?.state;
}

private toQueryParams(state: MapState, fountainSelector: FountainSelector | undefined): QueryParams {
const q: Omit<QueryParams, 'loc'> = fountainSelector ? this.getQueryParamsForSelector(fountainSelector) : {};
return {
Expand Down
8 changes: 4 additions & 4 deletions src/app/services/utils.ts
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@ export function getSingleNumericParam(paramMap: ParamMap, paramName: string, isO
paramMap,
paramName,
isOptional,
'number',
'numeric',
v => isNumeric(v),
v => Number(v)
);
Expand All @@ -32,7 +32,7 @@ export function isNumeric(v: string | undefined): boolean {
export function getSingleNumberParam(paramMap: ParamMap, paramName: string): number;
export function getSingleNumberParam(paramMap: ParamMap, paramName: string, isOptional: true): number | undefined;
export function getSingleNumberParam(paramMap: ParamMap, paramName: string, isOptional = false): number | undefined {
return getSingleQueryParamTypeOfCheck(paramMap, paramName, isOptional, 'numberic');
return getSingleQueryParamTypeOfCheck(paramMap, paramName, isOptional, 'number');
}

export function getSingleBooleanParam(paramMap: ParamMap, paramName: string): boolean;
Expand Down Expand Up @@ -69,13 +69,13 @@ function getSingleQueryParam<T>(
if (arr.isEmpty() && isOptional) {
return undefined;
} else if (arr.length > 1) {
throw Error(`${paramName} is not a single parameter, was ${JSON.stringify(arr)} ${typeof arr}`);
throw Error(`${paramName} is not a single parameter, was ${JSON.stringify(arr)} with type ${typeof arr}`);
} else {
const v = arr[0];
if (typeCheck(v)) {
return typeConversion(v);
} else {
throw Error(`${paramName} was of a wrong type, expected ${type} was ${JSON.stringify(v)} ${typeof v}`);
throw Error(`${paramName} was of a wrong type, expected ${type} was ${JSON.stringify(v)} with type ${typeof v}`);
}
}
}
2 changes: 2 additions & 0 deletions tsconfig.json
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,8 @@
"noFallthroughCasesInSwitch": true,
"noImplicitAny": true,
"noImplicitReturns": true,
// checked by eslint
//"noUnusedLocals": true
"noPropertyAccessFromIndexSignature": true,
"noUncheckedIndexedAccess": true,
"noUnusedParameters": true,
Expand Down

0 comments on commit 22ed17c

Please sign in to comment.