diff --git a/projects/gameboard-ui/src/app/admin/components/challenge-spec-editor/challenge-spec-editor.component.html b/projects/gameboard-ui/src/app/admin/components/challenge-spec-editor/challenge-spec-editor.component.html index d4c8e989..2a4de4a5 100644 --- a/projects/gameboard-ui/src/app/admin/components/challenge-spec-editor/challenge-spec-editor.component.html +++ b/projects/gameboard-ui/src/app/admin/components/challenge-spec-editor/challenge-spec-editor.component.html @@ -13,7 +13,7 @@

{{ spec.name }}

+ (input)="handleSpecUpdated(spec)">
diff --git a/projects/gameboard-ui/src/app/admin/components/challenge-spec-editor/challenge-spec-editor.component.ts b/projects/gameboard-ui/src/app/admin/components/challenge-spec-editor/challenge-spec-editor.component.ts index 77e133a3..8ac9497d 100644 --- a/projects/gameboard-ui/src/app/admin/components/challenge-spec-editor/challenge-spec-editor.component.ts +++ b/projects/gameboard-ui/src/app/admin/components/challenge-spec-editor/challenge-spec-editor.component.ts @@ -4,7 +4,7 @@ import { fa } from '@/services/font-awesome.service'; import { UnsubscriberService } from '@/services/unsubscriber.service'; import { slug } from '@/tools/functions'; import { Component, EventEmitter, Input, OnChanges, Output, SimpleChanges } from '@angular/core'; -import { Subject, debounceTime, filter, firstValueFrom, switchMap, tap } from 'rxjs'; +import { Subject, debounceTime, filter, switchMap, tap } from 'rxjs'; @Component({ selector: 'app-challenge-spec-editor', @@ -18,9 +18,20 @@ export class ChallengeSpecEditorComponent implements OnChanges { protected fa = fa; protected slug = slug; - protected requestUpdateSpec$ = new Subject(); + private requestUpdateSpec$ = new Subject(); - constructor() { } + constructor( + private specService: SpecService, + private unsub: UnsubscriberService) { + this.unsub.add( + this.requestUpdateSpec$.pipe( + debounceTime(500), + filter(s => s.points >= 0), + switchMap(s => this.specService.update(s)), + tap(s => this.specUpdate.emit(s)), + ).subscribe() + ); + } ngOnChanges(changes: SimpleChanges): void { if (!this.spec) { @@ -29,7 +40,7 @@ export class ChallengeSpecEditorComponent implements OnChanges { } protected handleSpecUpdated(spec: Spec) { - this.specUpdate.emit(spec); + this.requestUpdateSpec$.next(spec); } protected handleSpecDeleted(spec: Spec) { diff --git a/projects/gameboard-ui/src/app/admin/game-mapper/game-mapper.component.html b/projects/gameboard-ui/src/app/admin/game-mapper/game-mapper.component.html index dc45413e..feb0ae24 100644 --- a/projects/gameboard-ui/src/app/admin/game-mapper/game-mapper.component.html +++ b/projects/gameboard-ui/src/app/admin/game-mapper/game-mapper.component.html @@ -45,7 +45,7 @@

Challenge Specs

- + At least one of this game's enabled challenge specs has a point value of zero. This makes it impossible for Gameboard to determine when a challenge has been completed. We strongly recommend assigning a non-zero point value to each challenge. @@ -59,7 +59,7 @@

Challenge Specs

  • + (specUpdate)="handleSpecUpdated(spec)">
diff --git a/projects/gameboard-ui/src/app/admin/game-mapper/game-mapper.component.ts b/projects/gameboard-ui/src/app/admin/game-mapper/game-mapper.component.ts index a80fb72f..3f20f039 100644 --- a/projects/gameboard-ui/src/app/admin/game-mapper/game-mapper.component.ts +++ b/projects/gameboard-ui/src/app/admin/game-mapper/game-mapper.component.ts @@ -50,7 +50,7 @@ export class GameMapperComponent implements OnInit, AfterViewInit { viewing = 'edit'; addedCount = 0; - protected hasZeroPointSpecs$: Observable; + protected hasZeroPointSpecs = false; constructor( private api: SpecService, @@ -62,10 +62,7 @@ export class GameMapperComponent implements OnInit, AfterViewInit { debounceTime(500), switchMap(id => gameSvc.retrieveSpecs(id)), tap(r => this.list = r), - ); - - this.hasZeroPointSpecs$ = this.list$.pipe( - map(specList => specList.some(s => !s.disabled && (!s.points || s.points <= 0))) + tap(r => this.checkForZeroPointActiveSpecs(r)) ); // Grabs external specs @@ -166,6 +163,14 @@ export class GameMapperComponent implements OnInit, AfterViewInit { return g.id; } + protected handleSpecUpdated(spec: Spec) { + this.checkForZeroPointActiveSpecs(this.list); + } + + private checkForZeroPointActiveSpecs(specs: Spec[]) { + this.hasZeroPointSpecs = specs.some(s => s.points <= 0); + } + mousemove(e: MouseEvent) { if (!this.specDrag) { return; }