fix
This commit is contained in:
+34
-13
@@ -543,8 +543,12 @@ function AppContent() {
|
|||||||
liveRef.current = live
|
liveRef.current = live
|
||||||
}, [live])
|
}, [live])
|
||||||
|
|
||||||
function navigate(path) {
|
function navigate(path, { replace = false } = {}) {
|
||||||
|
if (replace) {
|
||||||
|
window.history.replaceState({}, '', path)
|
||||||
|
} else {
|
||||||
window.history.pushState({}, '', path)
|
window.history.pushState({}, '', path)
|
||||||
|
}
|
||||||
setRoute(parseRoute(path))
|
setRoute(parseRoute(path))
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -596,6 +600,12 @@ function AppContent() {
|
|||||||
|
|
||||||
useEffect(() => {
|
useEffect(() => {
|
||||||
if (!analyticsPreferences.analytics) return
|
if (!analyticsPreferences.analytics) return
|
||||||
|
if (
|
||||||
|
route.page === 'team' &&
|
||||||
|
(profile.teamName !== route.teamName || profile.detail.status !== 'ready')
|
||||||
|
) {
|
||||||
|
return
|
||||||
|
}
|
||||||
|
|
||||||
const visitorId = stableId(analyticsVisitorKey)
|
const visitorId = stableId(analyticsVisitorKey)
|
||||||
let stopped = false
|
let stopped = false
|
||||||
@@ -685,7 +695,7 @@ function AppContent() {
|
|||||||
window.clearInterval(timer)
|
window.clearInterval(timer)
|
||||||
document.removeEventListener('visibilitychange', onVisibilityChange)
|
document.removeEventListener('visibilitychange', onVisibilityChange)
|
||||||
}
|
}
|
||||||
}, [analyticsPreferences, route])
|
}, [analyticsPreferences, profile.detail.status, profile.teamName, route])
|
||||||
|
|
||||||
useEffect(() => {
|
useEffect(() => {
|
||||||
const onKeyDown = (event) => {
|
const onKeyDown = (event) => {
|
||||||
@@ -820,19 +830,19 @@ function AppContent() {
|
|||||||
games: { status: 'loading', data: null, error: null },
|
games: { status: 'loading', data: null, error: null },
|
||||||
})
|
})
|
||||||
|
|
||||||
Promise.allSettled([
|
fetchJson(apiEndpoints.detail(route.teamName), controller.signal)
|
||||||
fetchJson(apiEndpoints.detail(route.teamName), controller.signal),
|
.then((detail) => {
|
||||||
|
if (controller.signal.aborted) return
|
||||||
|
|
||||||
|
return Promise.allSettled([
|
||||||
fetchJson(apiEndpoints.history(route.teamName), controller.signal),
|
fetchJson(apiEndpoints.history(route.teamName), controller.signal),
|
||||||
fetchJson(apiEndpoints.games(route.teamName), controller.signal),
|
fetchJson(apiEndpoints.games(route.teamName), controller.signal),
|
||||||
]).then(([detailResult, historyResult, gamesResult]) => {
|
]).then(([historyResult, gamesResult]) => {
|
||||||
if (controller.signal.aborted) return
|
if (controller.signal.aborted) return
|
||||||
|
|
||||||
setProfile({
|
setProfile({
|
||||||
teamName: route.teamName,
|
teamName: route.teamName,
|
||||||
detail:
|
detail: { status: 'ready', data: detail, error: null },
|
||||||
detailResult.status === 'fulfilled'
|
|
||||||
? { status: 'ready', data: detailResult.value, error: null }
|
|
||||||
: { status: 'error', data: null, error: detailResult.reason.message },
|
|
||||||
history:
|
history:
|
||||||
historyResult.status === 'fulfilled'
|
historyResult.status === 'fulfilled'
|
||||||
? { status: 'ready', data: historyResult.value, error: null }
|
? { status: 'ready', data: historyResult.value, error: null }
|
||||||
@@ -843,6 +853,10 @@ function AppContent() {
|
|||||||
: { status: 'error', data: null, error: gamesResult.reason.message },
|
: { status: 'error', data: null, error: gamesResult.reason.message },
|
||||||
})
|
})
|
||||||
})
|
})
|
||||||
|
})
|
||||||
|
.catch(() => {
|
||||||
|
if (!controller.signal.aborted) navigate('/teams', { replace: true })
|
||||||
|
})
|
||||||
|
|
||||||
return () => controller.abort()
|
return () => controller.abort()
|
||||||
}, [route.page, route.teamName])
|
}, [route.page, route.teamName])
|
||||||
@@ -1022,7 +1036,11 @@ function AppContent() {
|
|||||||
|
|
||||||
const topTeamName = bestTeamName(teams[0])
|
const topTeamName = bestTeamName(teams[0])
|
||||||
const searchPlaceholder =
|
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) {
|
async function handleTeamSearch(event) {
|
||||||
event.preventDefault()
|
event.preventDefault()
|
||||||
@@ -1031,9 +1049,12 @@ function AppContent() {
|
|||||||
|
|
||||||
try {
|
try {
|
||||||
const resolved = await fetchJson(apiEndpoints.resolve(name))
|
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 {
|
} 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 || ''
|
const longName = detail?.long_name || leaderboardTeam?.long_name || ''
|
||||||
|
|
||||||
return (
|
return (
|
||||||
<section className="space-y-6">
|
<section className="space-y-6 pt-24 sm:pt-28">
|
||||||
<button
|
<button
|
||||||
className="text-sm font-semibold text-fury-cyan transition hover:text-text"
|
className="text-sm font-semibold text-fury-cyan transition hover:text-text"
|
||||||
onClick={() => navigate('/teams')}
|
onClick={() => navigate('/teams')}
|
||||||
|
|||||||
Reference in New Issue
Block a user