From 8e491123d6266c7efbee82c7a01a9e43243d5e77 Mon Sep 17 00:00:00 2001 From: Zoe Roux Date: Tue, 29 Dec 2020 23:18:20 +0100 Subject: [PATCH] Fixing player's back navigation when using direct link to the watch page --- src/app/pages/player/player.component.ts | 14 +++++++++++--- src/app/services/startup.service.ts | 7 +++++-- 2 files changed, 16 insertions(+), 5 deletions(-) diff --git a/src/app/pages/player/player.component.ts b/src/app/pages/player/player.component.ts index d2599405..c4f64ab7 100644 --- a/src/app/pages/player/player.component.ts +++ b/src/app/pages/player/player.component.ts @@ -16,6 +16,7 @@ import { ActivatedRoute, Event, NavigationCancel, NavigationEnd, NavigationStart import { OidcSecurityService } from "angular-auth-oidc-client"; import * as Hls from "hls.js"; import { ShowService } from "../../services/api.service"; +import { StartupService } from "../../services/startup.service"; import { getWhatIsSupported, method, @@ -162,7 +163,8 @@ export class PlayerComponent implements OnInit, OnDestroy, AfterViewInit private router: Router, private location: Location, private injector: Injector, - private shows: ShowService) + private shows: ShowService, + private startup: StartupService) { } ngOnInit() @@ -359,8 +361,14 @@ export class PlayerComponent implements OnInit, OnDestroy, AfterViewInit back() { - // TODO add the show page in the backstack if the user used a direct link to go to the watch page. - this.location.back(); + if (this.startup.loadedFromWatch) + { + this.router.navigate(["show", this.startup.show], {replaceUrl: true}) + this.startup.loadedFromWatch = false; + this.startup.show = null; + } + else + this.location.back(); } next() diff --git a/src/app/services/startup.service.ts b/src/app/services/startup.service.ts index 6b64621d..8cf2a981 100644 --- a/src/app/services/startup.service.ts +++ b/src/app/services/startup.service.ts @@ -5,14 +5,17 @@ import { Injectable } from "@angular/core"; }) export class StartupService { + loadedFromWatch: boolean = false; + show: string = null; + constructor() {} load(): Promise { if (window.location.pathname.startsWith("/watch/")) { - const show = window.location.pathname.match(/^\/watch\/(?.*)(-s\d+e\d+)+?$/).groups["show"]; - history.pushState({}, null, `/show/${show}`) + this.loadedFromWatch = true; + this.show = window.location.pathname.match(/^\/watch\/(?.*)(-s\d+e\d+)+?$/).groups["show"]; } return Promise.resolve(null); }