diff --git a/src/app/views/dashboard/dashboard.component.html b/src/app/views/dashboard/dashboard.component.html index d5d3788..1badaea 100644 --- a/src/app/views/dashboard/dashboard.component.html +++ b/src/app/views/dashboard/dashboard.component.html @@ -27,15 +27,21 @@ {{ user.username }} - Is banned - {{ user.banned }} + Banned + Actions + @if (user.banned == false) { + } @else { + + } diff --git a/src/app/views/dashboard/dashboard.component.scss b/src/app/views/dashboard/dashboard.component.scss index a6005e9..2a2310e 100644 --- a/src/app/views/dashboard/dashboard.component.scss +++ b/src/app/views/dashboard/dashboard.component.scss @@ -30,4 +30,8 @@ padding: 0.25rem 0; } } +} + +.unbanned { + color:green; } \ No newline at end of file diff --git a/src/app/views/dashboard/dashboard.component.ts b/src/app/views/dashboard/dashboard.component.ts index fe0c88a..02a1192 100644 --- a/src/app/views/dashboard/dashboard.component.ts +++ b/src/app/views/dashboard/dashboard.component.ts @@ -1,5 +1,5 @@ import {AsyncPipe} from '@angular/common'; -import {Component, OnInit} from '@angular/core'; +import {ChangeDetectorRef, Component, OnInit} from '@angular/core'; import {MatFabButton, MatMiniFabButton} from '@angular/material/button'; import {MatFormFieldModule} from '@angular/material/form-field'; import {MatIcon} from '@angular/material/icon'; @@ -31,7 +31,7 @@ export class DashboardComponent implements OnInit { displayedColumns: Array = ['username', 'actions', 'banned']; usersDataSource: MatTableDataSource = new MatTableDataSource([]); - constructor(private adminService: AdminService, protected authService: AuthService) { + constructor(private adminService: AdminService, protected authService: AuthService, private cdr: ChangeDetectorRef) { } ngOnInit(): void { @@ -62,11 +62,20 @@ export class DashboardComponent implements OnInit { } banPlayer(user: UserData): void { - console.log(`Banning user: ${user.username}`); - this.adminService.banPlayer(user.id).subscribe(()=>{}); - this.fetchPlayers(''); + this.adminService.banPlayer(user.id).subscribe(() => { + user.banned = true; + this.usersDataSource.data = [...this.usersDataSource.data]; + }); } + unbanPlayer(user: UserData): void { + this.adminService.unbanPlayer(user.id).subscribe(() => { + user.banned = false; + this.usersDataSource.data = [...this.usersDataSource.data]; + }); + } + + onSearch(searchbar: HTMLInputElement): void { this.fetchPlayers(searchbar.value); } @@ -75,5 +84,4 @@ export class DashboardComponent implements OnInit { searchbar.value = ''; this.fetchPlayers(''); } - }