feat: refactor leaderboard display to use tables for better structure and readability

This commit is contained in:
2026-03-01 01:08:16 +00:00
parent 263670dcae
commit e915ba4919

View File

@@ -57,131 +57,109 @@
<!-- Top Players --> <!-- Top Players -->
{#if activeTab === 'players'} {#if activeTab === 'players'}
<div class="mt-6 rounded-lg border border-border bg-surface-800"> <div class="mt-6 overflow-x-auto rounded-lg border border-border bg-surface-800">
{#if data.topPlayers.length === 0} {#if data.topPlayers.length === 0}
<div class="py-12 text-center"> <div class="py-12 text-center">
<p class="text-sm text-text-secondary">No ranked players yet. Play some matches!</p> <p class="text-sm text-text-secondary">No ranked players yet. Play some matches!</p>
</div> </div>
{:else} {:else}
<div <table class="w-full">
class="grid grid-cols-[auto_auto_1fr_auto_auto_auto] gap-4 border-b border-border px-4 py-3" <thead>
> <tr class="border-b border-border text-left text-xs font-600 text-text-secondary">
<span class="text-xs font-600 text-text-secondary">#</span> <th class="w-10 py-3 pl-4 text-center">#</th>
<span class="text-xs font-600 text-text-secondary"></span> <th class="w-10 py-3"></th>
<span class="text-xs font-600 text-text-secondary">Player</span> <th class="py-3">Player</th>
<span class="text-xs font-600 text-text-secondary">ELO</span> <th class="w-16 py-3 pr-4 text-right">ELO</th>
<span class="text-xs font-600 text-text-secondary">W/L</span> <th class="w-16 py-3 pr-4 text-right">W/L</th>
<span class="text-xs font-600 text-text-secondary">Win %</span> <th class="w-16 py-3 pr-4 text-right">Win %</th>
</div> </tr>
</thead>
{#each data.topPlayers as p} <tbody>
{@const medal = rankBadge(p.rank)} {#each data.topPlayers as p}
<div {@const medal = rankBadge(p.rank)}
class="grid grid-cols-[auto_auto_1fr_auto_auto_auto] items-center gap-4 border-b border-border/50 px-4 py-3 last:border-b-0 {p.rank <= <tr class="border-b border-border/50 last:border-b-0 {p.rank <= 3 ? 'bg-accent/[0.02]' : ''}">
3 <td class="py-3 pl-4 text-center text-sm font-700 tabular-nums {medal?.color ?? 'text-text-secondary'}">
? 'bg-accent/[0.02]' {medal ? medal.emoji : p.rank}
: ''}" </td>
> <td class="py-3">
<!-- Rank --> {#if p.image}
<span class="w-6 text-center text-sm font-700 tabular-nums {medal?.color ?? 'text-text-secondary'}"> <img src={p.image} alt="" class="h-8 w-8 rounded-full" />
{medal ? medal.emoji : p.rank} {:else}
</span> <div class="flex h-8 w-8 items-center justify-center rounded-full bg-surface-600 text-xs font-700 text-text-secondary">
{p.name.charAt(0).toUpperCase()}
<!-- Avatar --> </div>
{#if p.image} {/if}
<img src={p.image} alt="" class="h-8 w-8 rounded-full" /> </td>
{:else} <td class="py-3 text-sm font-600">{p.name}</td>
<div <td class="py-3 pr-4 text-right text-sm font-700 tabular-nums {eloColor(p.elo)}">{p.elo}</td>
class="flex h-8 w-8 items-center justify-center rounded-full bg-surface-600 text-xs font-700 text-text-secondary" <td class="py-3 pr-4 text-right text-xs tabular-nums text-text-secondary">
> <span class="text-green-400">{p.wins}</span>/<span class="text-red-400">{p.losses}</span>
{p.name.charAt(0).toUpperCase()} </td>
</div> <td class="py-3 pr-4 text-right text-xs font-600 tabular-nums {p.winRate !== '—' && parseFloat(p.winRate) >= 50 ? 'text-green-400' : 'text-text-secondary'}">
{/if} {p.winRate}{p.winRate !== '—' ? '%' : ''}
</td>
<!-- Name --> </tr>
<span class="truncate text-sm font-600">{p.name}</span> {/each}
</tbody>
<!-- ELO --> </table>
<span class="text-sm font-700 tabular-nums {eloColor(p.elo)}">{p.elo}</span>
<!-- W/L -->
<span class="text-xs tabular-nums text-text-secondary">
<span class="text-green-400">{p.wins}</span>/<span class="text-red-400">{p.losses}</span>
</span>
<!-- Win Rate -->
<span class="text-xs font-600 tabular-nums {p.winRate !== '—' && parseFloat(p.winRate) >= 50 ? 'text-green-400' : 'text-text-secondary'}">
{p.winRate}{p.winRate !== '—' ? '%' : ''}
</span>
</div>
{/each}
{/if} {/if}
</div> </div>
{/if} {/if}
<!-- Top Teams --> <!-- Top Teams -->
{#if activeTab === 'teams'} {#if activeTab === 'teams'}
<div class="mt-6 rounded-lg border border-border bg-surface-800"> <div class="mt-6 overflow-x-auto rounded-lg border border-border bg-surface-800">
{#if data.topTeams.length === 0} {#if data.topTeams.length === 0}
<div class="py-12 text-center"> <div class="py-12 text-center">
<p class="text-sm text-text-secondary">No team results yet.</p> <p class="text-sm text-text-secondary">No team results yet.</p>
</div> </div>
{:else} {:else}
<div class="grid grid-cols-[auto_auto_1fr_auto_auto] gap-4 border-b border-border px-4 py-3"> <table class="w-full">
<span class="text-xs font-600 text-text-secondary">#</span> <thead>
<span class="text-xs font-600 text-text-secondary"></span> <tr class="border-b border-border text-left text-xs font-600 text-text-secondary">
<span class="text-xs font-600 text-text-secondary">Team</span> <th class="w-10 py-3 pl-4 text-center">#</th>
<span class="text-xs font-600 text-text-secondary">Wins</span> <th class="w-10 py-3"></th>
<span class="text-xs font-600 text-text-secondary">Matches</span> <th class="py-3">Team</th>
</div> <th class="w-16 py-3 pr-4 text-right">Wins</th>
<th class="w-20 py-3 pr-4 text-right">Matches</th>
{#each data.topTeams as t} </tr>
{@const medal = rankBadge(t.rank)} </thead>
<div <tbody>
class="grid grid-cols-[auto_auto_1fr_auto_auto] items-center gap-4 border-b border-border/50 px-4 py-3 last:border-b-0 {t.rank <= {#each data.topTeams as t}
3 {@const medal = rankBadge(t.rank)}
? 'bg-accent/[0.02]' <tr class="border-b border-border/50 last:border-b-0 {t.rank <= 3 ? 'bg-accent/[0.02]' : ''}">
: ''}" <td class="py-3 pl-4 text-center text-sm font-700 tabular-nums {medal?.color ?? 'text-text-secondary'}">
> {medal ? medal.emoji : t.rank}
<!-- Rank --> </td>
<span class="w-6 text-center text-sm font-700 tabular-nums {medal?.color ?? 'text-text-secondary'}"> <td class="py-3">
{medal ? medal.emoji : t.rank} {#if t.avatarUrl}
</span> <img src={t.avatarUrl} alt="" class="h-8 w-8 rounded-full" />
{:else}
<!-- Avatar --> <div class="flex h-8 w-8 items-center justify-center rounded-full bg-surface-600 text-xs font-700 text-text-secondary">
{#if t.avatarUrl} {t.name.charAt(0).toUpperCase()}
<img src={t.avatarUrl} alt="" class="h-8 w-8 rounded-full" /> </div>
{:else} {/if}
<div </td>
class="flex h-8 w-8 items-center justify-center rounded-full bg-surface-600 text-xs font-700 text-text-secondary" <td class="py-3">
> <span class="text-sm font-600">{t.name}</span>
{t.name.charAt(0).toUpperCase()} {#if t.isPersonal}
</div> <span class="ml-1 text-[10px] text-text-secondary">(solo)</span>
{/if} {/if}
<p class="text-xs text-text-secondary">{t.memberCount} member{t.memberCount !== 1 ? 's' : ''}</p>
<!-- Name --> </td>
<div class="min-w-0"> <td class="py-3 pr-4 text-right text-sm font-700 tabular-nums text-green-400">{t.wins}</td>
<span class="truncate text-sm font-600">{t.name}</span> <td class="py-3 pr-4 text-right text-xs tabular-nums text-text-secondary">{t.totalMatches}</td>
{#if t.isPersonal} </tr>
<span class="ml-1 text-[10px] text-text-secondary">(solo)</span> {/each}
{/if} </tbody>
<p class="text-xs text-text-secondary">{t.memberCount} member{t.memberCount !== 1 ? 's' : ''}</p> </table>
</div>
<!-- Wins -->
<span class="text-sm font-700 tabular-nums text-green-400">{t.wins}</span>
<!-- Total Matches -->
<span class="text-xs tabular-nums text-text-secondary">{t.totalMatches}</span>
</div>
{/each}
{/if} {/if}
</div> </div>
{/if} {/if}
<!-- High Scores --> <!-- High Scores -->
{#if activeTab === 'scores'} {#if activeTab === 'scores'}
<div class="mt-6 rounded-lg border border-border bg-surface-800"> <div class="mt-6 overflow-x-auto rounded-lg border border-border bg-surface-800">
{#if data.highScores.length === 0} {#if data.highScores.length === 0}
<div class="py-12 text-center"> <div class="py-12 text-center">
<p class="text-sm text-text-secondary">No scores recorded yet.</p> <p class="text-sm text-text-secondary">No scores recorded yet.</p>
@@ -190,71 +168,56 @@
<div class="px-4 py-2.5 border-b border-border"> <div class="px-4 py-2.5 border-b border-border">
<p class="text-xs text-text-secondary">Ranked by pp (performance points) when available, then score</p> <p class="text-xs text-text-secondary">Ranked by pp (performance points) when available, then score</p>
</div> </div>
<div <table class="w-full">
class="grid grid-cols-[auto_auto_1fr_auto_auto_auto_auto] gap-3 border-b border-border px-4 py-3" <thead>
> <tr class="border-b border-border text-left text-xs font-600 text-text-secondary">
<span class="text-xs font-600 text-text-secondary">#</span> <th class="w-10 py-3 pl-4 text-center">#</th>
<span class="text-xs font-600 text-text-secondary"></span> <th class="w-10 py-3"></th>
<span class="text-xs font-600 text-text-secondary">Player</span> <th class="py-3">Player</th>
<span class="text-xs font-600 text-text-secondary">Map</span> <th class="w-12 py-3 pr-4 text-right">Map</th>
<span class="text-xs font-600 text-accent">PP</span> <th class="w-16 py-3 pr-4 text-right text-accent">PP</th>
<span class="text-xs font-600 text-text-secondary">Score</span> <th class="w-24 py-3 pr-4 text-right">Score</th>
<span class="text-xs font-600 text-text-secondary">Acc</span> <th class="w-16 py-3 pr-4 text-right">Acc</th>
</div> </tr>
</thead>
{#each data.highScores as s} <tbody>
{@const medal = rankBadge(s.rank)} {#each data.highScores as s}
<div {@const medal = rankBadge(s.rank)}
class="grid grid-cols-[auto_auto_1fr_auto_auto_auto_auto] items-center gap-3 border-b border-border/50 px-4 py-3 last:border-b-0 {s.rank <= <tr class="border-b border-border/50 last:border-b-0 {s.rank <= 3 ? 'bg-accent/[0.02]' : ''}">
3 <td class="py-3 pl-4 text-center text-sm font-700 tabular-nums {medal?.color ?? 'text-text-secondary'}">
? 'bg-accent/[0.02]' {medal ? medal.emoji : s.rank}
: ''}" </td>
> <td class="py-3">
<!-- Rank --> {#if s.playerImage}
<span class="w-6 text-center text-sm font-700 tabular-nums {medal?.color ?? 'text-text-secondary'}"> <img src={s.playerImage} alt="" class="h-8 w-8 rounded-full" />
{medal ? medal.emoji : s.rank} {:else}
</span> <div class="flex h-8 w-8 items-center justify-center rounded-full bg-surface-600 text-xs font-700 text-text-secondary">
{s.playerName.charAt(0).toUpperCase()}
<!-- Avatar --> </div>
{#if s.playerImage} {/if}
<img src={s.playerImage} alt="" class="h-8 w-8 rounded-full" /> </td>
{:else} <td class="py-3">
<div <span class="text-sm font-600">{s.playerName}</span>
class="flex h-8 w-8 items-center justify-center rounded-full bg-surface-600 text-xs font-700 text-text-secondary" <p class="truncate text-xs text-text-secondary">
> <a href="/matches/{s.matchId}" class="hover:text-accent">{s.matchName}</a>
{s.playerName.charAt(0).toUpperCase()} </p>
</div> </td>
{/if} <td class="py-3 pr-4 text-right text-xs font-600 {catColors[s.mapCategory] ?? 'text-text-secondary'}">
{s.mapCategory}{s.mapOrder}
<!-- Player + match context --> </td>
<div class="min-w-0"> <td class="py-3 pr-4 text-right text-sm font-700 tabular-nums {s.pp != null ? 'text-accent' : 'text-text-secondary/40'}">
<span class="truncate text-sm font-600">{s.playerName}</span> {s.pp != null ? `${Math.round(s.pp)}pp` : '—'}
<p class="truncate text-xs text-text-secondary"> </td>
<a href="/matches/{s.matchId}" class="hover:text-accent">{s.matchName}</a> <td class="py-3 pr-4 text-right text-sm font-700 tabular-nums text-text-primary">
</p> {s.score.toLocaleString()}
</div> </td>
<td class="py-3 pr-4 text-right text-xs tabular-nums text-text-secondary">
<!-- Map slot --> {s.accuracy > 0 ? `${(s.accuracy * 100).toFixed(1)}%` : '—'}
<span class="text-xs font-600 {catColors[s.mapCategory] ?? 'text-text-secondary'}"> </td>
{s.mapCategory}{s.mapOrder} </tr>
</span> {/each}
</tbody>
<!-- PP --> </table>
<span class="text-sm font-700 tabular-nums {s.pp != null ? 'text-accent' : 'text-text-secondary/40'}">
{s.pp != null ? `${Math.round(s.pp)}pp` : '—'}
</span>
<!-- Score -->
<span class="text-sm font-700 tabular-nums text-text-primary">
{s.score.toLocaleString()}
</span>
<!-- Accuracy -->
<span class="text-xs tabular-nums text-text-secondary">
{s.accuracy > 0 ? `${(s.accuracy * 100).toFixed(1)}%` : '—'}
</span>
</div>
{/each}
{/if} {/if}
</div> </div>
{/if} {/if}