fixed profile link bug

master
Max 5 years ago
parent 7ded9d49b8
commit b1f3b7201c

@ -6,13 +6,13 @@
<mat-card class="mat-elevation-z8"> <mat-card class="mat-elevation-z8">
<mat-card-header> <mat-card-header>
<div mat-card-avatar class="profile-picture"></div> <div mat-card-avatar class="profile-picture"></div>
<mat-card-title>{{user.username}}</mat-card-title> <mat-card-title>{{userProfile.username}}</mat-card-title>
<mat-card-subtitle>{{user.handle}}</mat-card-subtitle> <mat-card-subtitle>{{userProfile.handle}}</mat-card-subtitle>
<div class="icon-box"> <div class="icon-box">
<button mat-icon-button <button mat-icon-button
class="request-button" class="request-button"
(click)="sendFriendRequest(user)" (click)="sendFriendRequest(userProfile)"
[disabled]="!user.allowedToSendRequest"> [disabled]="!userProfile.allowedToSendRequest">
<mat-icon>person_add</mat-icon> <mat-icon>person_add</mat-icon>
</button> </button>
</div> </div>
@ -21,27 +21,27 @@
<table id="profile-table"> <table id="profile-table">
<tr> <tr>
<div class="mat-header-cell">name: </div> <div class="mat-header-cell">name: </div>
<td>{{user.username}}</td> <td>{{userProfile.username}}</td>
</tr> </tr>
<mat-divider></mat-divider> <mat-divider></mat-divider>
<tr> <tr>
<div class="mat-header-cell">handle: </div> <div class="mat-header-cell">handle: </div>
<td>{{user.handle}}</td> <td>{{userProfile.handle}}</td>
</tr> </tr>
<mat-divider></mat-divider> <mat-divider></mat-divider>
<tr> <tr>
<div class="mat-header-cell">profileID: </div> <div class="mat-header-cell">profileID: </div>
<td>{{user.userID}}</td> <td>{{userProfile.userID}}</td>
</tr> </tr>
<mat-divider></mat-divider> <mat-divider></mat-divider>
<tr> <tr>
<div class="mat-header-cell">points: </div> <div class="mat-header-cell">points: </div>
<td>{{user.points}}</td> <td>{{userProfile.points}}</td>
</tr> </tr>
<mat-divider></mat-divider> <mat-divider></mat-divider>
<tr> <tr>
<div class="mat-header-cell">level: </div> <div class="mat-header-cell">level: </div>
<td>{{user.level}}</td> <td>{{userProfile.level}}</td>
</tr> </tr>
<mat-divider></mat-divider> <mat-divider></mat-divider>
<tr> <tr>

@ -1,5 +1,5 @@
import { Component, OnInit, ViewChild} from '@angular/core'; import { Component, OnInit, ViewChild} from '@angular/core';
import {Router} from '@angular/router'; import {Router, NavigationEnd} from '@angular/router';
import {Http, URLSearchParams, Headers} from '@angular/http'; import {Http, URLSearchParams, Headers} from '@angular/http';
import { User } from 'src/app/models/user'; import { User } from 'src/app/models/user';
import { Actionlist } from 'src/app/models/actionlist'; import { Actionlist } from 'src/app/models/actionlist';
@ -20,7 +20,7 @@ export class ProfileComponent implements OnInit {
actionlist: Actionlist = new Actionlist(); actionlist: Actionlist = new Actionlist();
levellist: Levellist = new Levellist(); levellist: Levellist = new Levellist();
private user: User = new User(); userProfile: User = new User();
self: User; self: User;
id: string; id: string;
rankname: string; rankname: string;
@ -34,7 +34,17 @@ export class ProfileComponent implements OnInit {
private router: Router, private router: Router,
private http: Http, private http: Http,
private requestService: RequestService, private requestService: RequestService,
private data: DatasharingService) { } private data: DatasharingService) {
router.events.forEach((event) => {
// check if the user is on the profile page (of userY) and routes to the page of userY (e.g. his own page)
if (event instanceof NavigationEnd) {
if (this.id !== this.router.url.substr(this.router.url.lastIndexOf('/') + 1) && this.id) {
// reload the user
this.ngOnInit();
}
}
});
}
@ViewChild(MatSort, {static: true}) sort: MatSort; @ViewChild(MatSort, {static: true}) sort: MatSort;
ngOnInit() { ngOnInit() {
@ -58,14 +68,15 @@ export class ProfileComponent implements OnInit {
public updateUserInfo(response: any) { public updateUserInfo(response: any) {
if (response.data.getUser != null) { if (response.data.getUser != null) {
this.profileNotFound = false; this.profileNotFound = false;
this.user.loggedIn = true; this.userProfile.loggedIn = true;
this.user.userID = response.data.getUser.id; this.userProfile.userID = response.data.getUser.id;
this.user.username = response.data.getUser.name; this.userProfile.username = response.data.getUser.name;
this.user.handle = response.data.getUser.handle; this.userProfile.handle = response.data.getUser.handle;
this.user.points = response.data.getUser.points; this.userProfile.points = response.data.getUser.points;
this.user.level = response.data.getUser.level; this.userProfile.level = response.data.getUser.level;
this.rankname = this.levellist.getLevelName(this.user.level); this.rankname = this.levellist.getLevelName(this.userProfile.level);
this.user.allowedToSendRequest = this.requestService.isAllowedToSendRequest(response.data.getUser.id, this.self); // tslint:disable-next-line:max-line-length
this.userProfile.allowedToSendRequest = this.requestService.isAllowedToSendRequest(response.data.getUser.id, this.self);
} else { } else {
this.profileNotFound = true; this.profileNotFound = true;
} }

Loading…
Cancel
Save