This commit is contained in:
2026-05-16 11:55:00 +01:00
parent ec6996192c
commit bf1abe39c8
+30 -1
View File
@@ -96,6 +96,27 @@ function bestTeamName(team) {
return team?.tag_name || team?.short_name || team?.long_name || '' return team?.tag_name || team?.short_name || team?.long_name || ''
} }
function teamDetailLooksReal(detail) {
if (!detail || typeof detail !== 'object') return false
const summary = detail.team_summary || detail.squadron_summary || null
const players = Array.isArray(detail.players) ? detail.players : []
const hasStableId = Boolean(detail.clan_id || detail.id || detail.team_id || detail.squadron_id)
const hasRoster = players.length > 0
const hasActivity = Boolean(
Number(summary?.player_count || 0) > 0 ||
Number(summary?.total_battles || 0) > 0 ||
Number(summary?.wins || 0) > 0 ||
Number(summary?.points?.total_points || summary?.total_points || 0) > 0,
)
return hasStableId || hasRoster || hasActivity
}
function canonicalTeamName(detail, fallback = '') {
return detail?.tag_name || detail?.short_name || detail?.long_name || fallback
}
function normalizeAnalyticsPreferences(value) { function normalizeAnalyticsPreferences(value) {
if (!value || typeof value !== 'object') return { ...defaultAnalyticsPreferences } if (!value || typeof value !== 'object') return { ...defaultAnalyticsPreferences }
@@ -833,6 +854,10 @@ function AppContent() {
fetchJson(apiEndpoints.detail(route.teamName), controller.signal) fetchJson(apiEndpoints.detail(route.teamName), controller.signal)
.then((detail) => { .then((detail) => {
if (controller.signal.aborted) return if (controller.signal.aborted) return
if (!teamDetailLooksReal(detail)) {
navigate('/teams', { replace: true })
return
}
return Promise.allSettled([ return Promise.allSettled([
fetchJson(apiEndpoints.history(route.teamName), controller.signal), fetchJson(apiEndpoints.history(route.teamName), controller.signal),
@@ -1069,7 +1094,11 @@ function AppContent() {
const resolved = await fetchJson(apiEndpoints.resolve(name)) const resolved = await fetchJson(apiEndpoints.resolve(name))
const resolvedName = resolved.tag_name || resolved.short_name || resolved.long_name const resolvedName = resolved.tag_name || resolved.short_name || resolved.long_name
if (!resolvedName) throw new Error('Team not found') if (!resolvedName) throw new Error('Team not found')
navigate(teamPath(resolvedName))
const detail = await fetchJson(apiEndpoints.detail(resolvedName))
if (!teamDetailLooksReal(detail)) throw new Error('Team not found')
navigate(teamPath(canonicalTeamName(detail, resolvedName)))
setTeamQuery('') setTeamQuery('')
} catch { } catch {
setSearchHint({ status: 'error', name: '' }) setSearchHint({ status: 'error', name: '' })