Fix post-game analysis state, add profile nav route, and fix mobile profile overflow

This commit is contained in:
tyuXX 2026-11-22 20:10:16 +03:00
parent 02b8bafb1e
commit 3ccab53b41
7 changed files with 158 additions and 23 deletions

View file

@ -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) => {

View file

@ -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) {

View file

@ -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;
}
}

View file

@ -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,10 +762,23 @@ export function mountAnalysisView(
.then((resp) => {
if (destroyed) return;
if (resp.kind === 'active') {
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;
}
storedGame = resp.game;
report = resp.analysis;
initialFen = resp.game.initialFen;

View file

@ -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));

View file

@ -578,19 +578,23 @@ 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.' });
return;
}
if (stored) {
const analysis = db.getAnalysis(gameId);
sendJson(res, 200, { kind: 'stored', game: stored, analysis });
return;
}
if (active) {
sendJson(res, 200, { kind: 'active', game: active });
return;
}
sendJson(res, 404, { error: 'Game not found.' });
return;
}
}
sendJson(res, 404, { error: 'API route not found.' });

View file

@ -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<string>(`/api/games/${pvpGameId}/pgn`);