-import { Component, OnDestroy, OnInit } from '@angular/core'
+import { tap } from 'rxjs/operators'
+import { Component, ComponentFactoryResolver, OnInit, ViewChild } from '@angular/core'
import { ActivatedRoute, Router } from '@angular/router'
import {
AuthService,
ComponentPagination,
ConfirmService,
+ DisableForReuseHook,
LocalStorageService,
Notifier,
ScreenService,
ServerService,
+ User,
UserService
} from '@app/core'
import { immutableAssign } from '@app/helpers'
-import { UserHistoryService } from '@app/shared/shared-main'
-import { AbstractVideoList } from '@app/shared/shared-video-miniature'
+import { UserHistoryService, Video } from '@app/shared/shared-main'
+import { MiniatureDisplayOptions, VideosSelectionComponent } from '@app/shared/shared-video-miniature'
@Component({
templateUrl: './my-history.component.html',
styleUrls: [ './my-history.component.scss' ]
})
-export class MyHistoryComponent extends AbstractVideoList implements OnInit, OnDestroy {
+export class MyHistoryComponent implements OnInit, DisableForReuseHook {
+ @ViewChild('videosSelection', { static: true }) videosSelection: VideosSelectionComponent
+
titlePage: string
pagination: ComponentPagination = {
currentPage: 1,
itemsPerPage: 5,
totalItems: null
}
+
videosHistoryEnabled: boolean
+ miniatureDisplayOptions: MiniatureDisplayOptions = {
+ date: true,
+ views: true,
+ by: true,
+ privacyLabel: false,
+ privacyText: true,
+ state: true,
+ blacklistInfo: true
+ }
+
+ getVideosObservableFunction = this.getVideosObservable.bind(this)
+
+ user: User
+
+ videos: Video[] = []
+ search: string
+
+ disabled = false
+
constructor (
protected router: Router,
protected serverService: ServerService,
protected screenService: ScreenService,
protected storageService: LocalStorageService,
private confirmService: ConfirmService,
- private userHistoryService: UserHistoryService
+ private userHistoryService: UserHistoryService,
+ protected cfr: ComponentFactoryResolver
) {
- super()
-
- this.titlePage = $localize`My videos history`
+ this.titlePage = $localize`My watch history`
}
ngOnInit () {
- super.ngOnInit()
+ this.user = this.authService.getUser()
this.authService.userInformationLoaded
- .subscribe(() => {
- this.videosHistoryEnabled = this.authService.getUser().videosHistoryEnabled
- })
+ .subscribe(() => this.videosHistoryEnabled = this.user.videosHistoryEnabled)
+ }
+ disableForReuse () {
+ this.disabled = true
}
- ngOnDestroy () {
- super.ngOnDestroy()
+ enabledForReuse () {
+ this.disabled = false
+ }
+
+ reloadData () {
+ this.videosSelection.reloadVideos()
+ }
+
+ onSearch (search: string) {
+ this.search = search
+ this.reloadData()
}
getVideosObservable (page: number) {
const newPagination = immutableAssign(this.pagination, { currentPage: page })
- return this.userHistoryService.getUserVideosHistory(newPagination)
+ return this.userHistoryService.getUserVideosHistory(newPagination, this.search)
+ .pipe(
+ tap(res => this.pagination.totalItems = res.total)
+ )
}
generateSyndicationList () {
+ /* method disabled */
throw new Error('Method not implemented.')
}
onVideosHistoryChange () {
this.userService.updateMyProfile({ videosHistoryEnabled: this.videosHistoryEnabled })
- .subscribe(
- () => {
- const message = this.videosHistoryEnabled === true ?
- $localize`Videos history is enabled` :
- $localize`Videos history is disabled`
+ .subscribe({
+ next: () => {
+ const message = this.videosHistoryEnabled === true
+ ? $localize`Videos history is enabled`
+ : $localize`Videos history is disabled`
this.notifier.success(message)
this.authService.refreshUserInformation()
},
- err => this.notifier.error(err.message)
- )
+ error: err => this.notifier.error(err.message)
+ })
}
async deleteHistory () {
if (res !== true) return
this.userHistoryService.deleteUserVideosHistory()
- .subscribe(
- () => {
+ .subscribe({
+ next: () => {
this.notifier.success($localize`Videos history deleted`)
- this.reloadVideos()
+ this.reloadData()
},
- err => this.notifier.error(err.message)
- )
+ error: err => this.notifier.error(err.message)
+ })
}
}