]> git.immae.eu Git - github/Chocobozzz/PeerTube.git/blobdiff - client/src/app/shared/video/abstract-video-list.ts
Redirect to uuid video route after upload
[github/Chocobozzz/PeerTube.git] / client / src / app / shared / video / abstract-video-list.ts
index ee1ed2cb27fd28d425a8ce79ea7b897a70d63866..2b6870a789b2b06c5c0101df5ae8477604203ff0 100644 (file)
@@ -2,6 +2,7 @@ import { OnInit } from '@angular/core'
 import { ActivatedRoute, Router } from '@angular/router'
 import { NotificationsService } from 'angular2-notifications'
 import { Observable } from 'rxjs/Observable'
+import { AuthService } from '../../core/auth'
 import { SortField } from './sort-field.type'
 import { VideoPagination } from './video-pagination.model'
 import { Video } from './video.model'
@@ -17,9 +18,10 @@ export abstract class AbstractVideoList implements OnInit {
   videos: Video[] = []
   loadOnInit = true
 
-  protected notificationsService: NotificationsService
-  protected router: Router
-  protected route: ActivatedRoute
+  protected abstract notificationsService: NotificationsService
+  protected abstract authService: AuthService
+  protected abstract router: Router
+  protected abstract route: ActivatedRoute
 
   protected abstract currentRoute: string
 
@@ -28,6 +30,10 @@ export abstract class AbstractVideoList implements OnInit {
 
   abstract getVideosObservable (): Observable<{ videos: Video[], totalVideos: number}>
 
+  get user () {
+    return this.authService.getUser()
+  }
+
   ngOnInit () {
     // Subscribe to route changes
     const routeParams = this.route.snapshot.params
@@ -62,7 +68,7 @@ export abstract class AbstractVideoList implements OnInit {
     observable.subscribe(
       ({ videos, totalVideos }) => {
         // Paging is too high, return to the first one
-        if (totalVideos <= ((this.pagination.currentPage - 1) * this.pagination.itemsPerPage)) {
+        if (this.pagination.currentPage > 1 && totalVideos <= ((this.pagination.currentPage - 1) * this.pagination.itemsPerPage)) {
           this.pagination.currentPage = 1
           this.setNewRouteParams()
           return this.reloadVideos()
@@ -82,6 +88,10 @@ export abstract class AbstractVideoList implements OnInit {
   }
 
   protected hasMoreVideos () {
+    // No results
+    if (this.pagination.totalItems === 0) return false
+
+    // Not loaded yet
     if (!this.pagination.totalItems) return true
 
     const maxPage = this.pagination.totalItems / this.pagination.itemsPerPage