import { Injectable } from '@angular/core'; import { Router } from '@angular/router'; import { PortalDeterminationService } from '@core/services/portal-determination.service'; @Injectable({ providedIn: 'root' }) export class DeepLinkingService { static AttemptedRoutePlatformKey = `_yc_attemptedRoutePlatform`; static AttemptedRouteManagerKey = `_yc_attemptedRouteManager`; static AttemptedRouteApplicantKey = `_yc_attemptedRouteApplicant`; get attemptedRouteApplicant (): string { return localStorage.getItem(DeepLinkingService.AttemptedRouteApplicantKey); } set attemptedRouteApplicant (value: string) { localStorage.setItem(DeepLinkingService.AttemptedRouteApplicantKey, value); } get attemptedRouteManager (): string { return localStorage.getItem(DeepLinkingService.AttemptedRouteManagerKey); } set attemptedRouteManager (value: string) { localStorage.setItem(DeepLinkingService.AttemptedRouteManagerKey, value); } get attemptedRoutePlatform (): string { return localStorage.getItem(DeepLinkingService.AttemptedRoutePlatformKey); } set attemptedRoutePlatform (value: string) { localStorage.setItem(DeepLinkingService.AttemptedRoutePlatformKey, value); } constructor ( private portal: PortalDeterminationService, private router: Router ) { setTimeout(() => { this.init(); }); } private init () { const handedOff = localStorage.getItem('handedOff'); if (handedOff === 'true') { this.attemptDeepLink(location.pathname); localStorage.removeItem('handedOff'); } } attemptDeepLink (route: string) { if (this.portal.isApply) { return this.attemptDeepLinkApplicant(route); } else if (this.portal.isManager) { return this.attemptDeepLinkManager(route); } else if (this.portal.isPlatform) { return this.attemptDeepLinkPlatform(route); } } setAttemptedRoute (route: string) { if (this.portal.isApply) { return this.setAttemptedRouteApplicant(route); } else if (this.portal.isManager) { return this.setAttemptedRouteManager(route); } else if (this.portal.isPlatform) { return this.setAttemptedRoutePlatform(route); } } getAttemptedRoute () { if (this.portal.isApply) { return this.getAttemptedRouteApplicant(); } else if (this.portal.isManager) { return this.getAttemptedRouteManager(); } else if (this.portal.isPlatform) { return this.getAttemptedRoutePlatform(); } return ''; } attemptDeepLinkApplicant (route: string) { this.router.navigateByUrl(this.attemptedRouteApplicant || route); this.attemptedRouteApplicant = ''; } attemptDeepLinkManager (route: string) { this.router.navigateByUrl(this.attemptedRouteManager || route); this.attemptedRouteManager = ''; } attemptDeepLinkPlatform (route: string) { this.router.navigateByUrl(this.attemptedRoutePlatform || route); this.attemptedRoutePlatform = ''; } setAttemptedRouteApplicant (route: string) { this.attemptedRouteApplicant = route; } setAttemptedRouteManager (route: string) { this.attemptedRouteManager = route; } setAttemptedRoutePlatform (route: string) { this.attemptedRoutePlatform = route; } getAttemptedRouteApplicant () { return this.attemptedRouteApplicant; } getAttemptedRouteManager () { return this.attemptedRouteManager; } getAttemptedRoutePlatform () { return this.attemptedRoutePlatform; } }