Skip to content

Commit

Permalink
Partial fix for GBAPI#281 - added more explanatory error message when…
Browse files Browse the repository at this point in the history
… someone attempts to delete a game with players in it.
  • Loading branch information
sei-bstein committed Nov 20, 2023
1 parent d0f192b commit a44a1bb
Show file tree
Hide file tree
Showing 2 changed files with 15 additions and 6 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -35,6 +35,10 @@
</div>
</div>

<div class="component-errors">
<app-error-div [errors]="errors"></app-error-div>
</div>

<ng-container *ngIf="games$ | async as games; else loading">

<!-- Card view mode -->
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,8 +5,8 @@ import { Component, OnInit } from '@angular/core';
import { ActivatedRoute, Router } from '@angular/router';
import { faArrowLeft, faPlus, faCopy, faTrash, faEdit, faUsers, faUser, faUsersCog, faCog, faTv, faToggleOff, faToggleOn, faEyeSlash, faUndo, faGlobeAmericas, faClone, faChartBar, faCommentSlash, faLock, faGamepad } from '@fortawesome/free-solid-svg-icons';
import { fa } from '@/services/font-awesome.service';
import { BehaviorSubject, Subject, Observable } from 'rxjs';
import { debounceTime, switchMap, tap, mergeMap } from 'rxjs/operators';
import { BehaviorSubject, Subject, Observable, firstValueFrom } from 'rxjs';
import { debounceTime, switchMap, tap, mergeMap, catchError } from 'rxjs/operators';
import { Game, NewGame } from '../../api/game-models';
import { GameService } from '../../api/game.service';
import { Search } from '../../api/models';
Expand All @@ -29,6 +29,7 @@ export class DashboardComponent implements OnInit {
preferenceKey = 'admin.dashboard.game.viewer.mode'; // key to save toggle in local storage
tableView: boolean; // true = table, false = cards

protected errors: any[] = [];
search: Search = { term: '' };
hot!: Game | null;

Expand Down Expand Up @@ -85,10 +86,14 @@ export class DashboardComponent implements OnInit {
this.creating$.next({ name: 'NewGame' } as Game);
}

delete(game: Game): void {
this.api.delete(game.id).subscribe(
() => this.remove(game)
);
async delete(game: Game): Promise<void> {
try {
await firstValueFrom(this.api.delete(game.id));
this.remove(game);
}
catch (err: any) {
this.errors.push(err);
}
}

remove(game: Game): void {
Expand Down

0 comments on commit a44a1bb

Please sign in to comment.