{"version":3,"file":"chunk-eq9jnys4.js","sources":["packages/sports/web/app/src/event-list-shared/sport/services/sorting-state.service.ts"],"sourcesContent":["import { Injectable, OnDestroy } from '@angular/core';\nimport { ActivationStart } from '@angular/router';\n\nimport { RouterEventsService } from '@frontend/sports/common/core/utils/router-events';\nimport { GridSorting } from '@frontend/sports/grid/core/feature/model';\nimport { LocalStoreService } from '@frontend/vanilla/core';\nimport { isArray } from 'lodash-es';\nimport { Subject, takeUntil } from 'rxjs';\n\nimport { CompetitionRouteService } from '../../../competition-list/competition-route.service';\n\nexport type SortingPage = 'live' | 'competitions' | 'coupons' | 'virtual';\n\n@Injectable({ providedIn: 'root' })\nexport class SortingStateService implements OnDestroy {\n private config: Map;\n private currentVirtualCompetitionId: number | null;\n private readonly storageKey = 'grid-sorting';\n private readonly serviceDestroyed$ = new Subject();\n\n constructor(\n private storage: LocalStoreService,\n private routerEventsService: RouterEventsService,\n private competitionRouteService: CompetitionRouteService,\n ) {\n this.loadConfigFromStorage();\n this.subscribeVirtualCompetitionRouteChanges();\n }\n\n get(page: SortingPage, sport?: number): GridSorting | undefined {\n return this.getSorting(page, sport);\n }\n\n set(page: SortingPage, sorting: GridSorting, sport?: number): void {\n this.setSorting(page, sorting, sport);\n this.store();\n }\n\n getVirtualCompetition(): GridSorting {\n const virtualCompetition = this.getSorting('virtual');\n\n if (virtualCompetition === undefined) {\n return GridSorting.Time;\n }\n\n return virtualCompetition;\n }\n\n setByVirtualCompetitionId(sorting: GridSorting, competitionId: number): void {\n this.setSorting('virtual', sorting);\n this.currentVirtualCompetitionId = competitionId;\n }\n\n private removeVirtualCompetition(competitionIds?: number | number[]): void {\n if (!this.currentVirtualCompetitionId) {\n return;\n }\n\n if (isArray(competitionIds) || competitionIds !== this.currentVirtualCompetitionId) {\n this.currentVirtualCompetitionId = null;\n this.config.delete('virtual');\n }\n }\n\n private setSorting(page: SortingPage, sorting: GridSorting, sport?: number): void {\n const key = this.getKey(page, sport);\n this.config.set(key, sorting);\n }\n\n private getSorting(page: SortingPage, sport?: number): GridSorting | undefined {\n const key = this.getKey(page, sport);\n\n return this.config.get(key);\n }\n\n private getKey(page: SortingPage, sport?: number): string {\n if (page === 'virtual') {\n return page;\n }\n\n return [sport || 0, page].join('|');\n }\n\n private store(): void {\n this.storage.set(this.storageKey, Array.from(this.config.entries()));\n }\n\n private loadConfigFromStorage(): void {\n this.config = new Map(this.storage.get(this.storageKey) || []);\n }\n\n private subscribeVirtualCompetitionRouteChanges(): void {\n this.routerEventsService.currentActivationStart.pipe(takeUntil(this.serviceDestroyed$)).subscribe(this.tryRemoveVirtualCompetition);\n }\n\n // While in the context of a virtual competition, the sorting should not change when navigating\n // through the groups. Leaving the context of a given virtual competition, should reset the sorting\n private tryRemoveVirtualCompetition = (event?: ActivationStart): void => {\n if (event) {\n const competitionRouteParams = this.competitionRouteService.params();\n if (!competitionRouteParams.isVirtual || competitionRouteParams.league !== this.currentVirtualCompetitionId) {\n this.removeVirtualCompetition();\n }\n }\n };\n\n ngOnDestroy(): void {\n this.serviceDestroyed$.next();\n this.serviceDestroyed$.complete();\n }\n}\n"],"names":["SortingStateService","constructor","storage","routerEventsService","competitionRouteService","storageKey","serviceDestroyed$","Subject","tryRemoveVirtualCompetition","event","competitionRouteParams","params","isVirtual","league","currentVirtualCompetitionId","removeVirtualCompetition","loadConfigFromStorage","subscribeVirtualCompetitionRouteChanges","get","page","sport","getSorting","set","sorting","setSorting","store","getVirtualCompetition","virtualCompetition","undefined","GridSorting","Time","setByVirtualCompetitionId","competitionId","competitionIds","isArray","config","delete","key","getKey","join","Array","from","entries","Map","currentActivationStart","pipe","takeUntil","subscribe","ngOnDestroy","next","complete","ɵɵinject","LocalStoreService","RouterEventsService","CompetitionRouteService","m","factory","ɵfac","providedIn","_SortingStateService"],"mappings":"6JAcA,IAAaA,CAAmB,CAAA,CAAA,IAAA,CAA1B,IAAOA,CAAP,CAAA,MAAOA,CAAmB,CAM5BC,WACYC,CAAAA,CAAAA,CACAC,CACA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