From 3ccab53b41cb007ca73a3b761314309453c66248 Mon Sep 17 00:00:00 2001 From: tyuXX Date: Sun, 22 Nov 2026 20:10:16 +0300 Subject: [PATCH] Fix post-game analysis state, add profile nav route, and fix mobile profile overflow --- src/client/components/navbar.ts | 11 +++- src/client/main.ts | 6 +++ src/client/styles.css | 90 ++++++++++++++++++++++++++++++-- src/client/views/analysisView.ts | 28 +++++++++- src/client/views/profileView.ts | 31 +++++++---- src/server/httpApi.ts | 14 +++-- tests/server.test.ts | 1 + 7 files changed, 158 insertions(+), 23 deletions(-) diff --git a/src/client/components/navbar.ts b/src/client/components/navbar.ts index a629552..1cfecc2 100644 --- a/src/client/components/navbar.ts +++ b/src/client/components/navbar.ts @@ -75,7 +75,14 @@ export class Navbar { badge: state.friendBadgeCount > 0 ? state.friendBadgeCount : undefined, match: (p) => p.indexOf('/friends') === 0 }, - { href: '/leaderboard', label: 'Leaderboard', match: (p) => p.indexOf('/leaderboard') === 0 } + { href: '/leaderboard', label: 'Leaderboard', match: (p) => p.indexOf('/leaderboard') === 0 }, + { + href: state.user ? `/u/${encodeURIComponent(state.user.username)}` : '/profile', + label: 'Profile', + match: (p) => + p === '/profile' || + (state.user !== null && p.toLowerCase() === `/u/${encodeURIComponent(state.user.username)}`.toLowerCase()) + } ]; for (const item of navItems) { @@ -129,7 +136,7 @@ export class Navbar { if (state.user) { const profileLink = el( 'a', - { href: `/u/${encodeURIComponent(state.user.username)}`, className: 'nav-user-link' }, + { href: `/u/${encodeURIComponent(state.user.username)}`, className: 'btn btn-sm nav-user-link' }, state.user.username ); profileLink.addEventListener('click', (e) => { diff --git a/src/client/main.ts b/src/client/main.ts index b0156d3..eddaef1 100644 --- a/src/client/main.ts +++ b/src/client/main.ts @@ -150,6 +150,12 @@ class App { this.activeView = mountFriendsView(this.mainEl, this.ctx); } else if (pathname === '/leaderboard') { this.activeView = mountLeaderboardView(this.mainEl, this.ctx); + } else if (pathname === '/profile') { + if (this.user) { + this.activeView = mountProfileView(this.mainEl, this.ctx, this.user.username); + } else { + this.navigate('/login?next=/profile', true); + } } else if (pathname === '/analysis') { this.activeView = mountAnalysisView(this.mainEl, this.ctx); } else if (pathname.indexOf('/analysis/') === 0) { diff --git a/src/client/styles.css b/src/client/styles.css index da79275..128213b 100644 --- a/src/client/styles.css +++ b/src/client/styles.css @@ -222,12 +222,15 @@ a { .nav-user-link { font-weight: 600; - font-size: 13px; - padding: 4px 6px; + font-size: 12px; + max-width: 140px; + overflow: hidden; + text-overflow: ellipsis; + white-space: nowrap; } .nav-user-link:hover { - text-decoration: underline; + border-color: var(--accent); } /* Main container */ @@ -756,8 +759,16 @@ a { align-items: center; } +.profile-id { + min-width: 0; + max-width: 100%; + overflow-wrap: break-word; + margin-bottom: 6px; +} + .profile-title-row { display: flex; + flex-wrap: wrap; align-items: center; margin-bottom: 4px; } @@ -765,6 +776,22 @@ a { .profile-username { margin: 0 8px 0 0; font-size: 20px; + word-break: break-word; +} + +.table-scroll-wrap { + width: 100%; + overflow-x: auto; + -webkit-overflow-scrolling: touch; +} + +.mobile-game-meta { + display: none; +} + +.game-players-text { + overflow-wrap: break-word; + word-break: break-word; } .h2h-line { @@ -1650,8 +1677,33 @@ a { } .rating-card { - width: 49%; - margin-right: 1%; + width: 48.5%; + margin-right: 3%; + } + + .rating-card:nth-child(2n) { + margin-right: 0; + } + + .rating-big { + font-size: 16px; + } + + .filter-bar > .select { + flex: 1 1 46%; + min-width: 0; + } + + .filter-bar > .filter-opp { + flex: 1 1 140px; + width: auto; + min-width: 0; + } + + .inline-pw-form > .input { + width: 100%; + flex: 1 1 100%; + margin-right: 0; } .bot-level-card { @@ -1659,3 +1711,31 @@ a { margin-right: 0; } } + +@media (max-width: 600px) { + .profile-games-table .col-time, + .profile-games-table .col-date { + display: none; + } + + .mobile-game-meta { + display: block; + margin-top: 2px; + } + + .profile-games-table th, + .profile-games-table td { + padding: 7px 8px; + } + + .profile-games-table .col-actions .btn { + display: block; + width: 100%; + margin-left: 0; + margin-bottom: 4px; + } + + .profile-games-table .col-actions .btn:last-child { + margin-bottom: 0; + } +} diff --git a/src/client/views/analysisView.ts b/src/client/views/analysisView.ts index 5a9d9db..6cc1cad 100644 --- a/src/client/views/analysisView.ts +++ b/src/client/views/analysisView.ts @@ -37,6 +37,7 @@ export function mountAnalysisView( gameId?: string ): ViewHandle { let storedGame: StoredGame | null = null; + let unsavedAborted = false; let report: GameAnalysisReport | null = null; let loadError = ''; @@ -463,6 +464,18 @@ export function mountAnalysisView( ); const body = el('div', { className: 'card-body compact' }); + if (unsavedAborted) { + body.appendChild( + el( + 'div', + { className: 'small-text muted' }, + 'Aborted games (< 2 plies) are not saved for post-game reports, but you can explore lines with the Live Engine above.' + ) + ); + analysisControlEl.appendChild(body); + return; + } + if (!report || report.status === 'error') { if (report?.status === 'error') { body.appendChild(el('div', { className: 'alert alert-error' }, 'Previous analysis encountered an error.')); @@ -749,7 +762,20 @@ export function mountAnalysisView( .then((resp) => { if (destroyed) return; if (resp.kind === 'active') { - loadError = 'This game is still in progress. Watch it live first!'; + if (!resp.game.finished) { + loadError = 'This game is still in progress. Watch it live first!'; + updateAll(); + return; + } + unsavedAborted = true; + initialFen = resp.game.initialFen; + mainUci = resp.game.movesUci.slice(); + mainSan = resp.game.movesSan.slice(); + mainPly = mainUci.length; + rebuildMainFens(); + renderHeader(); + renderAnalysisControl(); + renderPgnPanel(); updateAll(); return; } diff --git a/src/client/views/profileView.ts b/src/client/views/profileView.ts index 3c00eee..111d067 100644 --- a/src/client/views/profileView.ts +++ b/src/client/views/profileView.ts @@ -363,14 +363,15 @@ export function mountProfileView(container: HTMLElement, ctx: AppContext, userna if (games.length === 0) { histBody.appendChild(el('div', { className: 'empty-state' }, 'No games match the current filters.')); } else { - const table = el('table', { className: 'data-table' }); + const tableWrap = el('div', { className: 'table-scroll-wrap' }); + const table = el('table', { className: 'data-table profile-games-table' }); const thead = el('thead'); const hr = el('tr'); hr.appendChild(el('th', null, 'Players')); - hr.appendChild(el('th', null, 'Time')); + hr.appendChild(el('th', { className: 'col-time' }, 'Time')); hr.appendChild(el('th', null, 'Result')); - hr.appendChild(el('th', null, 'Date')); - hr.appendChild(el('th', { className: 'col-right' }, 'Open')); + hr.appendChild(el('th', { className: 'col-date' }, 'Date')); + hr.appendChild(el('th', { className: 'col-right col-actions' }, 'Open')); thead.appendChild(hr); table.appendChild(thead); @@ -385,22 +386,31 @@ export function mountProfileView(container: HTMLElement, ctx: AppContext, userna ? 'win' : 'loss'; - const playersTd = el('td'); + const playersTd = el('td', { className: 'col-players' }); playersTd.appendChild( el( 'div', - null, + { className: 'game-players-text' }, `${g.whiteUsername}${g.whiteRatingBefore ? ` (${g.whiteRatingBefore})` : ''} vs ${ g.blackUsername }${g.blackRatingBefore ? ` (${g.blackRatingBefore})` : ''}` ) ); + playersTd.appendChild( + el( + 'div', + { className: 'mobile-game-meta small-text muted' }, + `${formatTimeControl(g.initialMs, g.incrementMs)} · ${ + g.botLevel ? 'Bot' : g.rated ? 'Rated' : 'Casual' + } · ${formatRelativeDate(g.endedAt)}` + ) + ); tr.appendChild(playersTd); tr.appendChild( el( 'td', - null, + { className: 'col-time' }, `${formatTimeControl(g.initialMs, g.incrementMs)} · ${g.botLevel ? 'Bot' : g.rated ? 'Rated' : 'Casual'}` ) ); @@ -416,9 +426,9 @@ export function mountProfileView(container: HTMLElement, ctx: AppContext, userna resTd.appendChild(el('span', { className: 'small-text muted' }, ` ${g.termination}`)); tr.appendChild(resTd); - tr.appendChild(el('td', { className: 'small-text muted' }, formatRelativeDate(g.endedAt))); + tr.appendChild(el('td', { className: 'small-text muted col-date' }, formatRelativeDate(g.endedAt))); - const actTd = el('td', { className: 'col-right' }); + const actTd = el('td', { className: 'col-right col-actions' }); const viewBtn = el('button', { type: 'button', className: 'btn btn-xs' }, 'View'); const analyzeBtn = el('button', { type: 'button', className: 'btn btn-xs btn-primary' }, 'Analyze'); viewBtn.addEventListener('click', () => ctx.navigate(`/game/${g.id}`)); @@ -430,7 +440,8 @@ export function mountProfileView(container: HTMLElement, ctx: AppContext, userna tbody.appendChild(tr); } table.appendChild(tbody); - histBody.appendChild(table); + tableWrap.appendChild(table); + histBody.appendChild(tableWrap); } const totalPages = Math.max(1, Math.ceil(totalGames / limit)); diff --git a/src/server/httpApi.ts b/src/server/httpApi.ts index a7aae50..565705e 100644 --- a/src/server/httpApi.ts +++ b/src/server/httpApi.ts @@ -578,17 +578,21 @@ export function createHttpHandler(deps: { if (gameId && !segments[2] && method === 'GET') { const active = gameManager.getGameState(gameId); - if (active) { + if (active && !active.finished) { sendJson(res, 200, { kind: 'active', game: active }); return; } const stored = db.getGameById(gameId); - if (!stored) { - sendJson(res, 404, { error: 'Game not found.' }); + if (stored) { + const analysis = db.getAnalysis(gameId); + sendJson(res, 200, { kind: 'stored', game: stored, analysis }); return; } - const analysis = db.getAnalysis(gameId); - sendJson(res, 200, { kind: 'stored', game: stored, analysis }); + if (active) { + sendJson(res, 200, { kind: 'active', game: active }); + return; + } + sendJson(res, 404, { error: 'Game not found.' }); return; } } diff --git a/tests/server.test.ts b/tests/server.test.ts index a41449f..8d4fd83 100644 --- a/tests/server.test.ts +++ b/tests/server.test.ts @@ -259,6 +259,7 @@ test('ChessUp full server E2E: auth, lobby, PvP, Glicko-2, Stockfish analysis, b // Check REST history, PGN, leaderboard const storedRes = await alice.req<{ kind: string; game: { result: string } }>(`/api/games/${pvpGameId}`); assert.equal(storedRes.status, 200); + assert.equal(storedRes.data.kind, 'stored'); assert.equal(storedRes.data.game.result, '1-0'); const pgnRes = await alice.req(`/api/games/${pvpGameId}/pgn`);