From e771e82dfac5f8cd5462fecf6618f9b1fb314e30 Mon Sep 17 00:00:00 2001 From: Florian CUNY Date: Mon, 26 Apr 2021 11:01:29 +0200 Subject: Added "last" and a reversed ?playlistPosition in playlist URL (#3974) * Added "last" and a reversed playlistPosition Implements https://github.com/Chocobozzz/PeerTube/issues/3897 * Fixed lint errors in video-watch component * Applied requested changes * Removed debug logs * Fixed lint * Playlist position styling Co-authored-by: Chocobozzz --- .../+videos/+video-watch/video-watch-playlist.component.ts | 3 +++ .../src/app/+videos/+video-watch/video-watch.component.ts | 13 ++++++++++++- 2 files changed, 15 insertions(+), 1 deletion(-) (limited to 'client/src/app') diff --git a/client/src/app/+videos/+video-watch/video-watch-playlist.component.ts b/client/src/app/+videos/+video-watch/video-watch-playlist.component.ts index a70167da5..0a4d6bfd1 100644 --- a/client/src/app/+videos/+video-watch/video-watch-playlist.component.ts +++ b/client/src/app/+videos/+video-watch/video-watch-playlist.component.ts @@ -118,6 +118,9 @@ export class VideoWatchPlaylistComponent { updatePlaylistIndex (position: number) { if (this.playlistElements.length === 0 || !position) return + // Handle the reverse index + if (position < 0) position = this.playlist.videosLength + position + 1 + for (const playlistElement of this.playlistElements) { // >= if the previous videos were not valid if (playlistElement.video && playlistElement.position >= position) { diff --git a/client/src/app/+videos/+video-watch/video-watch.component.ts b/client/src/app/+videos/+video-watch/video-watch.component.ts index 5530dc8ad..107826824 100644 --- a/client/src/app/+videos/+video-watch/video-watch.component.ts +++ b/client/src/app/+videos/+video-watch/video-watch.component.ts @@ -188,7 +188,18 @@ export class VideoWatchComponent implements OnInit, OnDestroy { }) this.queryParamsSub = this.route.queryParams.subscribe(queryParams => { - this.playlistPosition = queryParams[ 'playlistPosition' ] + // Handle the ?playlistPosition + const positionParam = queryParams[ 'playlistPosition' ] + + this.playlistPosition = positionParam === 'last' + ? -1 // Handle the "last" index + : parseInt(positionParam, 10) + + if (isNaN(this.playlistPosition)) { + console.error(`playlistPosition query param '${positionParam}' was parsed as NaN, defaulting to 1.`) + this.playlistPosition = 1 + } + this.videoWatchPlaylist.updatePlaylistIndex(this.playlistPosition) const start = queryParams[ 'start' ] -- cgit v1.2.3