fix
This commit is contained in:
+30
-1
@@ -96,6 +96,27 @@ function bestTeamName(team) {
|
||||
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) {
|
||||
if (!value || typeof value !== 'object') return { ...defaultAnalyticsPreferences }
|
||||
|
||||
@@ -833,6 +854,10 @@ function AppContent() {
|
||||
fetchJson(apiEndpoints.detail(route.teamName), controller.signal)
|
||||
.then((detail) => {
|
||||
if (controller.signal.aborted) return
|
||||
if (!teamDetailLooksReal(detail)) {
|
||||
navigate('/teams', { replace: true })
|
||||
return
|
||||
}
|
||||
|
||||
return Promise.allSettled([
|
||||
fetchJson(apiEndpoints.history(route.teamName), controller.signal),
|
||||
@@ -1069,7 +1094,11 @@ function AppContent() {
|
||||
const resolved = await fetchJson(apiEndpoints.resolve(name))
|
||||
const resolvedName = resolved.tag_name || resolved.short_name || resolved.long_name
|
||||
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('')
|
||||
} catch {
|
||||
setSearchHint({ status: 'error', name: '' })
|
||||
|
||||
Reference in New Issue
Block a user