From 630d2be98c3930f4b493b161af11ac7ab54dcfcf Mon Sep 17 00:00:00 2001 From: Max Date: Tue, 10 Dec 2019 00:23:56 +0100 Subject: [PATCH] added log out button --- src/app/components/feed/feed.component.ts | 2 + .../main-navigation.component.html | 32 ++++++++-- .../main-navigation.component.sass | 10 +++- .../main-navigation.component.ts | 60 +++++++++++++++++-- 4 files changed, 93 insertions(+), 11 deletions(-) diff --git a/src/app/components/feed/feed.component.ts b/src/app/components/feed/feed.component.ts index 9a04690..1163804 100644 --- a/src/app/components/feed/feed.component.ts +++ b/src/app/components/feed/feed.component.ts @@ -40,6 +40,7 @@ export class FeedComponent implements OnInit { } showNew() { + console.log("showNew()") this.feedService.getAllPostsRaw().subscribe(response => { this.feedNew = this.feedService.renderAllPosts(response.json()) this.parentSelectedPostList = this.feedNew}) @@ -48,6 +49,7 @@ export class FeedComponent implements OnInit { } showMostLiked() { + console.log("showMostLiked()") this.feedService.getAllPostsRaw().subscribe(response => { this.feedMostLiked = this.feedService.renderAllPosts(response.json()) this.parentSelectedPostList = this.feedMostLiked}) diff --git a/src/app/components/main-navigation/main-navigation.component.html b/src/app/components/main-navigation/main-navigation.component.html index 49ed684..d6aac82 100644 --- a/src/app/components/main-navigation/main-navigation.component.html +++ b/src/app/components/main-navigation/main-navigation.component.html @@ -2,11 +2,20 @@ Menu - {{link.label}} + Home + Profile + About + Imprint + + @@ -22,14 +31,29 @@ Greenvironment diff --git a/src/app/components/main-navigation/main-navigation.component.sass b/src/app/components/main-navigation/main-navigation.component.sass index 360998c..50f76fb 100644 --- a/src/app/components/main-navigation/main-navigation.component.sass +++ b/src/app/components/main-navigation/main-navigation.component.sass @@ -10,18 +10,22 @@ .sidenav width: 200px - .sidenav .mat-toolbar background: inherit - - .mat-toolbar.mat-primary height: 56px position: sticky top: 0 z-index: 1000 +#link-box + padding: 0.5em + +.link-button + width: 100% + margin-bottom: 0.5em + diff --git a/src/app/components/main-navigation/main-navigation.component.ts b/src/app/components/main-navigation/main-navigation.component.ts index 4a102ee..7c1b355 100644 --- a/src/app/components/main-navigation/main-navigation.component.ts +++ b/src/app/components/main-navigation/main-navigation.component.ts @@ -1,14 +1,30 @@ -import { Component } from '@angular/core'; +import { Component, OnInit } from '@angular/core'; import { BreakpointObserver, Breakpoints } from '@angular/cdk/layout'; import { Observable } from 'rxjs'; import { map, shareReplay } from 'rxjs/operators'; +import { DatasharingService } from '../../services/datasharing.service'; +import { SelfService } from '../../services/selfservice/self.service'; +import { environment } from 'src/environments/environment'; +import { Levellist } from 'src/app/models/levellist'; +import { Http } from '@angular/http'; +import { Router } from '@angular/router'; +import { User } from 'src/app/models/user'; @Component({ selector: 'app-main-navigation', templateUrl: './main-navigation.component.html', styleUrls: ['./main-navigation.component.sass'] }) -export class MainNavigationComponent { +export class MainNavigationComponent implements OnInit { + loggedIn: boolean = false; + userId: number; + username: string + user: User + levellist: Levellist = new Levellist() + level: string + points: number + profileUrl: string; + isHandset$: Observable = this.breakpointObserver.observe(Breakpoints.Handset) .pipe( @@ -16,12 +32,48 @@ export class MainNavigationComponent { shareReplay() ); - constructor(private breakpointObserver: BreakpointObserver) {} + constructor(private data: DatasharingService,private selfservice: SelfService,private breakpointObserver: BreakpointObserver, private http: Http, private router: Router) {} + ngOnInit() { + this.data.currentUserInfo.subscribe(user => { + this.user = user + this.loggedIn = user.loggedIn; + this.userId = user.userID; + this.username = user.username + this.level = this.levellist.getLevelName(user.level) + this.points = user.points + this.profileUrl = '/profile/' + this.userId; + }) + } + navLinksLoggedIn = [ + { path: '', label: 'Home' }, + { path: 'profile/1', label: 'Profile' }, + { path: '/about', label: 'About' }, + { path: '/imprint', label: 'Imprint' }, + ]; navLinks = [ { path: '', label: 'Home' }, - { path: '/profile/1', label: 'Profile' }, { path: '/about', label: 'About' }, { path: '/imprint', label: 'Imprint' }, { path: '/login', label: 'Login' }, + { path: '/register', label: 'Register' }, ]; + + logout() { + let url = environment.graphQLUrl + + let headers = new Headers() + headers.set('Content-Type', 'application/json') + + const body = {query: `mutation { + logout + }`} + + this.http.post(url, body).subscribe(response => { + console.log(response.text())}) + this.loggedIn = false + let user = new User() + user.loggedIn = false + this.data.changeUserInfo(user) + this.router.navigate(['login']) + } }