From e40c7c6ecc8105805ca7a16296c62a6dca110756 Mon Sep 17 00:00:00 2001 From: Heidi Date: Sat, 16 May 2026 11:50:47 +0100 Subject: [PATCH] fix --- src/App.jsx | 77 ++++++++++++++++++++++++++++++++++------------------- 1 file changed, 49 insertions(+), 28 deletions(-) diff --git a/src/App.jsx b/src/App.jsx index 7090c11..d1a3c2e 100644 --- a/src/App.jsx +++ b/src/App.jsx @@ -543,8 +543,12 @@ function AppContent() { liveRef.current = live }, [live]) - function navigate(path) { - window.history.pushState({}, '', path) + function navigate(path, { replace = false } = {}) { + if (replace) { + window.history.replaceState({}, '', path) + } else { + window.history.pushState({}, '', path) + } setRoute(parseRoute(path)) } @@ -596,6 +600,12 @@ function AppContent() { useEffect(() => { if (!analyticsPreferences.analytics) return + if ( + route.page === 'team' && + (profile.teamName !== route.teamName || profile.detail.status !== 'ready') + ) { + return + } const visitorId = stableId(analyticsVisitorKey) let stopped = false @@ -685,7 +695,7 @@ function AppContent() { window.clearInterval(timer) document.removeEventListener('visibilitychange', onVisibilityChange) } - }, [analyticsPreferences, route]) + }, [analyticsPreferences, profile.detail.status, profile.teamName, route]) useEffect(() => { const onKeyDown = (event) => { @@ -820,29 +830,33 @@ function AppContent() { games: { status: 'loading', data: null, error: null }, }) - Promise.allSettled([ - fetchJson(apiEndpoints.detail(route.teamName), controller.signal), - fetchJson(apiEndpoints.history(route.teamName), controller.signal), - fetchJson(apiEndpoints.games(route.teamName), controller.signal), - ]).then(([detailResult, historyResult, gamesResult]) => { - if (controller.signal.aborted) return + fetchJson(apiEndpoints.detail(route.teamName), controller.signal) + .then((detail) => { + if (controller.signal.aborted) return - setProfile({ - teamName: route.teamName, - detail: - detailResult.status === 'fulfilled' - ? { status: 'ready', data: detailResult.value, error: null } - : { status: 'error', data: null, error: detailResult.reason.message }, - history: - historyResult.status === 'fulfilled' - ? { status: 'ready', data: historyResult.value, error: null } - : { status: 'error', data: null, error: historyResult.reason.message }, - games: - gamesResult.status === 'fulfilled' - ? { status: 'ready', data: gamesResult.value, error: null } - : { status: 'error', data: null, error: gamesResult.reason.message }, + return Promise.allSettled([ + fetchJson(apiEndpoints.history(route.teamName), controller.signal), + fetchJson(apiEndpoints.games(route.teamName), controller.signal), + ]).then(([historyResult, gamesResult]) => { + if (controller.signal.aborted) return + + setProfile({ + teamName: route.teamName, + detail: { status: 'ready', data: detail, error: null }, + history: + historyResult.status === 'fulfilled' + ? { status: 'ready', data: historyResult.value, error: null } + : { status: 'error', data: null, error: historyResult.reason.message }, + games: + gamesResult.status === 'fulfilled' + ? { status: 'ready', data: gamesResult.value, error: null } + : { status: 'error', data: null, error: gamesResult.reason.message }, + }) + }) + }) + .catch(() => { + if (!controller.signal.aborted) navigate('/teams', { replace: true }) }) - }) return () => controller.abort() }, [route.page, route.teamName]) @@ -1022,7 +1036,11 @@ function AppContent() { const topTeamName = bestTeamName(teams[0]) const searchPlaceholder = - searchHint.status === 'ready' ? `Found ${searchHint.name}` : topTeamName || 'Search teams' + searchHint.status === 'ready' + ? `Found ${searchHint.name}` + : searchHint.status === 'error' + ? 'Team not found' + : topTeamName || 'Search teams' async function handleTeamSearch(event) { event.preventDefault() @@ -1031,9 +1049,12 @@ function AppContent() { try { const resolved = await fetchJson(apiEndpoints.resolve(name)) - navigate(teamPath(resolved.tag_name || resolved.short_name || resolved.long_name || name)) + const resolvedName = resolved.tag_name || resolved.short_name || resolved.long_name + if (!resolvedName) throw new Error('Team not found') + navigate(teamPath(resolvedName)) + setTeamQuery('') } catch { - navigate(teamPath(name)) + setSearchHint({ status: 'error', name: '' }) } } @@ -1989,7 +2010,7 @@ function TeamProfilePage({ navigate, profile, requestedTeam, teams }) { const longName = detail?.long_name || leaderboardTeam?.long_name || '' return ( -
+