merge: fix scouting dashboard controls

This commit is contained in:
bisco
2026-06-03 22:56:33 +02:00
3 changed files with 69 additions and 12 deletions
+24 -6
View File
@@ -82,27 +82,45 @@
</section> </section>
<section class="quickbar" aria-label="Quick filters"> <section class="quickbar" aria-label="Quick filters">
<div class="chip-group"> <div class="chip-group" aria-label="Position quick filter">
<button
type="button"
[class.active]="filters.position === ''"
[attr.aria-pressed]="filters.position === ''"
(click)="setPosition('')"
>
All positions
</button>
<button <button
*ngFor="let position of positions" *ngFor="let position of positions"
type="button" type="button"
[class.active]="filters.position === position" [class.active]="filters.position === position"
(click)="togglePosition(position)" [attr.aria-pressed]="filters.position === position"
(click)="setPosition(position)"
> >
{{ position }} {{ position }}
</button> </button>
</div> </div>
<div class="chip-group league-chips"> <div class="chip-group league-chips" aria-label="League quick filter">
<button
type="button"
[class.active]="filters.league === ''"
[attr.aria-pressed]="filters.league === ''"
(click)="setLeague('')"
>
All leagues
</button>
<button <button
*ngFor="let league of leagues" *ngFor="let league of leagues"
type="button" type="button"
[class.active]="filters.league === league" [class.active]="filters.league === league"
(click)="toggleLeague(league)" [attr.aria-pressed]="filters.league === league"
(click)="setLeague(league)"
> >
{{ league }} {{ league }}
</button> </button>
</div> </div>
<span class="filter-count">{{ activeFiltersCount }} active</span> <span class="filter-count">{{ isUpdatingResults ? 'Updating...' : activeFiltersCount + ' active' }}</span>
</section> </section>
<p *ngIf="errorMessage" class="alert">{{ errorMessage }}</p> <p *ngIf="errorMessage" class="alert">{{ errorMessage }}</p>
@@ -151,7 +169,7 @@
</tbody> </tbody>
</table> </table>
<div *ngIf="!loading && players.length === 0" class="empty">No players match the current filters.</div> <div *ngIf="!loading && players.length === 0" class="empty">No players match the current filters.</div>
<div *ngIf="loading" class="empty">Loading scouting board...</div> <div *ngIf="showLoadingPlaceholder" class="empty">Loading scouting board...</div>
</div> </div>
<aside class="detail" *ngIf="selectedPlayer"> <aside class="detail" *ngIf="selectedPlayer">
+31
View File
@@ -89,6 +89,37 @@ describe('AppComponent', () => {
assert.equal(calls, 1); assert.equal(calls, 1);
}); });
it('applies quick filters immediately and can clear them with all controls', () => {
const requestedPositions: string[] = [];
const api = {
searchPlayers: (filters: { position: string; league: string }) => {
requestedPositions.push(`${filters.position}:${filters.league}`);
return of({ count: 0, results: [] });
},
} as unknown as PlayerApiService;
const component = new AppComponent(api);
component.setPosition('PG');
component.setLeague('LBA');
component.setPosition('');
component.setLeague('');
assert.deepEqual(requestedPositions, ['PG:', 'PG:LBA', ':LBA', ':']);
});
it('shows the loading placeholder only before results exist', () => {
const api = {
searchPlayers: () => of({ count: samplePlayers.length, results: samplePlayers }),
} as unknown as PlayerApiService;
const component = new AppComponent(api);
component.loading = true;
assert.equal(component.showLoadingPlaceholder, true);
component.players = samplePlayers;
assert.equal(component.showLoadingPlaceholder, false);
});
it('sorts the visible scouting board by selected stat', () => { it('sorts the visible scouting board by selected stat', () => {
const api = { const api = {
searchPlayers: () => of({ count: samplePlayers.length, results: samplePlayers }), searchPlayers: () => of({ count: samplePlayers.length, results: samplePlayers }),
+14 -6
View File
@@ -95,14 +95,14 @@ export class AppComponent {
this.search(); this.search();
} }
togglePosition(position: string): void { setPosition(position: string): void {
this.filters.position = this.filters.position === position ? '' : position; this.filters.position = position;
this.onFilterChange(); this.search();
} }
toggleLeague(league: string): void { setLeague(league: string): void {
this.filters.league = this.filters.league === league ? '' : league; this.filters.league = league;
this.onFilterChange(); this.search();
} }
sortBy(key: SortKey): void { sortBy(key: SortKey): void {
@@ -153,6 +153,14 @@ export class AppComponent {
].filter((value) => value !== null && String(value).trim().length > 0).length; ].filter((value) => value !== null && String(value).trim().length > 0).length;
} }
get showLoadingPlaceholder(): boolean {
return this.loading && this.players.length === 0;
}
get isUpdatingResults(): boolean {
return this.loading && this.players.length > 0;
}
private sortPlayers(players: PlayerSummary[]): PlayerSummary[] { private sortPlayers(players: PlayerSummary[]): PlayerSummary[] {
return [...players].sort((a, b) => this.numericStat(b, this.activeSort) - this.numericStat(a, this.activeSort)); return [...players].sort((a, b) => this.numericStat(b, this.activeSort) - this.numericStat(a, this.activeSort));
} }