]> git.immae.eu Git - github/Chocobozzz/PeerTube.git/blobdiff - client/src/app/shared/video/abstract-video-list.ts
Replace current state when changing page
[github/Chocobozzz/PeerTube.git] / client / src / app / shared / video / abstract-video-list.ts
index c18ebcf5463d5c893b853c337ba67aa8ff79df00..728c864e9fb719519b36ba3d8de9bd50d0411660 100644 (file)
@@ -1,5 +1,6 @@
 import { ElementRef, OnDestroy, OnInit, ViewChild } from '@angular/core'
 import { ActivatedRoute, Router } from '@angular/router'
+import { Location } from '@angular/common'
 import { isInMobileView } from '@app/shared/misc/utils'
 import { InfiniteScrollerDirective } from '@app/shared/video/infinite-scroller.directive'
 import { NotificationsService } from 'angular2-notifications'
@@ -9,7 +10,7 @@ import { fromEvent } from 'rxjs/observable/fromEvent'
 import { Subscription } from 'rxjs/Subscription'
 import { AuthService } from '../../core/auth'
 import { ComponentPagination } from '../rest/component-pagination.model'
-import { SortField } from './sort-field.type'
+import { VideoSortField } from './sort-field.type'
 import { Video } from './video.model'
 
 export abstract class AbstractVideoList implements OnInit, OnDestroy {
@@ -23,8 +24,10 @@ export abstract class AbstractVideoList implements OnInit, OnDestroy {
     itemsPerPage: 10,
     totalItems: null
   }
-  sort: SortField = '-createdAt'
-  defaultSort: SortField = '-createdAt'
+  sort: VideoSortField = '-createdAt'
+  defaultSort: VideoSortField = '-createdAt'
+  syndicationItems = []
+
   loadOnInit = true
   pageHeight: number
   videoWidth: number
@@ -38,6 +41,7 @@ export abstract class AbstractVideoList implements OnInit, OnDestroy {
   protected abstract authService: AuthService
   protected abstract router: Router
   protected abstract route: ActivatedRoute
+  protected abstract location: Location
   protected abstract currentRoute: string
   abstract titlePage: string
 
@@ -47,6 +51,7 @@ export abstract class AbstractVideoList implements OnInit, OnDestroy {
   private resizeSubscription: Subscription
 
   abstract getVideosObservable (page: number): Observable<{ videos: Video[], totalVideos: number}>
+  abstract generateSyndicationList ()
 
   get user () {
     return this.authService.getUser()
@@ -54,7 +59,7 @@ export abstract class AbstractVideoList implements OnInit, OnDestroy {
 
   ngOnInit () {
     // Subscribe to route changes
-    const routeParams = this.route.snapshot.params
+    const routeParams = this.route.snapshot.queryParams
     this.loadRouteParams(routeParams)
 
     this.resizeSubscription = fromEvent(window, 'resize')
@@ -151,7 +156,7 @@ export abstract class AbstractVideoList implements OnInit, OnDestroy {
   }
 
   protected loadRouteParams (routeParams: { [ key: string ]: any }) {
-    this.sort = routeParams['sort'] as SortField || this.defaultSort
+    this.sort = routeParams['sort'] as VideoSortField || this.defaultSort
 
     if (routeParams['page'] !== undefined) {
       this.pagination.currentPage = parseInt(routeParams['page'], 10)
@@ -161,14 +166,21 @@ export abstract class AbstractVideoList implements OnInit, OnDestroy {
   }
 
   protected setNewRouteParams () {
-    const routeParams = this.buildRouteParams()
-    this.router.navigate([ this.currentRoute, routeParams ])
+    const paramsObject = this.buildRouteParams()
+
+    const queryParams = Object.keys(paramsObject).map(p => p + '=' + paramsObject[p]).join('&')
+    this.location.replaceState(this.currentRoute, queryParams)
   }
 
   protected buildVideoPages () {
     this.videoPages = Object.values(this.loadedPages)
   }
 
+  protected buildVideoHeight () {
+    // Same ratios than base width/height
+    return this.videosElement.nativeElement.offsetWidth * (this.baseVideoHeight / this.baseVideoWidth)
+  }
+
   private minPageLoaded () {
     return Math.min(...Object.keys(this.loadedPages).map(e => parseInt(e, 10)))
   }
@@ -183,8 +195,7 @@ export abstract class AbstractVideoList implements OnInit, OnDestroy {
 
       // Video takes all the width
       this.videoWidth = -1
-      // Same ratios than base width/height
-      this.videoHeight = this.videosElement.nativeElement.offsetWidth * (this.baseVideoHeight / this.baseVideoWidth)
+      this.videoHeight = this.buildVideoHeight()
       this.pageHeight = this.pagination.itemsPerPage * this.videoHeight
     } else {
       this.videoWidth = this.baseVideoWidth