aboutsummaryrefslogtreecommitdiffhomepage
path: root/client/src/app/shared/video/abstract-video-list.ts
diff options
context:
space:
mode:
Diffstat (limited to 'client/src/app/shared/video/abstract-video-list.ts')
-rw-r--r--client/src/app/shared/video/abstract-video-list.ts24
1 files changed, 12 insertions, 12 deletions
diff --git a/client/src/app/shared/video/abstract-video-list.ts b/client/src/app/shared/video/abstract-video-list.ts
index cf717cf4c..84ca5cbe4 100644
--- a/client/src/app/shared/video/abstract-video-list.ts
+++ b/client/src/app/shared/video/abstract-video-list.ts
@@ -1,25 +1,25 @@
1import { OnDestroy, OnInit } from '@angular/core' 1import { OnInit } from '@angular/core'
2import { ActivatedRoute, Router } from '@angular/router' 2import { ActivatedRoute, Router } from '@angular/router'
3import { NotificationsService } from 'angular2-notifications' 3import { NotificationsService } from 'angular2-notifications'
4import { Observable } from 'rxjs/Observable' 4import { Observable } from 'rxjs/Observable'
5import { Subscription } from 'rxjs/Subscription'
6import { SortField } from './sort-field.type' 5import { SortField } from './sort-field.type'
7import { VideoPagination } from './video-pagination.model' 6import { VideoPagination } from './video-pagination.model'
8import { Video } from './video.model' 7import { Video } from './video.model'
9 8
10export abstract class AbstractVideoList implements OnInit, OnDestroy { 9export abstract class AbstractVideoList implements OnInit {
11 pagination: VideoPagination = { 10 pagination: VideoPagination = {
12 currentPage: 1, 11 currentPage: 1,
13 itemsPerPage: 25, 12 itemsPerPage: 25,
14 totalItems: null 13 totalItems: null
15 } 14 }
16 sort: SortField = '-createdAt' 15 sort: SortField = '-createdAt'
16 defaultSort: SortField = '-createdAt'
17 videos: Video[] = [] 17 videos: Video[] = []
18 loadOnInit = true
18 19
19 protected notificationsService: NotificationsService 20 protected notificationsService: NotificationsService
20 protected router: Router 21 protected router: Router
21 protected route: ActivatedRoute 22 protected route: ActivatedRoute
22 protected subActivatedRoute: Subscription
23 23
24 protected abstract currentRoute: string 24 protected abstract currentRoute: string
25 25
@@ -32,13 +32,7 @@ export abstract class AbstractVideoList implements OnInit, OnDestroy {
32 // Subscribe to route changes 32 // Subscribe to route changes
33 const routeParams = this.route.snapshot.params 33 const routeParams = this.route.snapshot.params
34 this.loadRouteParams(routeParams) 34 this.loadRouteParams(routeParams)
35 this.loadMoreVideos('after') 35 if (this.loadOnInit === true) this.loadMoreVideos('after')
36 }
37
38 ngOnDestroy () {
39 if (this.subActivatedRoute) {
40 this.subActivatedRoute.unsubscribe()
41 }
42 } 36 }
43 37
44 onNearOfTop () { 38 onNearOfTop () {
@@ -53,6 +47,12 @@ export abstract class AbstractVideoList implements OnInit, OnDestroy {
53 } 47 }
54 } 48 }
55 49
50 reloadVideos () {
51 this.videos = []
52 this.loadedPages = {}
53 this.loadMoreVideos('before')
54 }
55
56 loadMoreVideos (where: 'before' | 'after') { 56 loadMoreVideos (where: 'before' | 'after') {
57 if (this.loadedPages[this.pagination.currentPage] === true) return 57 if (this.loadedPages[this.pagination.currentPage] === true) return
58 58
@@ -105,7 +105,7 @@ export abstract class AbstractVideoList implements OnInit, OnDestroy {
105 } 105 }
106 106
107 protected loadRouteParams (routeParams: { [ key: string ]: any }) { 107 protected loadRouteParams (routeParams: { [ key: string ]: any }) {
108 this.sort = routeParams['sort'] as SortField || '-createdAt' 108 this.sort = routeParams['sort'] as SortField || this.defaultSort
109 109
110 if (routeParams['page'] !== undefined) { 110 if (routeParams['page'] !== undefined) {
111 this.pagination.currentPage = parseInt(routeParams['page'], 10) 111 this.pagination.currentPage = parseInt(routeParams['page'], 10)