]> git.immae.eu Git - github/Chocobozzz/PeerTube.git/blobdiff - client/src/app/app.component.ts
Client: fix login state when logout
[github/Chocobozzz/PeerTube.git] / client / src / app / app.component.ts
index 81b700a215c3f3b1de9c67bd8e32d13e21842cd1..b7a3d7c58c583e164ff1e62720b25750743a87d8 100644 (file)
@@ -1,52 +1,21 @@
 import { Component } from '@angular/core';
-import { HTTP_PROVIDERS } from '@angular/http';
-import { RouteConfig, Router, ROUTER_DIRECTIVES, ROUTER_PROVIDERS } from '@angular/router-deprecated';
+import { ActivatedRoute, Router, ROUTER_DIRECTIVES } from '@angular/router';
 
 import { FriendService } from './friends';
-import { LoginComponent } from './login';
 import {
   AuthService,
   AuthStatus,
-  Search,
-  SearchComponent
+  SearchComponent,
+  SearchService
 } from './shared';
-import {
-  VideoAddComponent,
-  VideoListComponent,
-  VideoWatchComponent,
-  VideoService
-} from './videos';
-
-@RouteConfig([
-  {
-    path: '/users/login',
-    name: 'UserLogin',
-    component: LoginComponent
-  },
-  {
-    path: '/videos/list',
-    name: 'VideosList',
-    component: VideoListComponent,
-    useAsDefault: true
-  },
-  {
-    path: '/videos/watch/:id',
-    name: 'VideosWatch',
-    component: VideoWatchComponent
-  },
-  {
-    path: '/videos/add',
-    name: 'VideosAdd',
-    component: VideoAddComponent
-  }
-])
+import { VideoService } from './videos';
 
 @Component({
     selector: 'my-app',
     template: require('./app.component.html'),
     styles: [ require('./app.component.scss') ],
     directives: [ ROUTER_DIRECTIVES, SearchComponent ],
-    providers: [ AuthService, FriendService, HTTP_PROVIDERS, ROUTER_PROVIDERS, VideoService ]
+    providers: [ FriendService, VideoService, SearchService ]
 })
 
 export class AppComponent {
@@ -56,6 +25,7 @@ export class AppComponent {
   constructor(
     private authService: AuthService,
     private friendService: FriendService,
+    private route: ActivatedRoute,
     private router: Router
   ) {
     this.isLoggedIn = this.authService.isLoggedIn();
@@ -64,25 +34,19 @@ export class AppComponent {
       status => {
         if (status === AuthStatus.LoggedIn) {
           this.isLoggedIn = true;
+          console.log('Logged in.');
+        } else if (status === AuthStatus.LoggedOut) {
+          this.isLoggedIn = false;
+          console.log('Logged out.');
+        } else {
+          console.error('Unknown auth status: ' + status);
         }
       }
     );
   }
 
-  onSearch(search: Search) {
-    if (search.value !== '') {
-      const params = {
-        field: search.field,
-        search: search.value
-      };
-      this.router.navigate(['VideosList', params]);
-    } else {
-      this.router.navigate(['VideosList']);
-    }
-  }
-
   logout() {
-    // this._authService.logout();
+    this.authService.logout();
   }
 
   makeFriends() {