Fixing player's back navigation when using direct link to the watch page

This commit is contained in:
Zoe Roux 2020-12-29 23:18:20 +01:00
parent e6c5522329
commit 8e491123d6
2 changed files with 16 additions and 5 deletions

View File

@ -16,6 +16,7 @@ import { ActivatedRoute, Event, NavigationCancel, NavigationEnd, NavigationStart
import { OidcSecurityService } from "angular-auth-oidc-client"; import { OidcSecurityService } from "angular-auth-oidc-client";
import * as Hls from "hls.js"; import * as Hls from "hls.js";
import { ShowService } from "../../services/api.service"; import { ShowService } from "../../services/api.service";
import { StartupService } from "../../services/startup.service";
import { import {
getWhatIsSupported, getWhatIsSupported,
method, method,
@ -162,7 +163,8 @@ export class PlayerComponent implements OnInit, OnDestroy, AfterViewInit
private router: Router, private router: Router,
private location: Location, private location: Location,
private injector: Injector, private injector: Injector,
private shows: ShowService) private shows: ShowService,
private startup: StartupService)
{ } { }
ngOnInit() ngOnInit()
@ -359,8 +361,14 @@ export class PlayerComponent implements OnInit, OnDestroy, AfterViewInit
back() back()
{ {
// TODO add the show page in the backstack if the user used a direct link to go to the watch page. if (this.startup.loadedFromWatch)
this.location.back(); {
this.router.navigate(["show", this.startup.show], {replaceUrl: true})
this.startup.loadedFromWatch = false;
this.startup.show = null;
}
else
this.location.back();
} }
next() next()

View File

@ -5,14 +5,17 @@ import { Injectable } from "@angular/core";
}) })
export class StartupService export class StartupService
{ {
loadedFromWatch: boolean = false;
show: string = null;
constructor() {} constructor() {}
load(): Promise<any> load(): Promise<any>
{ {
if (window.location.pathname.startsWith("/watch/")) if (window.location.pathname.startsWith("/watch/"))
{ {
const show = window.location.pathname.match(/^\/watch\/(?<show>.*)(-s\d+e\d+)+?$/).groups["show"]; this.loadedFromWatch = true;
history.pushState({}, null, `/show/${show}`) this.show = window.location.pathname.match(/^\/watch\/(?<show>.*)(-s\d+e\d+)+?$/).groups["show"];
} }
return Promise.resolve(null); return Promise.resolve(null);
} }