Fix battle-logs returning 0 results — replace SQB field names with TSS name field

bestTeamName and canonicalTeamName were checking tag_name/short_name/long_name
(SQB API fields) which don't exist on TSS team objects. Every team resolved to
an empty string so fetchRecentTssGames bailed out immediately with no matches.

Also clean up all other references to those dead fields throughout the component.

Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
This commit is contained in:
Liam
2026-06-15 06:28:17 +00:00
parent 65ad10ad11
commit 5cd95cf78f
+13 -18
View File
@@ -104,7 +104,7 @@ function formatDate(timestamp) {
}
function bestTeamName(team) {
return team?.tag_name || team?.short_name || team?.long_name || ''
return team?.name || ''
}
function teamDetailLooksReal(detail) {
@@ -125,7 +125,7 @@ function teamDetailLooksReal(detail) {
}
function canonicalTeamName(detail, fallback = '') {
return detail?.tag_name || detail?.short_name || detail?.long_name || fallback
return detail?.name || fallback
}
function normalizeAnalyticsPreferences(value) {
@@ -564,8 +564,7 @@ async function fetchRecentTssGames(teams, signal) {
bySession.set(game.session_id, {
...game,
team_name: data.tag_name || name,
long_name: data.long_name || '',
team_name: data.name || name,
})
})
})
@@ -1067,8 +1066,8 @@ function AppContent() {
const results = (data.teams || data.results || [])
.map((team) => ({
name: bestTeamName(team),
detail: team.long_name || team.short_name || '',
aliases: [team.tag_name, team.short_name, team.long_name].filter(Boolean),
detail: '',
aliases: [team.name].filter(Boolean),
}))
.filter((team) => team.name)
.slice(0, 10)
@@ -1079,8 +1078,8 @@ function AppContent() {
if (!controller.signal.aborted) {
fetchJson(apiEndpoints.resolve(query), controller.signal)
.then((data) => {
const name = data.tag_name || data.short_name || data.long_name || ''
setTeamSearchResults(name ? [{ name, detail: data.long_name || data.short_name || '', aliases: [name] }] : [])
const name = data.name || ''
setTeamSearchResults(name ? [{ name, detail: '', aliases: [name] }] : [])
setSearchHint(name ? { status: 'ready', name } : { status: 'error', name: '' })
})
.catch(() => {
@@ -1440,8 +1439,8 @@ function AppContent() {
return teams
.map((team) => {
const name = bestTeamName(team)
const aliases = [team.tag_name, team.short_name, team.long_name].filter(Boolean)
return { name, detail: team.long_name || team.short_name || '', aliases }
const aliases = [team.name].filter(Boolean)
return { name, detail: '', aliases }
})
.filter(({ name, aliases }) => {
if (!name || seen.has(name)) return false
@@ -1466,7 +1465,7 @@ function AppContent() {
try {
const resolved = await fetchJson(apiEndpoints.resolve(name))
const resolvedName = resolved.tag_name || resolved.short_name || resolved.long_name
const resolvedName = resolved.name
if (!resolvedName) throw new Error('Team not found')
const detail = await fetchJson(apiEndpoints.detail(resolvedName))
@@ -2846,9 +2845,6 @@ function TeamsPage({ leaderboard, navigate, teams }) {
<span className="text-sm font-semibold text-fury-cyan">#{index + 1}</span>
<span className="min-w-0">
<span className="block truncate text-lg font-semibold">{name}</span>
<span className="block truncate text-xs text-text-soft">
{team.long_name || team.short_name || 'Unresolved'}
</span>
</span>
<span className="text-sm">{formatNumber(team.player_count)} players</span>
<span className="text-sm">{formatNumber(team.total_battles)} battles</span>
@@ -2879,8 +2875,7 @@ function TeamProfilePage({ navigate, profile, requestedTeam, teams }) {
const ratingHourly = profile.history.data?.rating_hourly || []
const latestRating = ratingHourly.at(-1)?.rating || summary?.points?.total_points
const leaderboardTeam = teams.find((team) => bestTeamName(team) === requestedTeam)
const displayName = detail?.tag_name || bestTeamName(leaderboardTeam) || requestedTeam
const longName = detail?.long_name || leaderboardTeam?.long_name || ''
const displayName = detail?.name || bestTeamName(leaderboardTeam) || requestedTeam
return (
<section className="space-y-6 pt-24 sm:pt-28">
@@ -2900,7 +2895,7 @@ function TeamProfilePage({ navigate, profile, requestedTeam, teams }) {
</p>
<h1 className="mt-1 text-4xl font-bold">{displayName}</h1>
<p className="mt-2 text-sm text-text-soft">
{profile.detail.error || longName || profile.detail.status}
{profile.detail.error || ''}
</p>
</div>
<div className="grid grid-cols-2 gap-3 text-sm sm:grid-cols-3">
@@ -3090,7 +3085,7 @@ function BattleLogsPage({ live, matches }) {
<p className="truncate font-semibold text-fury-cyan">
{match.team_name || 'TSS team'}
</p>
<p className="truncate text-xs text-text-soft">{match.long_name || 'TSS battle record'}</p>
<p className="truncate text-xs text-text-soft">TSS battle record</p>
</div>
<p
className={`w-fit rounded-md px-3 py-1 text-sm font-semibold ${String(match.result).toLowerCase() === 'win'