fix
This commit is contained in:
+49
-28
@@ -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 (
|
||||
<section className="space-y-6">
|
||||
<section className="space-y-6 pt-24 sm:pt-28">
|
||||
<button
|
||||
className="text-sm font-semibold text-fury-cyan transition hover:text-text"
|
||||
onClick={() => navigate('/teams')}
|
||||
|
||||
Reference in New Issue
Block a user