mirror of https://github.com/Chocobozzz/PeerTube
Refactor next/prev logic
parent
5bb2ed6b81
commit
fd78d2e247
|
@ -137,26 +137,8 @@ export class VideoWatchPlaylistComponent {
|
||||||
this.onPlaylistVideosNearOfBottom(position)
|
this.onPlaylistVideosNearOfBottom(position)
|
||||||
}
|
}
|
||||||
|
|
||||||
findPreviousPlaylistVideo (position = this.currentPlaylistPosition): VideoPlaylistElement {
|
|
||||||
if (this.currentPlaylistPosition <= 1) {
|
|
||||||
// we have reached the top of the playlist: either loop or stop
|
|
||||||
if (this.loopPlaylist) {
|
|
||||||
this.currentPlaylistPosition = position = this.playlistPagination.totalItems
|
|
||||||
} else {
|
|
||||||
return
|
|
||||||
}
|
|
||||||
}
|
|
||||||
const previous = this.playlistElements.find(e => e.position === position)
|
|
||||||
|
|
||||||
if (!previous || !previous.video) {
|
|
||||||
return this.findPreviousPlaylistVideo(position - 1)
|
|
||||||
}
|
|
||||||
|
|
||||||
return previous
|
|
||||||
}
|
|
||||||
|
|
||||||
navigateToPreviousPlaylistVideo () {
|
navigateToPreviousPlaylistVideo () {
|
||||||
const previous = this.findPreviousPlaylistVideo(this.currentPlaylistPosition - 1)
|
const previous = this.findPlaylistVideo(this.currentPlaylistPosition - 1, 'previous')
|
||||||
if (!previous) return
|
if (!previous) return
|
||||||
|
|
||||||
const start = previous.startTimestamp
|
const start = previous.startTimestamp
|
||||||
|
@ -164,27 +146,32 @@ export class VideoWatchPlaylistComponent {
|
||||||
this.router.navigate([],{ queryParams: { playlistPosition: previous.position, start, stop } })
|
this.router.navigate([],{ queryParams: { playlistPosition: previous.position, start, stop } })
|
||||||
}
|
}
|
||||||
|
|
||||||
findNextPlaylistVideo (position = this.currentPlaylistPosition): VideoPlaylistElement {
|
findPlaylistVideo (position: number, type: 'previous' | 'next'): VideoPlaylistElement {
|
||||||
if (this.currentPlaylistPosition >= this.playlistPagination.totalItems) {
|
if (
|
||||||
// we have reached the end of the playlist: either loop or stop
|
(type === 'next' && position > this.playlistPagination.totalItems) ||
|
||||||
if (this.loopPlaylist) {
|
(type === 'previous' && position < 1)
|
||||||
this.currentPlaylistPosition = position = 0
|
) {
|
||||||
} else {
|
// End of the playlist: end the recursion if we're not in the loop mode
|
||||||
return
|
if (!this.loopPlaylist) return
|
||||||
}
|
|
||||||
|
// Loop mode
|
||||||
|
position = type === 'previous'
|
||||||
|
? this.playlistPagination.totalItems
|
||||||
|
: 1
|
||||||
}
|
}
|
||||||
|
|
||||||
const next = this.playlistElements.find(e => e.position === position)
|
const found = this.playlistElements.find(e => e.position === position)
|
||||||
|
if (found && found.video) return found
|
||||||
|
|
||||||
if (!next || !next.video) {
|
const newPosition = type === 'previous'
|
||||||
return this.findNextPlaylistVideo(position + 1)
|
? position - 1
|
||||||
}
|
: position + 1
|
||||||
|
|
||||||
return next
|
return this.findPlaylistVideo(newPosition, type)
|
||||||
}
|
}
|
||||||
|
|
||||||
navigateToNextPlaylistVideo () {
|
navigateToNextPlaylistVideo () {
|
||||||
const next = this.findNextPlaylistVideo(this.currentPlaylistPosition + 1)
|
const next = this.findPlaylistVideo(this.currentPlaylistPosition + 1, 'next')
|
||||||
if (!next) return
|
if (!next) return
|
||||||
|
|
||||||
const start = next.startTimestamp
|
const start = next.startTimestamp
|
||||||
|
|
Loading…
Reference in New Issue