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 * 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()

View File

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