feat: NCWF-5/6/7/8/9 chess analysis page and engine integration
Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
This commit is contained in:
@@ -0,0 +1,108 @@
|
||||
:host {
|
||||
display: block;
|
||||
}
|
||||
|
||||
.empty {
|
||||
font-size: 11px;
|
||||
color: rgba(255, 255, 255, 0.4);
|
||||
padding: 12px 16px;
|
||||
font-family: var(--nc-mono, monospace);
|
||||
letter-spacing: 0.06em;
|
||||
}
|
||||
|
||||
.move-grid {
|
||||
display: grid;
|
||||
grid-template-columns: 28px 1fr 1fr;
|
||||
gap: 2px 4px;
|
||||
padding: 8px 12px;
|
||||
font-family: var(--nc-mono, monospace);
|
||||
font-size: 12px;
|
||||
}
|
||||
|
||||
.mv-num {
|
||||
color: rgba(255, 255, 255, 0.3);
|
||||
font-size: 10px;
|
||||
display: flex;
|
||||
align-items: center;
|
||||
letter-spacing: 0.04em;
|
||||
}
|
||||
|
||||
.mv {
|
||||
display: flex;
|
||||
align-items: center;
|
||||
gap: 4px;
|
||||
padding: 4px 8px;
|
||||
cursor: pointer;
|
||||
border-radius: 2px;
|
||||
color: rgba(255, 255, 255, 0.8);
|
||||
transition:
|
||||
background 0.12s,
|
||||
color 0.12s;
|
||||
}
|
||||
|
||||
.mv:hover {
|
||||
background: rgba(255, 255, 255, 0.06);
|
||||
color: #fff;
|
||||
}
|
||||
|
||||
.mv.active {
|
||||
background: rgba(255, 69, 200, 0.18);
|
||||
color: #fff;
|
||||
}
|
||||
|
||||
.mv-empty {
|
||||
cursor: default;
|
||||
color: rgba(255, 255, 255, 0.25);
|
||||
}
|
||||
|
||||
.mv-empty:hover {
|
||||
background: transparent;
|
||||
color: rgba(255, 255, 255, 0.25);
|
||||
}
|
||||
|
||||
.mv-san {
|
||||
flex: 1;
|
||||
}
|
||||
|
||||
.mv-placeholder {
|
||||
opacity: 0.4;
|
||||
}
|
||||
|
||||
/* Quality badges */
|
||||
.mv-badge {
|
||||
font-size: 10px;
|
||||
font-weight: 700;
|
||||
padding: 1px 4px;
|
||||
border-radius: 2px;
|
||||
flex-shrink: 0;
|
||||
}
|
||||
|
||||
.q-brilliant .mv-badge,
|
||||
.mv-badge.q-brilliant {
|
||||
color: #5ee5a1;
|
||||
background: rgba(94, 229, 161, 0.15);
|
||||
}
|
||||
|
||||
.q-best .mv-badge,
|
||||
.mv-badge.q-best {
|
||||
color: #5ee5a1;
|
||||
background: rgba(94, 229, 161, 0.1);
|
||||
}
|
||||
|
||||
.q-inaccuracy .mv-badge,
|
||||
.mv-badge.q-inaccuracy {
|
||||
color: #ffb13a;
|
||||
background: rgba(255, 177, 58, 0.15);
|
||||
}
|
||||
|
||||
.q-mistake .mv-badge,
|
||||
.mv-badge.q-mistake {
|
||||
color: #ff7a7a;
|
||||
background: rgba(255, 122, 122, 0.15);
|
||||
}
|
||||
|
||||
.q-blunder .mv-badge,
|
||||
.mv-badge.q-blunder {
|
||||
color: #ff4444;
|
||||
background: rgba(255, 68, 68, 0.18);
|
||||
}
|
||||
@@ -0,0 +1,48 @@
|
||||
@if (moves.length === 0) {
|
||||
<div class="empty">No annotated moves yet.</div>
|
||||
} @else {
|
||||
<div class="move-grid" role="list">
|
||||
@for (pair of pairs; track $index) {
|
||||
<div class="mv-num" role="presentation">{{ $index + 1 }}</div>
|
||||
|
||||
<div
|
||||
class="mv"
|
||||
[class.active]="isWhiteActive($index)"
|
||||
[class]="qualityClass(pair.white)"
|
||||
role="listitem"
|
||||
tabindex="0"
|
||||
(click)="selectWhite($index)"
|
||||
(keydown.enter)="selectWhite($index)"
|
||||
>
|
||||
<span class="mv-san">{{ pair.white?.san ?? '' }}</span>
|
||||
@if (qualityLabel(pair.white)) {
|
||||
<span class="mv-badge" [class]="qualityClass(pair.white)">{{
|
||||
qualityLabel(pair.white)
|
||||
}}</span>
|
||||
}
|
||||
</div>
|
||||
|
||||
<div
|
||||
class="mv"
|
||||
[class.active]="isBlackActive($index)"
|
||||
[class.mv-empty]="!pair.black"
|
||||
[class]="qualityClass(pair.black)"
|
||||
role="listitem"
|
||||
[attr.tabindex]="pair.black ? 0 : null"
|
||||
(click)="selectBlack($index, pair.black)"
|
||||
(keydown.enter)="selectBlack($index, pair.black)"
|
||||
>
|
||||
@if (pair.black) {
|
||||
<span class="mv-san">{{ pair.black.san }}</span>
|
||||
@if (qualityLabel(pair.black)) {
|
||||
<span class="mv-badge" [class]="qualityClass(pair.black)">{{
|
||||
qualityLabel(pair.black)
|
||||
}}</span>
|
||||
}
|
||||
} @else {
|
||||
<span class="mv-san mv-placeholder">…</span>
|
||||
}
|
||||
</div>
|
||||
}
|
||||
</div>
|
||||
}
|
||||
@@ -0,0 +1,83 @@
|
||||
import { Component, EventEmitter, Input, Output } from '@angular/core';
|
||||
import { AnnotatedMove, MoveQuality } from '../../models/analysis.models';
|
||||
|
||||
interface AnnotatedPair {
|
||||
white: AnnotatedMove | null;
|
||||
black: AnnotatedMove | null;
|
||||
}
|
||||
|
||||
const QUALITY_LABELS: Record<MoveQuality, string> = {
|
||||
brilliant: '!!',
|
||||
best: '!',
|
||||
good: '',
|
||||
inaccuracy: '?!',
|
||||
mistake: '?',
|
||||
blunder: '??',
|
||||
};
|
||||
|
||||
const QUALITY_CLASSES: Record<MoveQuality, string> = {
|
||||
brilliant: 'q-brilliant',
|
||||
best: 'q-best',
|
||||
good: 'q-good',
|
||||
inaccuracy: 'q-inaccuracy',
|
||||
mistake: 'q-mistake',
|
||||
blunder: 'q-blunder',
|
||||
};
|
||||
|
||||
@Component({
|
||||
selector: 'app-annotated-move-list',
|
||||
standalone: true,
|
||||
imports: [],
|
||||
templateUrl: './annotated-move-list.component.html',
|
||||
styleUrl: './annotated-move-list.component.css',
|
||||
})
|
||||
export class AnnotatedMoveListComponent {
|
||||
@Input({ required: true }) moves: AnnotatedMove[] = [];
|
||||
@Input() activePly: number | null = null;
|
||||
@Output() plySelected = new EventEmitter<number>();
|
||||
|
||||
get pairs(): AnnotatedPair[] {
|
||||
const result: AnnotatedPair[] = [];
|
||||
for (let i = 0; i < this.moves.length; i += 2) {
|
||||
result.push({
|
||||
white: this.moves[i] ?? null,
|
||||
black: this.moves[i + 1] ?? null,
|
||||
});
|
||||
}
|
||||
return result;
|
||||
}
|
||||
|
||||
qualityLabel(move: AnnotatedMove | null): string {
|
||||
if (!move?.quality) return '';
|
||||
return QUALITY_LABELS[move.quality] ?? '';
|
||||
}
|
||||
|
||||
qualityClass(move: AnnotatedMove | null): string {
|
||||
if (!move?.quality) return '';
|
||||
return QUALITY_CLASSES[move.quality] ?? '';
|
||||
}
|
||||
|
||||
isWhiteActive(pairIndex: number): boolean {
|
||||
return this.activePly === pairIndex * 2;
|
||||
}
|
||||
|
||||
isBlackActive(pairIndex: number): boolean {
|
||||
return this.activePly === pairIndex * 2 + 1;
|
||||
}
|
||||
|
||||
selectWhite(pairIndex: number): void {
|
||||
this.plySelected.emit(pairIndex * 2);
|
||||
}
|
||||
|
||||
selectBlack(pairIndex: number, black: AnnotatedMove | null): void {
|
||||
if (!black) return;
|
||||
this.plySelected.emit(pairIndex * 2 + 1);
|
||||
}
|
||||
|
||||
formatEval(move: AnnotatedMove | null): string {
|
||||
if (!move || move.evalAfter === null) return '';
|
||||
const v = move.evalAfter;
|
||||
const sign = v > 0 ? '+' : '';
|
||||
return `${sign}${v.toFixed(2)}`;
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,53 @@
|
||||
:host {
|
||||
display: block;
|
||||
width: 100%;
|
||||
}
|
||||
|
||||
.timeline-wrap {
|
||||
width: 100%;
|
||||
overflow: hidden;
|
||||
}
|
||||
|
||||
.timeline-svg {
|
||||
display: block;
|
||||
width: 100%;
|
||||
height: 80px;
|
||||
}
|
||||
|
||||
.midline {
|
||||
stroke: rgba(255, 255, 255, 0.12);
|
||||
stroke-width: 1;
|
||||
stroke-dasharray: 4 4;
|
||||
}
|
||||
|
||||
.area-white {
|
||||
fill: rgba(255, 255, 255, 0.18);
|
||||
}
|
||||
|
||||
.area-black {
|
||||
fill: rgba(20, 20, 30, 0.55);
|
||||
}
|
||||
|
||||
.eval-line {
|
||||
fill: none;
|
||||
stroke: var(--nc-neon, #ff45c8);
|
||||
stroke-width: 1.5;
|
||||
stroke-linejoin: round;
|
||||
stroke-linecap: round;
|
||||
}
|
||||
|
||||
.active-marker {
|
||||
stroke: var(--nc-warning, #ffb13a);
|
||||
stroke-width: 1.5;
|
||||
stroke-dasharray: 3 3;
|
||||
opacity: 0.8;
|
||||
}
|
||||
|
||||
.empty {
|
||||
font-size: 11px;
|
||||
color: rgba(255, 255, 255, 0.4);
|
||||
padding: 12px 0;
|
||||
font-family: var(--nc-mono, monospace);
|
||||
letter-spacing: 0.06em;
|
||||
text-align: center;
|
||||
}
|
||||
@@ -0,0 +1,53 @@
|
||||
@if (points.length === 0) {
|
||||
<div class="empty">No evaluation data yet.</div>
|
||||
} @else {
|
||||
<div class="timeline-wrap" role="img" aria-label="Evaluation timeline">
|
||||
<svg
|
||||
class="timeline-svg"
|
||||
[attr.viewBox]="'0 0 ' + svgWidth + ' ' + svgHeight"
|
||||
preserveAspectRatio="none"
|
||||
>
|
||||
<!-- Midline (balanced) -->
|
||||
<line
|
||||
x1="0"
|
||||
[attr.y1]="svgHeight / 2"
|
||||
[attr.x2]="svgWidth"
|
||||
[attr.y2]="svgHeight / 2"
|
||||
class="midline"
|
||||
/>
|
||||
|
||||
<!-- White-advantage fill (clip above midline) -->
|
||||
<defs>
|
||||
<clipPath id="clip-white">
|
||||
<rect x="0" y="0" [attr.width]="svgWidth" [attr.height]="svgHeight / 2" />
|
||||
</clipPath>
|
||||
<clipPath id="clip-black">
|
||||
<rect
|
||||
x="0"
|
||||
[attr.y]="svgHeight / 2"
|
||||
[attr.width]="svgWidth"
|
||||
[attr.height]="svgHeight / 2"
|
||||
/>
|
||||
</clipPath>
|
||||
</defs>
|
||||
|
||||
<polygon [attr.points]="polylineWhite" class="area-white" clip-path="url(#clip-white)" />
|
||||
|
||||
<polygon [attr.points]="polylineBlack" class="area-black" clip-path="url(#clip-black)" />
|
||||
|
||||
<!-- Eval line -->
|
||||
<polyline [attr.points]="evalPolyline" class="eval-line" />
|
||||
|
||||
<!-- Active ply marker -->
|
||||
@if (activeX() !== null) {
|
||||
<line
|
||||
[attr.x1]="activeX()"
|
||||
y1="0"
|
||||
[attr.x2]="activeX()"
|
||||
[attr.y2]="svgHeight"
|
||||
class="active-marker"
|
||||
/>
|
||||
}
|
||||
</svg>
|
||||
</div>
|
||||
}
|
||||
@@ -0,0 +1,73 @@
|
||||
import { Component, Input, OnChanges } from '@angular/core';
|
||||
import { AnnotatedMove } from '../../models/analysis.models';
|
||||
|
||||
interface TimelinePoint {
|
||||
x: number;
|
||||
y: number;
|
||||
eval: number;
|
||||
san: string;
|
||||
plyIndex: number;
|
||||
}
|
||||
|
||||
const CLAMP = 5; // clamp eval to ±5 pawns for display
|
||||
const HEIGHT = 80;
|
||||
const WIDTH = 600;
|
||||
|
||||
@Component({
|
||||
selector: 'app-eval-timeline',
|
||||
standalone: true,
|
||||
imports: [],
|
||||
templateUrl: './eval-timeline.component.html',
|
||||
styleUrl: './eval-timeline.component.css',
|
||||
})
|
||||
export class EvalTimelineComponent implements OnChanges {
|
||||
@Input({ required: true }) moves: AnnotatedMove[] = [];
|
||||
@Input() activePly: number | null = null;
|
||||
|
||||
points: TimelinePoint[] = [];
|
||||
evalPolyline = '';
|
||||
polylineWhite = '';
|
||||
polylineBlack = '';
|
||||
svgWidth = WIDTH;
|
||||
svgHeight = HEIGHT;
|
||||
|
||||
ngOnChanges(): void {
|
||||
this.buildChart();
|
||||
}
|
||||
|
||||
activeX(): number | null {
|
||||
if (this.activePly === null) return null;
|
||||
const pt = this.points[this.activePly];
|
||||
return pt ? pt.x : null;
|
||||
}
|
||||
|
||||
private buildChart(): void {
|
||||
if (this.moves.length === 0) {
|
||||
this.points = [];
|
||||
this.evalPolyline = '';
|
||||
this.polylineWhite = '';
|
||||
this.polylineBlack = '';
|
||||
return;
|
||||
}
|
||||
|
||||
const total = this.moves.length;
|
||||
this.points = this.moves.map((m, i) => {
|
||||
const evalValue = m.evalAfter ?? 0;
|
||||
const clamped = Math.max(-CLAMP, Math.min(CLAMP, evalValue));
|
||||
const x = (i / Math.max(total - 1, 1)) * WIDTH;
|
||||
// y=0 => white winning (top), y=HEIGHT => black winning (bottom)
|
||||
const y = ((CLAMP - clamped) / (CLAMP * 2)) * HEIGHT;
|
||||
return { x, y, eval: evalValue, san: m.san, plyIndex: i };
|
||||
});
|
||||
|
||||
const coordStr = this.points.map((p) => `${p.x.toFixed(1)},${p.y.toFixed(1)}`).join(' ');
|
||||
this.evalPolyline = coordStr;
|
||||
|
||||
const mid = HEIGHT / 2;
|
||||
const first = this.points[0];
|
||||
const last = this.points[this.points.length - 1];
|
||||
|
||||
this.polylineWhite = `${first.x.toFixed(1)},${mid} ${coordStr} ${last.x.toFixed(1)},${mid}`;
|
||||
this.polylineBlack = this.polylineWhite;
|
||||
}
|
||||
}
|
||||
@@ -1,5 +1,4 @@
|
||||
<nav class="nc-nav">
|
||||
|
||||
<!-- Logo -->
|
||||
<div class="nc-logo" (click)="goToHome()" role="button" tabindex="0">
|
||||
<div class="nc-logo-mark">♞</div>
|
||||
@@ -8,201 +7,315 @@
|
||||
|
||||
<!-- Center links — only when logged in -->
|
||||
@if (currentUser) {
|
||||
<div class="nc-links">
|
||||
<button type="button" class="nc-link">
|
||||
<svg width="14" height="14" viewBox="0 0 24 24" fill="none" stroke="currentColor" stroke-width="1.7"
|
||||
stroke-linecap="round" stroke-linejoin="round">
|
||||
<path d="M1 12s4-8 11-8 11 8 11 8-4 8-11 8-11-8-11-8z" />
|
||||
<circle cx="12" cy="12" r="3" />
|
||||
</svg>
|
||||
Watch
|
||||
</button>
|
||||
<button type="button" class="nc-link" (click)="goToTournaments()">Tournaments</button>
|
||||
<button type="button" class="nc-link" (click)="goToBots()">Bots</button>
|
||||
</div>
|
||||
<div class="nc-links">
|
||||
<button type="button" class="nc-link">
|
||||
<svg
|
||||
width="14"
|
||||
height="14"
|
||||
viewBox="0 0 24 24"
|
||||
fill="none"
|
||||
stroke="currentColor"
|
||||
stroke-width="1.7"
|
||||
stroke-linecap="round"
|
||||
stroke-linejoin="round"
|
||||
>
|
||||
<path d="M1 12s4-8 11-8 11 8 11 8-4 8-11 8-11-8-11-8z" />
|
||||
<circle cx="12" cy="12" r="3" />
|
||||
</svg>
|
||||
Watch
|
||||
</button>
|
||||
<button type="button" class="nc-link" (click)="goToTournaments()">Tournaments</button>
|
||||
<button type="button" class="nc-link" (click)="goToBots()">Bots</button>
|
||||
<button type="button" class="nc-link" (click)="goToAnalysis()">Analysis</button>
|
||||
</div>
|
||||
}
|
||||
|
||||
<!-- Right cluster -->
|
||||
<div class="nc-right">
|
||||
|
||||
@if (currentUser; as user) {
|
||||
<!-- Notifications bell -->
|
||||
<div class="nc-dropdown-wrap" data-dropdown="notif">
|
||||
<button
|
||||
type="button"
|
||||
class="nc-bell"
|
||||
[class.is-open]="notifOpen"
|
||||
(click)="toggleNotif($event)"
|
||||
aria-label="Notifications"
|
||||
>
|
||||
<svg
|
||||
width="18"
|
||||
height="18"
|
||||
viewBox="0 0 24 24"
|
||||
fill="none"
|
||||
stroke="currentColor"
|
||||
stroke-width="1.6"
|
||||
stroke-linecap="round"
|
||||
stroke-linejoin="round"
|
||||
>
|
||||
<path d="M6 8a6 6 0 0 1 12 0c0 7 3 9 3 9H3s3-2 3-9" />
|
||||
<path d="M10.3 21a1.94 1.94 0 0 0 3.4 0" />
|
||||
</svg>
|
||||
@if (incomingChallenges.length > 0) {
|
||||
<span class="nc-badge">{{ incomingChallenges.length }}</span>
|
||||
}
|
||||
</button>
|
||||
|
||||
<!-- Notifications bell -->
|
||||
<div class="nc-dropdown-wrap" data-dropdown="notif">
|
||||
<button type="button" class="nc-bell" [class.is-open]="notifOpen" (click)="toggleNotif($event)"
|
||||
aria-label="Notifications">
|
||||
<svg width="18" height="18" viewBox="0 0 24 24" fill="none" stroke="currentColor" stroke-width="1.6"
|
||||
stroke-linecap="round" stroke-linejoin="round">
|
||||
<path d="M6 8a6 6 0 0 1 12 0c0 7 3 9 3 9H3s3-2 3-9" />
|
||||
<path d="M10.3 21a1.94 1.94 0 0 0 3.4 0" />
|
||||
</svg>
|
||||
@if (incomingChallenges.length > 0) {
|
||||
<span class="nc-badge">{{ incomingChallenges.length }}</span>
|
||||
@if (notifOpen) {
|
||||
<div class="nc-popover nc-notif" (click)="$event.stopPropagation()">
|
||||
<div class="nc-notif-header">
|
||||
<span class="nc-notif-header-title">Challenges</span>
|
||||
</div>
|
||||
|
||||
<div class="nc-notif-list">
|
||||
@if (incomingChallenges.length === 0) {
|
||||
<div class="nc-notif-empty">No pending challenges</div>
|
||||
}
|
||||
@for (challenge of incomingChallenges; track challenge.id) {
|
||||
<div class="nc-notif-row is-unread">
|
||||
<div class="nc-notif-icon">
|
||||
<svg
|
||||
width="14"
|
||||
height="14"
|
||||
viewBox="0 0 24 24"
|
||||
fill="none"
|
||||
stroke="currentColor"
|
||||
stroke-width="1.6"
|
||||
stroke-linecap="round"
|
||||
stroke-linejoin="round"
|
||||
>
|
||||
<line x1="14.5" y1="17.5" x2="3" y2="6" />
|
||||
<path d="M13 19l6 -6" />
|
||||
<path d="M16 16l4 4" />
|
||||
<path d="M19 21l2 -2" />
|
||||
<path d="M15 5l4 4" />
|
||||
<path d="M21 3l-3 1l-4 4" />
|
||||
</svg>
|
||||
</div>
|
||||
<div class="nc-notif-body">
|
||||
<div class="nc-notif-text">
|
||||
<b>{{ challenge.challenger.name }}</b> challenged you to a
|
||||
{{ getTimeControlDisplay(challenge) }} game.
|
||||
</div>
|
||||
<div class="nc-notif-meta">
|
||||
{{ challenge.challenger.rating }} ·
|
||||
{{ challenge.timeControl.type ?? 'Custom' }} ·
|
||||
{{ getExpirationInfo(challenge) }}
|
||||
</div>
|
||||
<div class="nc-notif-actions">
|
||||
<button
|
||||
type="button"
|
||||
class="nc-btn-accept"
|
||||
[disabled]="acceptingId === challenge.id || !!decliningId"
|
||||
(click)="acceptChallenge($event, challenge)"
|
||||
>
|
||||
<svg
|
||||
width="11"
|
||||
height="11"
|
||||
viewBox="0 0 24 24"
|
||||
fill="none"
|
||||
stroke="currentColor"
|
||||
stroke-width="2.4"
|
||||
stroke-linecap="round"
|
||||
stroke-linejoin="round"
|
||||
>
|
||||
<polyline points="20 6 9 17 4 12" />
|
||||
</svg>
|
||||
{{ acceptingId === challenge.id ? '...' : 'Accept' }}
|
||||
</button>
|
||||
<button
|
||||
type="button"
|
||||
class="nc-btn-decline"
|
||||
[disabled]="!!acceptingId || decliningId === challenge.id"
|
||||
(click)="declineChallenge($event, challenge)"
|
||||
>
|
||||
<svg
|
||||
width="10"
|
||||
height="10"
|
||||
viewBox="0 0 24 24"
|
||||
fill="none"
|
||||
stroke="currentColor"
|
||||
stroke-width="2.4"
|
||||
stroke-linecap="round"
|
||||
stroke-linejoin="round"
|
||||
>
|
||||
<line x1="18" y1="6" x2="6" y2="18" />
|
||||
<line x1="6" y1="6" x2="18" y2="18" />
|
||||
</svg>
|
||||
{{ decliningId === challenge.id ? '...' : 'Decline' }}
|
||||
</button>
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
}
|
||||
</div>
|
||||
|
||||
<div class="nc-notif-footer">
|
||||
<button type="button" class="nc-view-all" (click)="goToChallenges()">
|
||||
View all challenges
|
||||
</button>
|
||||
</div>
|
||||
</div>
|
||||
}
|
||||
</button>
|
||||
|
||||
@if (notifOpen) {
|
||||
<div class="nc-popover nc-notif" (click)="$event.stopPropagation()">
|
||||
<div class="nc-notif-header">
|
||||
<span class="nc-notif-header-title">Challenges</span>
|
||||
</div>
|
||||
|
||||
<div class="nc-notif-list">
|
||||
@if (incomingChallenges.length === 0) {
|
||||
<div class="nc-notif-empty">No pending challenges</div>
|
||||
}
|
||||
@for (challenge of incomingChallenges; track challenge.id) {
|
||||
<div class="nc-notif-row is-unread">
|
||||
<div class="nc-notif-icon">
|
||||
<svg width="14" height="14" viewBox="0 0 24 24" fill="none" stroke="currentColor" stroke-width="1.6"
|
||||
stroke-linecap="round" stroke-linejoin="round">
|
||||
<line x1="14.5" y1="17.5" x2="3" y2="6" />
|
||||
<path d="M13 19l6 -6" /><path d="M16 16l4 4" />
|
||||
<path d="M19 21l2 -2" /><path d="M15 5l4 4" />
|
||||
<path d="M21 3l-3 1l-4 4" />
|
||||
</svg>
|
||||
</div>
|
||||
<div class="nc-notif-body">
|
||||
<div class="nc-notif-text">
|
||||
<b>{{ challenge.challenger.name }}</b> challenged you to a
|
||||
{{ getTimeControlDisplay(challenge) }} game.
|
||||
</div>
|
||||
<div class="nc-notif-meta">
|
||||
{{ challenge.challenger.rating }} · {{ challenge.timeControl.type ?? 'Custom' }} · {{ getExpirationInfo(challenge) }}
|
||||
</div>
|
||||
<div class="nc-notif-actions">
|
||||
<button type="button" class="nc-btn-accept"
|
||||
[disabled]="acceptingId === challenge.id || !!decliningId"
|
||||
(click)="acceptChallenge($event, challenge)">
|
||||
<svg width="11" height="11" viewBox="0 0 24 24" fill="none" stroke="currentColor" stroke-width="2.4"
|
||||
stroke-linecap="round" stroke-linejoin="round">
|
||||
<polyline points="20 6 9 17 4 12" />
|
||||
</svg>
|
||||
{{ acceptingId === challenge.id ? '...' : 'Accept' }}
|
||||
</button>
|
||||
<button type="button" class="nc-btn-decline"
|
||||
[disabled]="!!acceptingId || decliningId === challenge.id"
|
||||
(click)="declineChallenge($event, challenge)">
|
||||
<svg width="10" height="10" viewBox="0 0 24 24" fill="none" stroke="currentColor" stroke-width="2.4"
|
||||
stroke-linecap="round" stroke-linejoin="round">
|
||||
<line x1="18" y1="6" x2="6" y2="18" /><line x1="6" y1="6" x2="18" y2="18" />
|
||||
</svg>
|
||||
{{ decliningId === challenge.id ? '...' : 'Decline' }}
|
||||
</button>
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
}
|
||||
</div>
|
||||
|
||||
<div class="nc-notif-footer">
|
||||
<button type="button" class="nc-view-all" (click)="goToChallenges()">View all challenges</button>
|
||||
</div>
|
||||
</div>
|
||||
}
|
||||
</div>
|
||||
|
||||
<!-- Games quick-access -->
|
||||
<button type="button" class="nc-games-btn" (click)="goToGames()">
|
||||
<svg width="13" height="13" viewBox="0 0 24 24" fill="none" stroke="currentColor" stroke-width="1.7"
|
||||
stroke-linecap="round" stroke-linejoin="round">
|
||||
<path d="M14.5 17.5L3 6"/>
|
||||
<path d="M13 19l6-6"/><path d="M16 16l4 4"/>
|
||||
<path d="M19 21l2-2"/><path d="M15 5l4 4"/>
|
||||
<path d="M21 3l-3 1-4 4"/>
|
||||
</svg>
|
||||
Games
|
||||
</button>
|
||||
|
||||
<!-- Profile -->
|
||||
<div class="nc-dropdown-wrap" data-dropdown="profile">
|
||||
<button type="button" class="nc-profile" [class.is-open]="profileOpen" (click)="toggleProfile($event)">
|
||||
<div class="nc-avatar nc-avatar-sm">{{ getInitial() }}</div>
|
||||
<span class="nc-profile-name">{{ user.username }}</span>
|
||||
<svg class="nc-chevron" width="12" height="12" viewBox="0 0 24 24" fill="none" stroke="currentColor"
|
||||
stroke-width="2" stroke-linecap="round" stroke-linejoin="round">
|
||||
<polyline points="6 9 12 15 18 9" />
|
||||
<!-- Games quick-access -->
|
||||
<button type="button" class="nc-games-btn" (click)="goToGames()">
|
||||
<svg
|
||||
width="13"
|
||||
height="13"
|
||||
viewBox="0 0 24 24"
|
||||
fill="none"
|
||||
stroke="currentColor"
|
||||
stroke-width="1.7"
|
||||
stroke-linecap="round"
|
||||
stroke-linejoin="round"
|
||||
>
|
||||
<path d="M14.5 17.5L3 6" />
|
||||
<path d="M13 19l6-6" />
|
||||
<path d="M16 16l4 4" />
|
||||
<path d="M19 21l2-2" />
|
||||
<path d="M15 5l4 4" />
|
||||
<path d="M21 3l-3 1-4 4" />
|
||||
</svg>
|
||||
Games
|
||||
</button>
|
||||
|
||||
@if (profileOpen) {
|
||||
<div class="nc-popover nc-menu" (click)="$event.stopPropagation()">
|
||||
<div class="nc-menu-header">
|
||||
<div class="nc-avatar nc-avatar-md">{{ getInitial() }}</div>
|
||||
<div>
|
||||
<div class="nc-menu-user-name">{{ user.username }}</div>
|
||||
<div class="nc-menu-user-sub">{{ user.rating }} · @{{ user.username }}</div>
|
||||
<!-- Profile -->
|
||||
<div class="nc-dropdown-wrap" data-dropdown="profile">
|
||||
<button
|
||||
type="button"
|
||||
class="nc-profile"
|
||||
[class.is-open]="profileOpen"
|
||||
(click)="toggleProfile($event)"
|
||||
>
|
||||
<div class="nc-avatar nc-avatar-sm">{{ getInitial() }}</div>
|
||||
<span class="nc-profile-name">{{ user.username }}</span>
|
||||
<svg
|
||||
class="nc-chevron"
|
||||
width="12"
|
||||
height="12"
|
||||
viewBox="0 0 24 24"
|
||||
fill="none"
|
||||
stroke="currentColor"
|
||||
stroke-width="2"
|
||||
stroke-linecap="round"
|
||||
stroke-linejoin="round"
|
||||
>
|
||||
<polyline points="6 9 12 15 18 9" />
|
||||
</svg>
|
||||
</button>
|
||||
|
||||
@if (profileOpen) {
|
||||
<div class="nc-popover nc-menu" (click)="$event.stopPropagation()">
|
||||
<div class="nc-menu-header">
|
||||
<div class="nc-avatar nc-avatar-md">{{ getInitial() }}</div>
|
||||
<div>
|
||||
<div class="nc-menu-user-name">{{ user.username }}</div>
|
||||
<div class="nc-menu-user-sub">{{ user.rating }} · @{{ user.username }}</div>
|
||||
</div>
|
||||
</div>
|
||||
|
||||
<div class="nc-menu-group">
|
||||
<button type="button" class="nc-menu-item" (click)="goToProfile()">
|
||||
<span class="nc-menu-icon">
|
||||
<svg
|
||||
width="14"
|
||||
height="14"
|
||||
viewBox="0 0 24 24"
|
||||
fill="none"
|
||||
stroke="currentColor"
|
||||
stroke-width="1.8"
|
||||
stroke-linecap="round"
|
||||
stroke-linejoin="round"
|
||||
>
|
||||
<path d="M20 21v-2a4 4 0 0 0-4-4H8a4 4 0 0 0-4 4v2" />
|
||||
<circle cx="12" cy="7" r="4" />
|
||||
</svg>
|
||||
</span>
|
||||
<span class="nc-menu-label">My profile</span>
|
||||
</button>
|
||||
|
||||
<button type="button" class="nc-menu-item" (click)="goToChallenges()">
|
||||
<span class="nc-menu-icon">
|
||||
<svg
|
||||
width="14"
|
||||
height="14"
|
||||
viewBox="0 0 24 24"
|
||||
fill="none"
|
||||
stroke="currentColor"
|
||||
stroke-width="1.6"
|
||||
stroke-linecap="round"
|
||||
stroke-linejoin="round"
|
||||
>
|
||||
<line x1="14.5" y1="17.5" x2="3" y2="6" />
|
||||
<path d="M13 19l6 -6" />
|
||||
<path d="M16 16l4 4" />
|
||||
<path d="M19 21l2 -2" />
|
||||
<path d="M15 5l4 4" />
|
||||
<path d="M21 3l-3 1l-4 4" />
|
||||
</svg>
|
||||
</span>
|
||||
<span class="nc-menu-label">Challenges</span>
|
||||
</button>
|
||||
|
||||
<button type="button" class="nc-menu-item" (click)="toggleTheme($event)">
|
||||
<span class="nc-menu-icon">
|
||||
<svg
|
||||
width="14"
|
||||
height="14"
|
||||
viewBox="0 0 24 24"
|
||||
fill="none"
|
||||
stroke="currentColor"
|
||||
stroke-width="1.7"
|
||||
stroke-linecap="round"
|
||||
stroke-linejoin="round"
|
||||
>
|
||||
<path d="M21 12.8A9 9 0 1 1 11.2 3a7 7 0 0 0 9.8 9.8z" />
|
||||
</svg>
|
||||
</span>
|
||||
<span class="nc-menu-label">{{ isDarkMode ? 'Light mode' : 'Dark mode' }}</span>
|
||||
<span class="nc-toggle" [class.is-on]="isDarkMode"></span>
|
||||
</button>
|
||||
</div>
|
||||
|
||||
<div class="nc-menu-group">
|
||||
<button type="button" class="nc-menu-item danger" (click)="logout()">
|
||||
<span class="nc-menu-icon">
|
||||
<svg
|
||||
width="14"
|
||||
height="14"
|
||||
viewBox="0 0 24 24"
|
||||
fill="none"
|
||||
stroke="currentColor"
|
||||
stroke-width="1.7"
|
||||
stroke-linecap="round"
|
||||
stroke-linejoin="round"
|
||||
>
|
||||
<path d="M9 21H5a2 2 0 0 1-2-2V5a2 2 0 0 1 2-2h4" />
|
||||
<polyline points="16 17 21 12 16 7" />
|
||||
<line x1="21" y1="12" x2="9" y2="12" />
|
||||
</svg>
|
||||
</span>
|
||||
<span class="nc-menu-label">Log out</span>
|
||||
</button>
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
|
||||
<div class="nc-menu-group">
|
||||
<button type="button" class="nc-menu-item" (click)="goToProfile()">
|
||||
<span class="nc-menu-icon">
|
||||
<svg width="14" height="14" viewBox="0 0 24 24" fill="none" stroke="currentColor" stroke-width="1.8"
|
||||
stroke-linecap="round" stroke-linejoin="round">
|
||||
<path d="M20 21v-2a4 4 0 0 0-4-4H8a4 4 0 0 0-4 4v2" />
|
||||
<circle cx="12" cy="7" r="4" />
|
||||
</svg>
|
||||
</span>
|
||||
<span class="nc-menu-label">My profile</span>
|
||||
</button>
|
||||
|
||||
<button type="button" class="nc-menu-item" (click)="goToChallenges()">
|
||||
<span class="nc-menu-icon">
|
||||
<svg width="14" height="14" viewBox="0 0 24 24" fill="none" stroke="currentColor" stroke-width="1.6"
|
||||
stroke-linecap="round" stroke-linejoin="round">
|
||||
<line x1="14.5" y1="17.5" x2="3" y2="6" />
|
||||
<path d="M13 19l6 -6" /><path d="M16 16l4 4" />
|
||||
<path d="M19 21l2 -2" /><path d="M15 5l4 4" />
|
||||
<path d="M21 3l-3 1l-4 4" />
|
||||
</svg>
|
||||
</span>
|
||||
<span class="nc-menu-label">Challenges</span>
|
||||
</button>
|
||||
|
||||
<button type="button" class="nc-menu-item" (click)="toggleTheme($event)">
|
||||
<span class="nc-menu-icon">
|
||||
<svg width="14" height="14" viewBox="0 0 24 24" fill="none" stroke="currentColor" stroke-width="1.7"
|
||||
stroke-linecap="round" stroke-linejoin="round">
|
||||
<path d="M21 12.8A9 9 0 1 1 11.2 3a7 7 0 0 0 9.8 9.8z" />
|
||||
</svg>
|
||||
</span>
|
||||
<span class="nc-menu-label">{{ isDarkMode ? 'Light mode' : 'Dark mode' }}</span>
|
||||
<span class="nc-toggle" [class.is-on]="isDarkMode"></span>
|
||||
</button>
|
||||
</div>
|
||||
|
||||
<div class="nc-menu-group">
|
||||
<button type="button" class="nc-menu-item danger" (click)="logout()">
|
||||
<span class="nc-menu-icon">
|
||||
<svg width="14" height="14" viewBox="0 0 24 24" fill="none" stroke="currentColor" stroke-width="1.7"
|
||||
stroke-linecap="round" stroke-linejoin="round">
|
||||
<path d="M9 21H5a2 2 0 0 1-2-2V5a2 2 0 0 1 2-2h4" />
|
||||
<polyline points="16 17 21 12 16 7" />
|
||||
<line x1="21" y1="12" x2="9" y2="12" />
|
||||
</svg>
|
||||
</span>
|
||||
<span class="nc-menu-label">Log out</span>
|
||||
</button>
|
||||
</div>
|
||||
}
|
||||
</div>
|
||||
}
|
||||
</div>
|
||||
|
||||
} @else {
|
||||
|
||||
<!-- Logged-out auth buttons -->
|
||||
<button type="button" class="nc-auth-btn" (click)="openLoginDialog()">Login</button>
|
||||
<button type="button" class="nc-auth-btn nc-auth-btn--primary" (click)="openRegisterDialog()">Register</button>
|
||||
|
||||
<!-- Logged-out auth buttons -->
|
||||
<button type="button" class="nc-auth-btn" (click)="openLoginDialog()">Login</button>
|
||||
<button type="button" class="nc-auth-btn nc-auth-btn--primary" (click)="openRegisterDialog()">
|
||||
Register
|
||||
</button>
|
||||
}
|
||||
</div>
|
||||
</nav>
|
||||
|
||||
@if (showLoginDialog) {
|
||||
<app-login-dialog (onClose)="closeLoginDialog()" (onSuccess)="onLoginSuccess()" />
|
||||
<app-login-dialog (onClose)="closeLoginDialog()" (onSuccess)="onLoginSuccess()" />
|
||||
}
|
||||
|
||||
@if (showRegisterDialog) {
|
||||
<app-register-dialog (onClose)="closeRegisterDialog()" (onSuccess)="onRegisterSuccess()" />
|
||||
<app-register-dialog (onClose)="closeRegisterDialog()" (onSuccess)="onRegisterSuccess()" />
|
||||
}
|
||||
|
||||
@@ -18,7 +18,7 @@ import { Challenge } from '../../models/challenge.models';
|
||||
standalone: true,
|
||||
imports: [CommonModule, LoginDialogComponent, RegisterDialogComponent],
|
||||
templateUrl: './toolbar.component.html',
|
||||
styleUrl: './toolbar.component.css'
|
||||
styleUrl: './toolbar.component.css',
|
||||
})
|
||||
export class ToolbarComponent implements OnInit {
|
||||
private readonly destroyRef = inject(DestroyRef);
|
||||
@@ -46,35 +46,36 @@ export class ToolbarComponent implements OnInit {
|
||||
ngOnInit(): void {
|
||||
this.destroyRef.onDestroy(() => this.stopPolling());
|
||||
|
||||
this.authService.currentUser$
|
||||
.pipe(takeUntilDestroyed(this.destroyRef))
|
||||
.subscribe(user => {
|
||||
this.currentUser = user;
|
||||
if (user) {
|
||||
this.challengeWs.connect();
|
||||
this.startPolling();
|
||||
} else {
|
||||
this.challengeWs.disconnect();
|
||||
this.stopPolling();
|
||||
this.navigatedChallengeIds.clear();
|
||||
this.challengeEventService.clear();
|
||||
}
|
||||
});
|
||||
this.authService.currentUser$.pipe(takeUntilDestroyed(this.destroyRef)).subscribe((user) => {
|
||||
this.currentUser = user;
|
||||
if (user) {
|
||||
this.challengeWs.connect();
|
||||
this.startPolling();
|
||||
} else {
|
||||
this.challengeWs.disconnect();
|
||||
this.stopPolling();
|
||||
this.navigatedChallengeIds.clear();
|
||||
this.challengeEventService.clear();
|
||||
}
|
||||
});
|
||||
|
||||
this.authDialogService.dialogState$
|
||||
.pipe(takeUntilDestroyed(this.destroyRef))
|
||||
.subscribe(state => {
|
||||
.subscribe((state) => {
|
||||
this.showLoginDialog = state === 'login';
|
||||
this.showRegisterDialog = state === 'register';
|
||||
});
|
||||
|
||||
this.themeService.darkMode$
|
||||
.pipe(takeUntilDestroyed(this.destroyRef))
|
||||
.subscribe(isDark => { this.isDarkMode = isDark; });
|
||||
this.themeService.darkMode$.pipe(takeUntilDestroyed(this.destroyRef)).subscribe((isDark) => {
|
||||
this.isDarkMode = isDark;
|
||||
});
|
||||
|
||||
this.challengeEventService.getIncomingChallenges$()
|
||||
this.challengeEventService
|
||||
.getIncomingChallenges$()
|
||||
.pipe(takeUntilDestroyed(this.destroyRef))
|
||||
.subscribe(challenges => { this.incomingChallenges = challenges; });
|
||||
.subscribe((challenges) => {
|
||||
this.incomingChallenges = challenges;
|
||||
});
|
||||
}
|
||||
|
||||
private startPolling(): void {
|
||||
@@ -91,7 +92,7 @@ export class ToolbarComponent implements OnInit {
|
||||
|
||||
private fetchChallenges(): void {
|
||||
this.challengeService.listChallenges().subscribe({
|
||||
next: response => {
|
||||
next: (response) => {
|
||||
const incoming = response.in ?? response.incoming ?? [];
|
||||
this.challengeEventService.setIncomingChallenges(incoming);
|
||||
|
||||
@@ -104,7 +105,7 @@ export class ToolbarComponent implements OnInit {
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
},
|
||||
});
|
||||
}
|
||||
|
||||
@@ -197,6 +198,12 @@ export class ToolbarComponent implements OnInit {
|
||||
void this.router.navigate(['/bots']);
|
||||
}
|
||||
|
||||
goToAnalysis(): void {
|
||||
this.profileOpen = false;
|
||||
this.notifOpen = false;
|
||||
void this.router.navigate(['/analysis']);
|
||||
}
|
||||
|
||||
onLoginSuccess(): void {
|
||||
this.closeLoginDialog();
|
||||
}
|
||||
@@ -227,12 +234,14 @@ export class ToolbarComponent implements OnInit {
|
||||
if (this.acceptingId || this.decliningId) return;
|
||||
this.acceptingId = challenge.id;
|
||||
this.challengeService.acceptChallenge(challenge.id).subscribe({
|
||||
next: accepted => {
|
||||
next: (accepted) => {
|
||||
this.acceptingId = null;
|
||||
this.challengeEventService.onChallengeAccepted(accepted);
|
||||
if (accepted.gameId) void this.router.navigate(['/game', accepted.gameId]);
|
||||
},
|
||||
error: () => { this.acceptingId = null; }
|
||||
error: () => {
|
||||
this.acceptingId = null;
|
||||
},
|
||||
});
|
||||
}
|
||||
|
||||
@@ -245,7 +254,9 @@ export class ToolbarComponent implements OnInit {
|
||||
this.decliningId = null;
|
||||
this.challengeEventService.removeChallenge(challenge.id);
|
||||
},
|
||||
error: () => { this.decliningId = null; }
|
||||
error: () => {
|
||||
this.decliningId = null;
|
||||
},
|
||||
});
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user