Press n or j to go to the next uncovered block, b, p or k for the previous block.
| 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 226 227 228 229 230 231 232 233 234 235 236 237 238 239 240 241 242 243 244 245 246 247 248 249 250 251 252 253 254 255 256 257 258 259 260 261 262 263 264 265 266 267 268 269 270 271 272 273 274 275 276 277 278 279 280 281 282 283 284 285 286 287 288 289 290 291 292 293 294 295 296 297 298 299 300 301 302 303 304 305 306 307 308 309 310 311 312 313 314 315 316 317 318 319 320 321 322 323 324 325 326 327 328 329 330 331 332 333 334 335 336 337 338 339 340 341 342 343 344 345 346 347 348 349 350 351 352 353 354 355 356 357 358 359 360 361 362 363 364 365 366 367 368 369 370 371 372 373 374 375 376 377 378 379 380 381 382 383 384 385 386 387 388 389 390 391 392 393 394 395 396 397 398 399 400 401 402 403 404 405 406 407 408 409 410 411 412 413 414 415 416 417 418 419 420 421 422 423 424 425 426 427 428 429 430 431 432 433 434 435 436 437 438 439 440 441 442 443 444 445 446 447 448 449 450 451 452 453 454 455 456 457 458 459 460 461 462 463 464 465 466 467 468 469 470 471 472 473 474 475 476 477 478 479 480 481 482 483 484 485 486 487 488 489 490 491 492 493 494 495 496 497 498 499 500 501 502 503 504 505 506 507 508 509 510 511 512 513 514 515 516 517 518 519 520 521 522 523 524 525 526 527 528 529 530 531 532 533 534 535 536 537 538 539 540 541 542 543 544 545 546 547 548 549 550 551 552 553 554 555 556 557 558 559 560 561 562 563 564 565 566 567 568 569 570 571 572 573 574 575 576 577 578 579 580 581 582 583 584 585 586 587 588 589 590 591 592 593 594 595 596 597 598 599 600 601 602 603 604 605 606 607 608 609 610 611 612 613 614 615 616 617 618 619 620 621 622 623 624 | 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 12x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 22x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 6x 4x 4x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 25x 25x 25x 25x 25x 25x 25x 25x 25x 25x 25x 25x 25x 25x 25x 25x 25x 24x 24x 24x 24x 24x 25x 25x 153x 153x 25x 25x 25x 25x 25x 25x 25x 25x 25x 25x 25x 24x 25x 25x 25x 25x 103x 103x 22x 22x 103x 1x 1x 1x 21x 21x 21x 21x 3x 25x 25x 25x 25x 25x 25x 25x 25x 25x 25x 147x 81x 81x 147x 147x 147x 147x 25x 25x 25x 3x 25x 25x 25x 25x 25x 25x 25x 25x 25x 25x 6x 6x 6x 6x 6x 25x 25x 1x 1x 1x 25x 25x 25x 25x 25x 25x 25x 25x 25x 25x 25x 25x 25x 25x 25x 25x 25x 25x 25x 25x 25x 25x 25x 25x 25x 25x 25x 25x 25x 52x 52x 52x 52x 52x 52x 52x 52x 5x 10x 5x 52x 44x 44x 52x 52x 52x 52x 52x 52x 52x 52x 52x 52x 52x 25x 25x 25x 25x 25x 25x 25x 25x 1x 1x 1x 1x 1x 24x 25x 25x 25x 25x 25x 25x 25x 25x 25x 25x 25x 25x 25x 25x 25x 25x 25x 25x 25x 25x 25x 25x 1x 1x | <template>
<section class="golden-boot">
<header class="gb-header">
<h3 class="gb-title">
Golden Boot
<span class="gb-beta-tag" data-testid="gb-beta-tag">Beta</span>
</h3>
<!-- Rendered only once the options exist. A <select> whose v-model is set
before its v-for options have arrived keeps displaying the option that
was there first, so the control would read "All" while the model — and
the request — said League. -->
<div v-if="filtersReady" class="gb-filters">
<select
v-model="selectedSeasonId"
class="gb-filter"
aria-label="Season"
>
<option v-for="s in seasons" :key="s.id" :value="s.id">
{{ s.name }}
</option>
</select>
<select
v-model="selectedMatchTypeId"
class="gb-filter"
aria-label="Competition"
>
<option v-for="t in matchTypes" :key="t.id" :value="t.id">
{{ t.name }}
</option>
<option v-if="leagueFlexIds" :value="LEAGUE_FLEX">
League + Flex
</option>
<option value="all">All</option>
</select>
</div>
</header>
<div v-if="loading" class="gb-state">Loading season stats...</div>
<div v-else-if="error" class="gb-state gb-state-error">{{ error }}</div>
<!-- Absent is not zero (CLAUDE.md: "Most Teams Have No User Data"). An empty
table would read as "nobody scored"; this says nothing has been logged. -->
<div v-else-if="nothingLogged" class="gb-state gb-state-empty">
<p class="gb-empty-title">Nothing recorded for this squad yet</p>
<p class="gb-empty-hint">
Appearances, goals and assists appear here once matches are scored in
the app. Results from the league feed do not include who played or who
scored.
</p>
</div>
<table v-else class="gb-table">
<thead>
<tr>
<th scope="col" class="gb-rank-col">#</th>
<th scope="col" class="gb-player-col">Player</th>
<th
v-for="col in statColumns"
:key="col.key"
scope="col"
class="gb-stat-col"
:class="{ 'gb-col-active': sortKey === col.key }"
:aria-sort="sortKey === col.key ? 'descending' : 'none'"
>
<button
type="button"
class="gb-sort-button"
:aria-label="`Sort by ${col.label}`"
@click="sortBy(col.key)"
>
{{ col.short }}
</button>
</th>
</tr>
</thead>
<tbody>
<tr v-for="(row, index) in rows" :key="row.player_id" class="gb-row">
<td class="gb-rank-col" :class="medalClass(index)">
{{ index + 1 }}
</td>
<td class="gb-player-col">
<span class="gb-jersey">#{{ row.jersey_number }}</span>
<span class="gb-name">{{ playerName(row) }}</span>
</td>
<td
v-for="col in statColumns"
:key="col.key"
class="gb-stat-col"
:class="{ 'gb-col-active': sortKey === col.key }"
>
{{ row[col.field] }}
</td>
</tr>
</tbody>
</table>
<p
v-if="!loading && !error && !nothingLogged"
class="gb-beta-note"
data-testid="gb-beta-note"
>
Beta: these stats come from club and team managers live scoring matches,
so mistakes happen. Fans and players, spot something wrong? Help us fix
it:
<SupportEmailLink
subject="Golden Boot correction"
:body="`Team ID: ${teamId}\nPlayer, match, and what should change:`"
display-text="contact support"
/>
</p>
</section>
</template>
<script>
import { ref, computed, onMounted, watch } from 'vue';
import { useAuthStore } from '@/stores/auth';
import { getApiBaseUrl } from '@/config/api';
import SupportEmailLink from '@/components/SupportEmailLink.vue';
// Minutes are deliberately absent. They are recorded, but a substitution nobody
// logged silently understates a player, and a column that is quietly wrong is
// worse than a column that is missing. Everything here is either counted from
// an event (G, A, YC, RC) or from an appearance record (GP, GS).
const STAT_COLUMNS = [
{ key: 'gp', short: 'GP', label: 'games played', field: 'games_played' },
{ key: 'gs', short: 'GS', label: 'games started', field: 'games_started' },
{ key: 'goals', short: 'G', label: 'goals', field: 'total_goals' },
{ key: 'assists', short: 'A', label: 'assists', field: 'total_assists' },
{
key: 'yc',
short: 'YC',
label: 'yellow cards',
field: 'total_yellow_cards',
},
{ key: 'rc', short: 'RC', label: 'red cards', field: 'total_red_cards' },
];
// The "every competition" choice. A sentinel, not null, so the <select> and the
// model cannot disagree about which option is selected.
const ALL_COMPETITIONS = 'all';
// League and Flex totalled (SB-1599). Homegrown teams play both, and Flex is a
// child league of Homegrown, so for them one without the other is half a season.
const LEAGUE_FLEX = 'league-flex';
// A team names its home league directly, and each mapping names its division's
// league, so a team registered in Homegrown is found either way.
const playsHomegrown = team =>
team?.league_name === 'Homegrown' ||
(team?.team_mappings || []).some(
m => m?.divisions?.leagues?.name === 'Homegrown'
);
const FIELD_BY_KEY = Object.fromEntries(
STAT_COLUMNS.map(c => [c.key, c.field])
);
export default {
name: 'GoldenBoot',
components: { SupportEmailLink },
props: {
teamId: { type: [Number, String], required: true },
// The default competition depends on the whole club, not this squad.
clubId: { type: [Number, String], default: null },
},
setup(props) {
const authStore = useAuthStore();
const loading = ref(true);
const error = ref(null);
const stats = ref([]);
const sortKey = ref('goals');
const seasons = ref([]);
const matchTypes = ref([]);
const selectedSeasonId = ref(null);
// 'all' rather than null: a null-valued <option> carries no value attribute,
// so the browser falls back to its label and the select reports "All" no
// matter which entry Vue marked selected. An explicit sentinel keeps the DOM
// and the model agreeing.
const selectedMatchTypeId = ref(ALL_COMPETITIONS);
const filtersReady = ref(false);
const statColumns = STAT_COLUMNS;
// [leagueId, flexId], or null when either type is not configured.
const leagueFlexIds = computed(() => {
const idOf = name =>
matchTypes.value.find(t => (t.name || '').toLowerCase() === name)?.id;
const league = idOf('league');
const flex = idOf('flex');
return league != null && flex != null ? [league, flex] : null;
});
const playerName = row => {
const name = `${row.first_name || ''} ${row.last_name || ''}`.trim();
return name || `#${row.jersey_number}`;
};
// Everyone who took part, not only scorers. An appearance is a
// contribution, so a player with games and no goals belongs here — while a
// squad member who has not played a minute does not, since a row of zeroes
// says something untrue about them (SB-670).
//
// A recorded goal, assist or card also counts as taking part. It ought to
// imply an appearance and normally does, but the appearance flags and the
// event counters are written by different paths, and a scorer missing from
// the scorers table would be a worse bug than one surplus row.
const played = computed(() =>
stats.value.filter(p => STAT_COLUMNS.some(col => (p[col.field] || 0) > 0))
);
const rows = computed(() => {
const primary = FIELD_BY_KEY[sortKey.value] || 'total_goals';
return [...played.value].sort((a, b) => {
const byPrimary = (b[primary] || 0) - (a[primary] || 0);
if (byPrimary !== 0) return byPrimary;
// Goals then assists break the tie before a name does, so two players
// level on the sorted column are separated by something they earned.
if (primary !== 'total_goals') {
const byGoals = (b.total_goals || 0) - (a.total_goals || 0);
if (byGoals !== 0) return byGoals;
}
if (primary !== 'total_assists') {
const byAssists = (b.total_assists || 0) - (a.total_assists || 0);
if (byAssists !== 0) return byAssists;
}
return playerName(a).localeCompare(playerName(b));
});
});
// Nobody took part in anything that was recorded. Distinct from "everyone
// scored zero": one is a season nobody logged, the other a season nobody
// scored in, and rendering the first as a table of zeroes is the
// absent-as-zero pun the CLAUDE.md rule forbids.
const nothingLogged = computed(() => !played.value.length);
// Rank and medal follow the column being sorted, so the tint always marks
// the leaders in what the reader is currently looking at.
const medalClass = index => {
if (index > 2) return '';
// No medals for leading on nothing — sorted by goals on a team that has
// not scored, the top three would otherwise be tinted for zero.
const primary = FIELD_BY_KEY[sortKey.value] || 'total_goals';
if (!(rows.value[0]?.[primary] || 0)) return '';
if (index === 0) return 'gb-medal-gold';
if (index === 1) return 'gb-medal-silver';
return 'gb-medal-bronze';
};
const sortBy = key => {
sortKey.value = key;
};
// Defaults: current season, league games only. A leaderboard that silently
// folds friendlies and tournaments into one total is not comparable with the
// league table beside it, so "All" has to be asked for. A club with a team
// in Homegrown opens on League + Flex instead (SB-1599).
//
// A failed club lookup only costs that default, so it must not fail the
// board: the club endpoint also answers 404 for a club with no teams.
const fetchClubIsHomegrown = async () => {
if (!props.clubId) return false;
try {
const teams = await authStore.apiRequest(
`${getApiBaseUrl()}/api/clubs/${props.clubId}/teams`,
{ method: 'GET' }
);
return Array.isArray(teams) && teams.some(playsHomegrown);
} catch (err) {
console.error('Error loading club teams for Golden Boot:', err);
return false;
}
};
const loadFilters = async () => {
const [seasonList, typeList, clubIsHomegrown] = await Promise.all([
authStore.apiRequest(`${getApiBaseUrl()}/api/seasons`, {
method: 'GET',
}),
authStore.apiRequest(`${getApiBaseUrl()}/api/match-types`, {
method: 'GET',
}),
fetchClubIsHomegrown(),
]);
seasons.value = seasonList || [];
matchTypes.value = typeList || [];
const currentSeason =
seasons.value.find(s => s.is_current) || seasons.value[0];
selectedSeasonId.value = currentSeason?.id ?? null;
const league = matchTypes.value.find(
t => (t.name || '').toLowerCase() === 'league'
);
// No league type configured is not an error — fall back to every
// competition rather than rendering an empty board.
selectedMatchTypeId.value =
clubIsHomegrown && leagueFlexIds.value
? LEAGUE_FLEX
: (league?.id ?? ALL_COMPETITIONS);
filtersReady.value = true;
return !!currentSeason;
};
const fetchStats = async () => {
if (!props.teamId || !filtersReady.value || !selectedSeasonId.value) {
return;
}
loading.value = true;
error.value = null;
try {
const params = new URLSearchParams({
season_id: String(selectedSeasonId.value),
});
if (selectedMatchTypeId.value === LEAGUE_FLEX) {
leagueFlexIds.value.forEach(id =>
params.append('match_type_id', String(id))
);
} else if (selectedMatchTypeId.value !== ALL_COMPETITIONS) {
params.set('match_type_id', String(selectedMatchTypeId.value));
}
const response = await authStore.apiRequest(
`${getApiBaseUrl()}/api/teams/${props.teamId}/stats?${params}`,
{ method: 'GET' }
);
stats.value = Array.isArray(response)
? response
: response?.players || [];
} catch (err) {
console.error('Error loading team stats:', err);
error.value = 'Could not load season stats';
} finally {
loading.value = false;
}
};
const init = async () => {
loading.value = true;
error.value = null;
try {
const hasSeason = await loadFilters();
if (!hasSeason) {
error.value = 'No season configured';
loading.value = false;
return;
}
} catch (err) {
console.error('Error loading stat filters:', err);
error.value = 'Could not load season stats';
loading.value = false;
return;
}
await fetchStats();
};
onMounted(init);
watch(() => props.teamId, fetchStats);
watch([selectedSeasonId, selectedMatchTypeId], fetchStats);
return {
loading,
error,
rows,
nothingLogged,
filtersReady,
seasons,
matchTypes,
selectedSeasonId,
selectedMatchTypeId,
leagueFlexIds,
LEAGUE_FLEX,
sortKey,
statColumns,
playerName,
medalClass,
sortBy,
};
},
};
</script>
<style scoped>
.golden-boot {
margin-top: 24px;
}
.gb-header {
display: flex;
align-items: baseline;
justify-content: space-between;
flex-wrap: wrap;
gap: 8px;
margin-bottom: 8px;
}
.gb-title {
font-size: 1.1rem;
font-weight: 700;
margin: 0;
color: rgb(var(--color-fg));
}
.gb-filters {
display: flex;
gap: 8px;
}
.gb-filter {
font-size: 0.8rem;
color: rgb(var(--color-fg));
background: rgb(var(--color-card));
border: 1px solid rgb(var(--color-line));
border-radius: 6px;
padding: 3px 6px;
cursor: pointer;
}
.gb-filter:hover {
border-color: rgb(var(--color-fg-muted));
}
.gb-state {
padding: 16px;
font-size: 0.9rem;
color: rgb(var(--color-fg-muted));
background: rgb(var(--color-surface-alt));
border-radius: 8px;
}
.gb-state-error {
color: #b91c1c;
background: rgb(185 28 28 / 0.1);
}
:global(.dark) .gb-state-error {
color: #fca5a5;
}
.gb-empty-title {
margin: 0 0 4px;
font-weight: 600;
color: rgb(var(--color-fg));
}
.gb-empty-hint {
margin: 0;
font-size: 0.82rem;
line-height: 1.4;
}
.gb-table {
width: 100%;
border-collapse: collapse;
font-size: 0.9rem;
}
.gb-table thead th {
padding: 8px 10px;
border-bottom: 2px solid rgb(var(--color-line));
font-size: 0.72rem;
font-weight: 600;
text-transform: uppercase;
letter-spacing: 0.04em;
color: rgb(var(--color-fg-muted));
text-align: left;
}
.gb-row td {
padding: 9px 10px;
border-bottom: 1px solid rgb(var(--color-line));
color: rgb(var(--color-fg));
}
.gb-row:hover td {
background: rgb(var(--color-surface-alt));
}
.gb-rank-col {
width: 42px;
text-align: center;
color: rgb(var(--color-fg-muted));
font-variant-numeric: tabular-nums;
}
.gb-player-col {
text-align: left;
}
.gb-jersey {
display: inline-block;
min-width: 30px;
color: rgb(var(--color-fg-muted));
font-variant-numeric: tabular-nums;
}
.gb-name {
font-weight: 500;
}
.gb-stat-col {
width: 44px;
text-align: center;
font-variant-numeric: tabular-nums;
}
/* A zero is a real measurement here, not a gap — but it should not compete with
the numbers that carry the story. */
.gb-row td.gb-stat-col {
color: rgb(var(--color-fg-muted));
}
.gb-table thead th.gb-stat-col {
text-align: center;
}
.gb-sort-button {
background: none;
border: none;
padding: 0;
font: inherit;
color: inherit;
text-transform: inherit;
letter-spacing: inherit;
cursor: pointer;
}
/* Same amber as the nav's Beta badge. Fixed colours: the tint stays light in both
themes, so the text on it stays dark. */
.gb-beta-tag {
display: inline-block;
margin-left: 4px;
padding: 1px 6px;
font-size: 0.625rem;
font-weight: 700;
text-transform: uppercase;
letter-spacing: 0.04em;
vertical-align: middle;
color: #92400e;
background-color: #fef3c7;
border-radius: 9999px;
}
.gb-beta-note {
margin: 10px 0 0;
font-size: 0.78rem;
line-height: 1.4;
color: rgb(var(--color-fg-muted));
}
.gb-sort-button:hover {
color: rgb(var(--color-fg));
}
/* Active sort column: shaded body cells and an accent rule under the header,
the way a league stats table marks what it is ordered by. */
.gb-table thead th.gb-col-active {
color: #b91c1c;
box-shadow: inset 0 -2px 0 0 #b91c1c;
}
:global(.dark) .gb-table thead th.gb-col-active {
color: #f87171;
box-shadow: inset 0 -2px 0 0 #f87171;
}
.gb-row td.gb-col-active {
background: rgb(var(--color-surface-alt));
color: rgb(var(--color-fg));
font-weight: 700;
}
.gb-row:hover td.gb-col-active {
background: rgb(var(--color-line));
}
/* The tints stay light in both themes, so the text on them stays dark. Needs
.gb-row td specificity, or the themed row colour lands on the tint. */
.gb-row td.gb-medal-gold,
.gb-row td.gb-medal-silver,
.gb-row td.gb-medal-bronze {
font-weight: 700;
color: #78350f;
border-radius: 4px;
}
.gb-row td.gb-medal-gold {
background: #fde68a;
}
.gb-row td.gb-medal-silver {
background: #e5e7eb;
color: #374151;
}
.gb-row td.gb-medal-bronze {
background: #f5d0a9;
}
@media (max-width: 480px) {
.gb-table {
font-size: 0.85rem;
}
.gb-row td,
.gb-table thead th {
padding: 8px 6px;
}
.gb-stat-col {
width: 34px;
}
.gb-jersey {
min-width: 26px;
}
}
</style>
|