Fix post-game analysis state, add profile nav route, and fix mobile profile overflow
This commit is contained in:
parent
02b8bafb1e
commit
3ccab53b41
7 changed files with 158 additions and 23 deletions
|
|
@ -75,7 +75,14 @@ export class Navbar {
|
||||||
badge: state.friendBadgeCount > 0 ? state.friendBadgeCount : undefined,
|
badge: state.friendBadgeCount > 0 ? state.friendBadgeCount : undefined,
|
||||||
match: (p) => p.indexOf('/friends') === 0
|
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) {
|
for (const item of navItems) {
|
||||||
|
|
@ -129,7 +136,7 @@ export class Navbar {
|
||||||
if (state.user) {
|
if (state.user) {
|
||||||
const profileLink = el(
|
const profileLink = el(
|
||||||
'a',
|
'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
|
state.user.username
|
||||||
);
|
);
|
||||||
profileLink.addEventListener('click', (e) => {
|
profileLink.addEventListener('click', (e) => {
|
||||||
|
|
|
||||||
|
|
@ -150,6 +150,12 @@ class App {
|
||||||
this.activeView = mountFriendsView(this.mainEl, this.ctx);
|
this.activeView = mountFriendsView(this.mainEl, this.ctx);
|
||||||
} else if (pathname === '/leaderboard') {
|
} else if (pathname === '/leaderboard') {
|
||||||
this.activeView = mountLeaderboardView(this.mainEl, this.ctx);
|
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') {
|
} else if (pathname === '/analysis') {
|
||||||
this.activeView = mountAnalysisView(this.mainEl, this.ctx);
|
this.activeView = mountAnalysisView(this.mainEl, this.ctx);
|
||||||
} else if (pathname.indexOf('/analysis/') === 0) {
|
} else if (pathname.indexOf('/analysis/') === 0) {
|
||||||
|
|
|
||||||
|
|
@ -222,12 +222,15 @@ a {
|
||||||
|
|
||||||
.nav-user-link {
|
.nav-user-link {
|
||||||
font-weight: 600;
|
font-weight: 600;
|
||||||
font-size: 13px;
|
font-size: 12px;
|
||||||
padding: 4px 6px;
|
max-width: 140px;
|
||||||
|
overflow: hidden;
|
||||||
|
text-overflow: ellipsis;
|
||||||
|
white-space: nowrap;
|
||||||
}
|
}
|
||||||
|
|
||||||
.nav-user-link:hover {
|
.nav-user-link:hover {
|
||||||
text-decoration: underline;
|
border-color: var(--accent);
|
||||||
}
|
}
|
||||||
|
|
||||||
/* Main container */
|
/* Main container */
|
||||||
|
|
@ -756,8 +759,16 @@ a {
|
||||||
align-items: center;
|
align-items: center;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
.profile-id {
|
||||||
|
min-width: 0;
|
||||||
|
max-width: 100%;
|
||||||
|
overflow-wrap: break-word;
|
||||||
|
margin-bottom: 6px;
|
||||||
|
}
|
||||||
|
|
||||||
.profile-title-row {
|
.profile-title-row {
|
||||||
display: flex;
|
display: flex;
|
||||||
|
flex-wrap: wrap;
|
||||||
align-items: center;
|
align-items: center;
|
||||||
margin-bottom: 4px;
|
margin-bottom: 4px;
|
||||||
}
|
}
|
||||||
|
|
@ -765,6 +776,22 @@ a {
|
||||||
.profile-username {
|
.profile-username {
|
||||||
margin: 0 8px 0 0;
|
margin: 0 8px 0 0;
|
||||||
font-size: 20px;
|
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 {
|
.h2h-line {
|
||||||
|
|
@ -1650,8 +1677,33 @@ a {
|
||||||
}
|
}
|
||||||
|
|
||||||
.rating-card {
|
.rating-card {
|
||||||
width: 49%;
|
width: 48.5%;
|
||||||
margin-right: 1%;
|
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 {
|
.bot-level-card {
|
||||||
|
|
@ -1659,3 +1711,31 @@ a {
|
||||||
margin-right: 0;
|
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;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
|
||||||
|
|
@ -37,6 +37,7 @@ export function mountAnalysisView(
|
||||||
gameId?: string
|
gameId?: string
|
||||||
): ViewHandle {
|
): ViewHandle {
|
||||||
let storedGame: StoredGame | null = null;
|
let storedGame: StoredGame | null = null;
|
||||||
|
let unsavedAborted = false;
|
||||||
let report: GameAnalysisReport | null = null;
|
let report: GameAnalysisReport | null = null;
|
||||||
let loadError = '';
|
let loadError = '';
|
||||||
|
|
||||||
|
|
@ -463,6 +464,18 @@ export function mountAnalysisView(
|
||||||
);
|
);
|
||||||
const body = el('div', { className: 'card-body compact' });
|
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 || report.status === 'error') {
|
||||||
if (report?.status === 'error') {
|
if (report?.status === 'error') {
|
||||||
body.appendChild(el('div', { className: 'alert alert-error' }, 'Previous analysis encountered an error.'));
|
body.appendChild(el('div', { className: 'alert alert-error' }, 'Previous analysis encountered an error.'));
|
||||||
|
|
@ -749,7 +762,20 @@ export function mountAnalysisView(
|
||||||
.then((resp) => {
|
.then((resp) => {
|
||||||
if (destroyed) return;
|
if (destroyed) return;
|
||||||
if (resp.kind === 'active') {
|
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();
|
updateAll();
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
|
||||||
|
|
@ -363,14 +363,15 @@ export function mountProfileView(container: HTMLElement, ctx: AppContext, userna
|
||||||
if (games.length === 0) {
|
if (games.length === 0) {
|
||||||
histBody.appendChild(el('div', { className: 'empty-state' }, 'No games match the current filters.'));
|
histBody.appendChild(el('div', { className: 'empty-state' }, 'No games match the current filters.'));
|
||||||
} else {
|
} 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 thead = el('thead');
|
||||||
const hr = el('tr');
|
const hr = el('tr');
|
||||||
hr.appendChild(el('th', null, 'Players'));
|
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, 'Result'));
|
||||||
hr.appendChild(el('th', null, 'Date'));
|
hr.appendChild(el('th', { className: 'col-date' }, 'Date'));
|
||||||
hr.appendChild(el('th', { className: 'col-right' }, 'Open'));
|
hr.appendChild(el('th', { className: 'col-right col-actions' }, 'Open'));
|
||||||
thead.appendChild(hr);
|
thead.appendChild(hr);
|
||||||
table.appendChild(thead);
|
table.appendChild(thead);
|
||||||
|
|
||||||
|
|
@ -385,22 +386,31 @@ export function mountProfileView(container: HTMLElement, ctx: AppContext, userna
|
||||||
? 'win'
|
? 'win'
|
||||||
: 'loss';
|
: 'loss';
|
||||||
|
|
||||||
const playersTd = el('td');
|
const playersTd = el('td', { className: 'col-players' });
|
||||||
playersTd.appendChild(
|
playersTd.appendChild(
|
||||||
el(
|
el(
|
||||||
'div',
|
'div',
|
||||||
null,
|
{ className: 'game-players-text' },
|
||||||
`${g.whiteUsername}${g.whiteRatingBefore ? ` (${g.whiteRatingBefore})` : ''} vs ${
|
`${g.whiteUsername}${g.whiteRatingBefore ? ` (${g.whiteRatingBefore})` : ''} vs ${
|
||||||
g.blackUsername
|
g.blackUsername
|
||||||
}${g.blackRatingBefore ? ` (${g.blackRatingBefore})` : ''}`
|
}${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(playersTd);
|
||||||
|
|
||||||
tr.appendChild(
|
tr.appendChild(
|
||||||
el(
|
el(
|
||||||
'td',
|
'td',
|
||||||
null,
|
{ className: 'col-time' },
|
||||||
`${formatTimeControl(g.initialMs, g.incrementMs)} · ${g.botLevel ? 'Bot' : g.rated ? 'Rated' : 'Casual'}`
|
`${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}`));
|
resTd.appendChild(el('span', { className: 'small-text muted' }, ` ${g.termination}`));
|
||||||
tr.appendChild(resTd);
|
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 viewBtn = el('button', { type: 'button', className: 'btn btn-xs' }, 'View');
|
||||||
const analyzeBtn = el('button', { type: 'button', className: 'btn btn-xs btn-primary' }, 'Analyze');
|
const analyzeBtn = el('button', { type: 'button', className: 'btn btn-xs btn-primary' }, 'Analyze');
|
||||||
viewBtn.addEventListener('click', () => ctx.navigate(`/game/${g.id}`));
|
viewBtn.addEventListener('click', () => ctx.navigate(`/game/${g.id}`));
|
||||||
|
|
@ -430,7 +440,8 @@ export function mountProfileView(container: HTMLElement, ctx: AppContext, userna
|
||||||
tbody.appendChild(tr);
|
tbody.appendChild(tr);
|
||||||
}
|
}
|
||||||
table.appendChild(tbody);
|
table.appendChild(tbody);
|
||||||
histBody.appendChild(table);
|
tableWrap.appendChild(table);
|
||||||
|
histBody.appendChild(tableWrap);
|
||||||
}
|
}
|
||||||
|
|
||||||
const totalPages = Math.max(1, Math.ceil(totalGames / limit));
|
const totalPages = Math.max(1, Math.ceil(totalGames / limit));
|
||||||
|
|
|
||||||
|
|
@ -578,17 +578,21 @@ export function createHttpHandler(deps: {
|
||||||
|
|
||||||
if (gameId && !segments[2] && method === 'GET') {
|
if (gameId && !segments[2] && method === 'GET') {
|
||||||
const active = gameManager.getGameState(gameId);
|
const active = gameManager.getGameState(gameId);
|
||||||
if (active) {
|
if (active && !active.finished) {
|
||||||
sendJson(res, 200, { kind: 'active', game: active });
|
sendJson(res, 200, { kind: 'active', game: active });
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
const stored = db.getGameById(gameId);
|
const stored = db.getGameById(gameId);
|
||||||
if (!stored) {
|
if (stored) {
|
||||||
sendJson(res, 404, { error: 'Game not found.' });
|
const analysis = db.getAnalysis(gameId);
|
||||||
|
sendJson(res, 200, { kind: 'stored', game: stored, analysis });
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
const analysis = db.getAnalysis(gameId);
|
if (active) {
|
||||||
sendJson(res, 200, { kind: 'stored', game: stored, analysis });
|
sendJson(res, 200, { kind: 'active', game: active });
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
sendJson(res, 404, { error: 'Game not found.' });
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
||||||
|
|
@ -259,6 +259,7 @@ test('ChessUp full server E2E: auth, lobby, PvP, Glicko-2, Stockfish analysis, b
|
||||||
// Check REST history, PGN, leaderboard
|
// Check REST history, PGN, leaderboard
|
||||||
const storedRes = await alice.req<{ kind: string; game: { result: string } }>(`/api/games/${pvpGameId}`);
|
const storedRes = await alice.req<{ kind: string; game: { result: string } }>(`/api/games/${pvpGameId}`);
|
||||||
assert.equal(storedRes.status, 200);
|
assert.equal(storedRes.status, 200);
|
||||||
|
assert.equal(storedRes.data.kind, 'stored');
|
||||||
assert.equal(storedRes.data.game.result, '1-0');
|
assert.equal(storedRes.data.game.result, '1-0');
|
||||||
|
|
||||||
const pgnRes = await alice.req<string>(`/api/games/${pvpGameId}/pgn`);
|
const pgnRes = await alice.req<string>(`/api/games/${pvpGameId}/pgn`);
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue