]> git.immae.eu Git - github/Chocobozzz/PeerTube.git/blobdiff - client/app/videos/video-list/video-list.component.ts
Add authentication tokens to make friends/quit friends
[github/Chocobozzz/PeerTube.git] / client / app / videos / video-list / video-list.component.ts
index a88fb379a4513ea79ad448e187e30f7fd2cedf97..baca00deb10877ffdccb1dadc11a857061f67e44 100644 (file)
@@ -10,8 +10,7 @@ import {
   Video,
   VideoService
 } from '../shared/index';
-import { Search, SearchField } from '../../shared/index';
-import { AuthService, User } from '../../users/index';
+import { AuthService, Search, SearchField, User } from '../../shared/index';
 import { VideoMiniatureComponent } from './video-miniature.component';
 import { VideoSortComponent } from './video-sort.component';
 
@@ -19,38 +18,38 @@ import { VideoSortComponent } from './video-sort.component';
   selector: 'my-videos-list',
   styleUrls: [ 'client/app/videos/video-list/video-list.component.css' ],
   templateUrl: 'client/app/videos/video-list/video-list.component.html',
-  directives: [ ROUTER_DIRECTIVES, PAGINATION_DIRECTIVES, VideoMiniatureComponent, VideoSortComponent, LoaderComponent ]
+  directives: [ LoaderComponent, PAGINATION_DIRECTIVES, ROUTER_DIRECTIVES, VideoMiniatureComponent, VideoSortComponent ]
 })
 
 export class VideoListComponent implements OnInit {
-  user: User = null;
-  videos: Video[] = [];
+  loading = false;
   pagination: Pagination = {
     currentPage: 1,
     itemsPerPage: 9,
     total: 0
   };
   sort: SortField;
-  loading: boolean = false;
+  user: User = null;
+  videos: Video[] = [];
 
   private search: Search;
 
   constructor(
-    private _authService: AuthService,
-    private _videoService: VideoService,
-    private _routeParams: RouteParams,
-    private _router: Router
+    private authService: AuthService,
+    private router: Router,
+    private routeParams: RouteParams,
+    private videoService: VideoService
   ) {
     this.search = {
-      value: this._routeParams.get('search'),
-      field: <SearchField>this._routeParams.get('field')
+      value: this.routeParams.get('search'),
+      field: <SearchField>this.routeParams.get('field')
     };
 
-    this.sort = <SortField>this._routeParams.get('sort') || '-createdDate';
+    this.sort = <SortField>this.routeParams.get('sort') || '-createdDate';
   }
 
   ngOnInit() {
-    if (this._authService.isLoggedIn()) {
+    if (this.authService.isLoggedIn()) {
       this.user = User.load();
     }
 
@@ -64,22 +63,27 @@ export class VideoListComponent implements OnInit {
     let observable = null;
 
     if (this.search.value !== null) {
-      observable = this._videoService.searchVideos(this.search, this.pagination, this.sort);
+      observable = this.videoService.searchVideos(this.search, this.pagination, this.sort);
     } else {
-      observable = this._videoService.getVideos(this.pagination, this.sort);
+      observable = this.videoService.getVideos(this.pagination, this.sort);
     }
 
     observable.subscribe(
       ({ videos, totalVideos }) => {
         this.videos = videos;
         this.pagination.total = totalVideos;
+
         this.loading = false;
       },
       error => alert(error)
     );
   }
 
-  onRemoved(video: Video): void {
+  noVideo() {
+    return !this.loading && this.videos.length === 0;
+  }
+
+  onRemoved(video: Video) {
     this.videos.splice(this.videos.indexOf(video), 1);
   }
 
@@ -91,11 +95,11 @@ export class VideoListComponent implements OnInit {
     };
 
     if (this.search.value) {
-      params.search = this.search.value;
       params.field = this.search.field;
+      params.search = this.search.value;
     }
 
-    this._router.navigate(['VideosList', params]);
+    this.router.navigate(['VideosList', params]);
     this.getVideos();
   }
 }