From 6a7cea15271cf30c4b06c7981bff5201978337e8 Mon Sep 17 00:00:00 2001 From: Chocobozzz Date: Wed, 15 Feb 2023 11:32:08 +0100 Subject: [PATCH] Fix live update of autoplay next video --- .../recommended-videos.component.html | 2 +- .../recommended-videos.component.ts | 29 +++++++++++++------ .../core/users/user-local-storage.service.ts | 1 + 3 files changed, 22 insertions(+), 10 deletions(-) diff --git a/client/src/app/+videos/+video-watch/shared/recommendations/recommended-videos.component.html b/client/src/app/+videos/+video-watch/shared/recommendations/recommended-videos.component.html index 5ac801622..2bbe26c96 100644 --- a/client/src/app/+videos/+video-watch/shared/recommendations/recommended-videos.component.html +++ b/client/src/app/+videos/+video-watch/shared/recommendations/recommended-videos.component.html @@ -14,7 +14,7 @@ Next video to be played diff --git a/client/src/app/+videos/+video-watch/shared/recommendations/recommended-videos.component.ts b/client/src/app/+videos/+video-watch/shared/recommendations/recommended-videos.component.ts index 97f742499..426f5d622 100644 --- a/client/src/app/+videos/+video-watch/shared/recommendations/recommended-videos.component.ts +++ b/client/src/app/+videos/+video-watch/shared/recommendations/recommended-videos.component.ts @@ -1,5 +1,5 @@ -import { Observable } from 'rxjs' -import { Component, EventEmitter, Input, OnChanges, OnInit, Output } from '@angular/core' +import { Observable, startWith, Subscription, switchMap } from 'rxjs' +import { Component, EventEmitter, Input, OnChanges, OnDestroy, OnInit, Output } from '@angular/core' import { AuthService, Notifier, User, UserService } from '@app/core' import { Video } from '@app/shared/shared-main' import { MiniatureDisplayOptions } from '@app/shared/shared-video-miniature' @@ -12,7 +12,7 @@ import { RecommendedVideosStore } from './recommended-videos.store' templateUrl: './recommended-videos.component.html', styleUrls: [ './recommended-videos.component.scss' ] }) -export class RecommendedVideosComponent implements OnInit, OnChanges { +export class RecommendedVideosComponent implements OnInit, OnChanges, OnDestroy { @Input() inputRecommendation: RecommendationInfo @Input() playlist: VideoPlaylist @Input() displayAsRow: boolean @@ -29,7 +29,9 @@ export class RecommendedVideosComponent implements OnInit, OnChanges { avatar: true } - userMiniature: User + user: User + + private userSub: Subscription readonly hasVideos$: Observable readonly videos$: Observable @@ -44,15 +46,20 @@ export class RecommendedVideosComponent implements OnInit, OnChanges { this.hasVideos$ = this.store.hasRecommendations$ this.videos$.subscribe(videos => this.gotRecommendations.emit(videos)) - this.userService.getAnonymousOrLoggedUser() - .subscribe(user => this.autoPlayNextVideo = user.autoPlayNextVideo) - this.autoPlayNextVideoTooltip = $localize`When active, the next video is automatically played after the current one.` } ngOnInit () { - this.userService.getAnonymousOrLoggedUser() - .subscribe(user => this.userMiniature = user) + this.userSub = this.userService.listenAnonymousUpdate() + .pipe( + startWith(true), + switchMap(() => this.userService.getAnonymousOrLoggedUser()) + ) + .subscribe(user => { + this.user = user + this.autoPlayNextVideo = user.autoPlayNextVideo + console.log(this.autoPlayNextVideo) + }) } ngOnChanges () { @@ -61,6 +68,10 @@ export class RecommendedVideosComponent implements OnInit, OnChanges { } } + ngOnDestroy(): void { + if (this.userSub) this.userSub.unsubscribe() + } + onVideoRemoved () { this.store.requestNewRecommendations(this.inputRecommendation) } diff --git a/client/src/app/core/users/user-local-storage.service.ts b/client/src/app/core/users/user-local-storage.service.ts index d5fd1e447..1e629249a 100644 --- a/client/src/app/core/users/user-local-storage.service.ts +++ b/client/src/app/core/users/user-local-storage.service.ts @@ -168,6 +168,7 @@ export class UserLocalStorageService { UserLocalStorageKeys.NSFW_POLICY, UserLocalStorageKeys.P2P_ENABLED, UserLocalStorageKeys.AUTO_PLAY_VIDEO, + UserLocalStorageKeys.AUTO_PLAY_NEXT_VIDEO, UserLocalStorageKeys.AUTO_PLAY_VIDEO_PLAYLIST, UserLocalStorageKeys.THEME, UserLocalStorageKeys.VIDEO_LANGUAGES