fix: NCWF-4 Token Issues (#8)

Co-authored-by: Lala, Shahd <Shahd.Lala@sybit.de>
Co-authored-by: shahdlala66 <shahd.lala66@gmail.com>
Reviewed-on: #8
This commit was merged in pull request #8.
This commit is contained in:
2026-06-02 21:55:55 +02:00
parent 873bfe3bae
commit 95eff42dfe
37 changed files with 2522 additions and 573 deletions
+163
View File
@@ -0,0 +1,163 @@
:host {
--nc-neon: #ff45c8;
--nc-bg: #06060d;
--nc-surface: rgba(20, 17, 42, 0.6);
--nc-text: #fff;
--nc-text-muted: rgba(255, 255, 255, 0.65);
--nc-text-dim: rgba(255, 255, 255, 0.45);
--nc-border: rgba(255, 255, 255, 0.08);
--nc-border-strong: rgba(255, 255, 255, 0.15);
--nc-success: #5ee5a1;
--nc-danger: #ff7a7a;
--nc-warn: #ffd166;
--nc-sans: "Space Grotesk", -apple-system, BlinkMacSystemFont, "Segoe UI", sans-serif;
display: block;
min-height: 100vh;
background: var(--nc-bg);
font-family: var(--nc-sans);
color: var(--nc-text);
}
:host-context(html:not([data-theme='dark'])) {
--nc-neon: #c026d3;
--nc-bg: #f5f0fc;
--nc-surface: rgba(255, 255, 255, 0.88);
--nc-text: #0f0022;
--nc-text-muted: rgba(15, 0, 34, 0.65);
--nc-text-dim: rgba(15, 0, 34, 0.4);
--nc-border: rgba(15, 0, 34, 0.1);
--nc-border-strong: rgba(15, 0, 34, 0.2);
--nc-success: #16a34a;
--nc-danger: #dc2626;
--nc-warn: #b45309;
}
.b-shell { padding-top: 72px; min-height: 100vh; }
.page { max-width: 680px; margin: 0 auto; padding: 32px 20px 64px; }
.crumb { display: flex; align-items: center; gap: 8px; margin-bottom: 28px;
font-size: 11px; color: var(--nc-text-dim); letter-spacing: 0.06em; }
.crumb-link { display: inline-flex; align-items: center; gap: 4px;
color: var(--nc-text-dim); text-decoration: none; transition: color 0.15s; }
.crumb-link:hover { color: var(--nc-neon); }
.crumb-sep { opacity: 0.35; }
.crumb-current { color: var(--nc-text-muted); }
.page-header { margin-bottom: 24px; }
.title-row { display: flex; align-items: center; justify-content: space-between; margin-bottom: 8px; }
.page-title { font-size: 22px; font-weight: 700; margin: 0; letter-spacing: -0.02em; }
.page-sub { font-size: 13px; color: var(--nc-text-muted); margin: 0; line-height: 1.5; }
.btn-new {
display: inline-flex; align-items: center; gap: 6px;
padding: 7px 14px; border-radius: 8px; border: none;
background: var(--nc-neon); color: #fff;
font-size: 13px; font-weight: 600; cursor: pointer; transition: opacity 0.15s;
}
.btn-new:hover { opacity: 0.85; }
/* Create panel */
.create-panel {
border: 1px solid var(--nc-border-strong); border-radius: 12px;
background: var(--nc-surface); padding: 16px; margin-bottom: 20px;
}
.create-inner { display: flex; flex-direction: column; gap: 10px; }
.field-label { font-size: 11px; font-weight: 600; text-transform: uppercase;
letter-spacing: 0.06em; color: var(--nc-text-muted); }
.create-row { display: flex; gap: 8px; align-items: center; }
.text-input {
flex: 1; padding: 8px 12px; border-radius: 8px;
border: 1px solid var(--nc-border-strong);
background: rgba(255,255,255,0.04); color: var(--nc-text); font-size: 14px;
}
.text-input:focus { outline: 2px solid var(--nc-neon); outline-offset: 1px; border-color: transparent; }
.text-input:disabled { opacity: 0.5; }
.error-text { font-size: 12px; color: var(--nc-danger); margin: 0; }
/* Buttons */
.btn-primary {
padding: 8px 16px; border-radius: 8px; border: none;
background: var(--nc-neon); color: #fff; font-size: 13px; font-weight: 600;
cursor: pointer; white-space: nowrap; transition: opacity 0.15s;
}
.btn-primary:disabled { opacity: 0.5; cursor: not-allowed; }
.btn-ghost {
padding: 8px 14px; border-radius: 8px; border: 1px solid var(--nc-border-strong);
background: transparent; color: var(--nc-text-muted); font-size: 13px; cursor: pointer;
}
.btn-ghost:disabled { opacity: 0.5; cursor: not-allowed; }
/* States */
.state-msg { display: flex; align-items: center; gap: 10px;
padding: 24px 0; color: var(--nc-text-muted); font-size: 13px; }
.pulse { width: 8px; height: 8px; border-radius: 50%; background: var(--nc-neon);
flex-shrink: 0; animation: pulse 1.4s ease-in-out infinite; }
@keyframes pulse { 0%, 100% { opacity: 1; transform: scale(1); } 50% { opacity: 0.4; transform: scale(0.85); } }
.empty-state { display: flex; flex-direction: column; align-items: center;
gap: 8px; padding: 64px 0; text-align: center; }
.empty-icon { color: var(--nc-text-dim); margin-bottom: 4px; }
.empty-title { font-size: 15px; font-weight: 600; margin: 0; }
.empty-sub { font-size: 13px; color: var(--nc-text-muted); margin: 0; }
/* Bot list */
.bot-list { display: flex; flex-direction: column; gap: 8px; }
.bot-card {
border: 1px solid var(--nc-border); border-radius: 12px;
background: var(--nc-surface); overflow: hidden;
}
.bot-main {
display: flex; align-items: center; gap: 12px;
padding: 14px 16px;
}
.bot-avatar {
width: 36px; height: 36px; border-radius: 50%; flex-shrink: 0;
background: var(--nc-neon); color: #fff;
display: flex; align-items: center; justify-content: center;
font-size: 16px; font-weight: 700;
}
.bot-info { display: flex; flex-direction: column; gap: 3px; flex: 1; min-width: 0; }
.bot-name { font-size: 14px; font-weight: 600; }
.bot-meta { font-size: 11px; color: var(--nc-text-muted); }
.bot-actions { display: flex; gap: 8px; flex-shrink: 0; }
.btn-token {
display: inline-flex; align-items: center; gap: 5px;
padding: 6px 12px; border-radius: 7px; border: 1px solid var(--nc-border-strong);
background: transparent; color: var(--nc-text-muted); font-size: 12px; cursor: pointer;
transition: background 0.15s, color 0.15s;
}
.btn-token:hover, .btn-token.active { background: rgba(255,69,200,0.1); color: var(--nc-neon); border-color: var(--nc-neon); }
.btn-token:disabled { opacity: 0.5; cursor: not-allowed; }
.btn-danger {
padding: 6px 12px; border-radius: 7px; border: 1px solid rgba(255,122,122,0.3);
background: transparent; color: var(--nc-danger); font-size: 12px; cursor: pointer;
transition: background 0.15s;
}
.btn-danger:hover { background: rgba(255,122,122,0.1); }
.btn-danger:disabled { opacity: 0.5; cursor: not-allowed; }
/* Token panel */
.token-panel {
border-top: 1px solid var(--nc-border); padding: 12px 16px;
display: flex; flex-direction: column; gap: 10px;
}
.token-warning {
display: flex; align-items: flex-start; gap: 8px;
font-size: 12px; color: var(--nc-warn);
}
.token-row { display: flex; align-items: center; gap: 8px; }
.token-value {
flex: 1; font-family: monospace; font-size: 11px;
background: rgba(0,0,0,0.2); border-radius: 6px;
padding: 8px 10px; word-break: break-all;
color: var(--nc-text-muted); border: 1px solid var(--nc-border);
}
.btn-copy {
padding: 6px 12px; border-radius: 7px; border: 1px solid var(--nc-border-strong);
background: transparent; color: var(--nc-text-muted); font-size: 12px;
cursor: pointer; white-space: nowrap; transition: color 0.15s;
flex-shrink: 0;
}
.btn-copy:hover { color: var(--nc-success); }
+125
View File
@@ -0,0 +1,125 @@
<div class="b-shell">
<div class="page">
<nav class="crumb">
<a routerLink="/" class="crumb-link">
<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="15 18 9 12 15 6"/>
</svg>
Back to lobby
</a>
<span class="crumb-sep">/</span>
<span class="crumb-current">My Bots</span>
</nav>
<header class="page-header">
<div class="title-row">
<h1 class="page-title">My Bots</h1>
<button type="button" class="btn-new" (click)="openCreate()">
<svg width="13" height="13" viewBox="0 0 24 24" fill="none" stroke="currentColor"
stroke-width="2.4" stroke-linecap="round" stroke-linejoin="round">
<line x1="12" y1="5" x2="12" y2="19"/><line x1="5" y1="12" x2="19" y2="12"/>
</svg>
New bot
</button>
</div>
<p class="page-sub">Bots are automated players owned by your account. Each has a token used to join tournaments and make moves.</p>
</header>
@if (showCreate) {
<div class="create-panel">
<div class="create-inner">
<label class="field-label">Bot name</label>
<div class="create-row">
<input type="text" class="text-input" [(ngModel)]="newBotName"
placeholder="e.g. AlphaBot" (keydown.enter)="submitCreate()"
[disabled]="creating" maxlength="40" />
<button type="button" class="btn-primary" (click)="submitCreate()"
[disabled]="creating || !newBotName.trim()">
{{ creating ? 'Creating…' : 'Create' }}
</button>
<button type="button" class="btn-ghost" (click)="cancelCreate()" [disabled]="creating">
Cancel
</button>
</div>
@if (createError) {
<p class="error-text">{{ createError }}</p>
}
</div>
</div>
}
@if (loading) {
<div class="state-msg"><span class="pulse"></span>Loading bots…</div>
} @else if (bots.length === 0) {
<div class="empty-state">
<svg width="36" height="36" viewBox="0 0 24 24" fill="none" stroke="currentColor"
stroke-width="1.3" stroke-linecap="round" stroke-linejoin="round" class="empty-icon">
<rect x="3" y="11" width="18" height="11" rx="2" ry="2"/>
<path d="M7 11V7a5 5 0 0 1 10 0v4"/>
</svg>
<p class="empty-title">No bots yet</p>
<p class="empty-sub">Create a bot to join tournaments and play automated games.</p>
</div>
} @else {
<div class="bot-list">
@for (bot of bots; track bot.id) {
<div class="bot-card">
<div class="bot-main">
<div class="bot-avatar">{{ bot.name.charAt(0).toUpperCase() }}</div>
<div class="bot-info">
<span class="bot-name">{{ bot.name }}</span>
<span class="bot-meta">Rating {{ bot.rating }} · Created {{ bot.createdAt | date:'MMM d, yyyy' }}</span>
</div>
<div class="bot-actions">
<button type="button" class="btn-token"
[class.active]="!!revealedTokens[bot.id]"
[disabled]="revealingId === bot.id"
(click)="revealToken(bot.id)">
<svg width="12" height="12" viewBox="0 0 24 24" fill="none" stroke="currentColor"
stroke-width="2" stroke-linecap="round" stroke-linejoin="round">
@if (revealedTokens[bot.id]) {
<path d="M17.94 17.94A10.07 10.07 0 0 1 12 20c-7 0-11-8-11-8a18.45 18.45 0 0 1 5.06-5.94"/>
<path d="M9.9 4.24A9.12 9.12 0 0 1 12 4c7 0 11 8 11 8a18.5 18.5 0 0 1-2.16 3.19"/>
<line x1="1" y1="1" x2="23" y2="23"/>
} @else {
<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>
{{ revealingId === bot.id ? '…' : (revealedTokens[bot.id] ? 'Hide' : 'Token') }}
</button>
<button type="button" class="btn-danger"
[disabled]="deletingId === bot.id"
(click)="deleteBot(bot.id)">
{{ deletingId === bot.id ? '…' : 'Delete' }}
</button>
</div>
</div>
@if (revealedTokens[bot.id]) {
<div class="token-panel">
<div class="token-warning">
<svg width="13" height="13" viewBox="0 0 24 24" fill="none" stroke="currentColor"
stroke-width="2" stroke-linecap="round" stroke-linejoin="round">
<path d="M10.29 3.86L1.82 18a2 2 0 0 0 1.71 3h16.94a2 2 0 0 0 1.71-3L13.71 3.86a2 2 0 0 0-3.42 0z"/>
<line x1="12" y1="9" x2="12" y2="13"/><line x1="12" y1="17" x2="12.01" y2="17"/>
</svg>
Token was just regenerated — the old one is now invalid. Keep this secret.
</div>
<div class="token-row">
<code class="token-value">{{ revealedTokens[bot.id] }}</code>
<button type="button" class="btn-copy" (click)="copyToken(bot.id)">
{{ copiedId === bot.id ? '✓ Copied' : 'Copy' }}
</button>
</div>
</div>
}
</div>
}
</div>
}
</div>
</div>
+111
View File
@@ -0,0 +1,111 @@
import { Component, DestroyRef, OnInit, inject } from '@angular/core';
import { CommonModule } from '@angular/common';
import { RouterLink } from '@angular/router';
import { FormsModule } from '@angular/forms';
import { takeUntilDestroyed } from '@angular/core/rxjs-interop';
import { BotService } from '../../services/bot.service';
import { Bot, BotWithToken } from '../../models/bot.models';
@Component({
selector: 'app-bots',
standalone: true,
imports: [CommonModule, RouterLink, FormsModule],
templateUrl: './bots.component.html',
styleUrl: './bots.component.css'
})
export class BotsComponent implements OnInit {
private readonly destroyRef = inject(DestroyRef);
private readonly botService = inject(BotService);
bots: Bot[] = [];
loading = true;
showCreate = false;
newBotName = '';
creating = false;
createError: string | null = null;
revealedTokens: Record<string, string> = {};
revealingId: string | null = null;
copiedId: string | null = null;
deletingId: string | null = null;
ngOnInit(): void {
this.loadBots();
}
loadBots(): void {
this.loading = true;
this.botService.list()
.pipe(takeUntilDestroyed(this.destroyRef))
.subscribe({
next: bots => { this.bots = bots; this.loading = false; },
error: () => { this.loading = false; }
});
}
openCreate(): void {
this.newBotName = '';
this.createError = null;
this.showCreate = true;
}
cancelCreate(): void {
this.showCreate = false;
}
submitCreate(): void {
const name = this.newBotName.trim();
if (!name) return;
this.creating = true;
this.createError = null;
this.botService.create(name).subscribe({
next: (bot: BotWithToken) => {
this.creating = false;
this.showCreate = false;
this.bots = [bot, ...this.bots];
this.revealedTokens[bot.id] = bot.token;
},
error: err => {
this.creating = false;
this.createError = err.error?.message ?? err.error?.error ?? 'Failed to create bot.';
}
});
}
revealToken(botId: string): void {
if (this.revealedTokens[botId]) {
delete this.revealedTokens[botId];
return;
}
this.revealingId = botId;
this.botService.rotateToken(botId).subscribe({
next: token => {
this.revealingId = null;
this.revealedTokens[botId] = token;
},
error: () => { this.revealingId = null; }
});
}
copyToken(botId: string): void {
const token = this.revealedTokens[botId];
if (!token) return;
navigator.clipboard.writeText(token).then(() => {
this.copiedId = botId;
setTimeout(() => { this.copiedId = null; }, 2000);
});
}
deleteBot(botId: string): void {
this.deletingId = botId;
this.botService.delete(botId).subscribe({
next: () => {
this.deletingId = null;
this.bots = this.bots.filter(b => b.id !== botId);
delete this.revealedTokens[botId];
},
error: () => { this.deletingId = null; }
});
}
}