-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'
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
avatar: true
}
- userMiniature: User
+ user: User
+
+ private userSub: Subscription
readonly hasVideos$: Observable<boolean>
readonly videos$: Observable<Video[]>
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 () {
}
}
+ ngOnDestroy(): void {
+ if (this.userSub) this.userSub.unsubscribe()
+ }
+
onVideoRemoved () {
this.store.requestNewRecommendations(this.inputRecommendation)
}
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