Replace current state when changing page
[oweals/peertube.git] / client / src / app / videos / video-list / video-local.component.ts
1 import { Component, OnDestroy, OnInit } from '@angular/core'
2 import { ActivatedRoute, Router } from '@angular/router'
3 import { immutableAssign } from '@app/shared/misc/utils'
4 import { Location } from '@angular/common'
5 import { NotificationsService } from 'angular2-notifications'
6 import { AuthService } from '../../core/auth'
7 import { AbstractVideoList } from '../../shared/video/abstract-video-list'
8 import { VideoSortField } from '../../shared/video/sort-field.type'
9 import { VideoService } from '../../shared/video/video.service'
10 import { VideoFilter } from '../../../../../shared/models/videos/video-query.type'
11
12 @Component({
13   selector: 'my-videos-local',
14   styleUrls: [ '../../shared/video/abstract-video-list.scss' ],
15   templateUrl: '../../shared/video/abstract-video-list.html'
16 })
17 export class VideoLocalComponent extends AbstractVideoList implements OnInit, OnDestroy {
18   titlePage = 'Local videos'
19   currentRoute = '/videos/local'
20   sort = '-createdAt' as VideoSortField
21   filter: VideoFilter = 'local'
22
23   constructor (protected router: Router,
24                protected route: ActivatedRoute,
25                protected notificationsService: NotificationsService,
26                protected authService: AuthService,
27                protected location: Location,
28                private videoService: VideoService) {
29     super()
30   }
31
32   ngOnInit () {
33     super.ngOnInit()
34
35     this.generateSyndicationList()
36   }
37
38   ngOnDestroy () {
39     super.ngOnDestroy()
40   }
41
42   getVideosObservable (page: number) {
43     const newPagination = immutableAssign(this.pagination, { currentPage: page })
44
45     return this.videoService.getVideos(newPagination, this.sort, this.filter)
46   }
47
48   generateSyndicationList () {
49     this.syndicationItems = this.videoService.getVideoFeedUrls(this.sort, this.filter)
50   }
51 }