]> git.immae.eu Git - github/Chocobozzz/PeerTube.git/blobdiff - client/src/app/videos/video-list/video-list.component.ts
Add a little explication on dev mode in README
[github/Chocobozzz/PeerTube.git] / client / src / app / videos / video-list / video-list.component.ts
index 062340ec523fce4e00de666c4984a4e11c48fca5..a8b92480b537d13542d5925c5583e7867b94d4d6 100644 (file)
@@ -1,33 +1,25 @@
 import { ChangeDetectorRef, Component, OnDestroy, OnInit } from '@angular/core';
-import { AsyncPipe } from '@angular/common';
-import { ActivatedRoute, Router, ROUTER_DIRECTIVES } from '@angular/router';
+import { ActivatedRoute, Router } from '@angular/router';
 import { BehaviorSubject } from 'rxjs/BehaviorSubject';
 
-import { PAGINATION_DIRECTIVES } from 'ng2-bootstrap/components/pagination';
-
 import {
-  LoaderComponent,
-  Pagination,
   SortField,
   Video,
   VideoService
 } from '../shared';
-import { AuthService, AuthUser, Search, SearchField } from '../../shared';
-import { VideoMiniatureComponent } from './video-miniature.component';
-import { VideoSortComponent } from './video-sort.component';
+import { AuthService } from '../../core';
+import { AuthUser, RestPagination, Search, SearchField } from '../../shared';
 import { SearchService } from '../../shared';
 
 @Component({
   selector: 'my-videos-list',
-  styles: [ require('./video-list.component.scss') ],
-  pipes: [ AsyncPipe ],
-  template: require('./video-list.component.html'),
-  directives: [ LoaderComponent, PAGINATION_DIRECTIVES, ROUTER_DIRECTIVES, VideoMiniatureComponent, VideoSortComponent ]
+  styleUrls: [ './video-list.component.scss' ],
+  templateUrl: './video-list.component.html'
 })
 
 export class VideoListComponent implements OnInit, OnDestroy {
   loading: BehaviorSubject<boolean> = new BehaviorSubject(false);
-  pagination: Pagination = {
+  pagination: RestPagination = {
     currentPage: 1,
     itemsPerPage: 9,
     totalItems: null
@@ -66,6 +58,8 @@ export class VideoListComponent implements OnInit, OnDestroy {
     // Subscribe to search changes
     this.subSearch = this.searchService.searchUpdated.subscribe(search => {
       this.search = search;
+      // Reset pagination
+      this.pagination.currentPage = 1;
 
       this.navigateToNewParams();
     });
@@ -76,7 +70,7 @@ export class VideoListComponent implements OnInit, OnDestroy {
     this.subSearch.unsubscribe();
   }
 
-  getVideos(detectChanges = true) {
+  getVideos() {
     this.loading.next(true);
     this.videos = [];
 
@@ -97,7 +91,7 @@ export class VideoListComponent implements OnInit, OnDestroy {
 
         this.loading.next(false);
       },
-      error => alert(error)
+      error => alert(error.text)
     );
   }
 
@@ -153,7 +147,11 @@ export class VideoListComponent implements OnInit, OnDestroy {
 
     this.sort = <SortField>routeParams['sort'] || '-createdDate';
 
-    this.pagination.currentPage = parseInt(routeParams['page']) || 1;
+    if (routeParams['page'] !== undefined) {
+      this.pagination.currentPage = parseInt(routeParams['page']);
+    } else {
+      this.pagination.currentPage = 1;
+    }
 
     this.changeDetector.detectChanges();
   }