mirror of
https://github.com/shumaiOne/shumai.git
synced 2026-12-04 06:54:28 +00:00
Merge pull request #167 from shumaiOne/fix/root-component-conditional-hooks
fix(webui): resolve conditional hooks and setState-in-render errors
This commit is contained in:
@@ -8,6 +8,7 @@ import {
|
|||||||
} from '@/ui/components/ui/dialog'
|
} from '@/ui/components/ui/dialog'
|
||||||
import { useQuery } from '@tanstack/react-query'
|
import { useQuery } from '@tanstack/react-query'
|
||||||
import { useNavigate } from '@tanstack/react-router'
|
import { useNavigate } from '@tanstack/react-router'
|
||||||
|
import { useEffect } from 'react'
|
||||||
import { m } from '@/ui/paraglide/messages.js'
|
import { m } from '@/ui/paraglide/messages.js'
|
||||||
|
|
||||||
export function TeamSelector() {
|
export function TeamSelector() {
|
||||||
@@ -23,14 +24,20 @@ export function TeamSelector() {
|
|||||||
},
|
},
|
||||||
})
|
})
|
||||||
|
|
||||||
|
const teams = teamsData?.data
|
||||||
|
const onlyTeamId = teams?.length === 1 ? teams[0].id : null
|
||||||
|
|
||||||
|
useEffect(() => {
|
||||||
|
if (onlyTeamId) {
|
||||||
|
navigate({ to: `/teams/${onlyTeamId}` })
|
||||||
|
}
|
||||||
|
}, [onlyTeamId, navigate])
|
||||||
|
|
||||||
if (isLoading) {
|
if (isLoading) {
|
||||||
return <div>{m.loading()}</div>
|
return <div>{m.loading()}</div>
|
||||||
}
|
}
|
||||||
|
|
||||||
const teams = teamsData?.data
|
if (onlyTeamId) {
|
||||||
|
|
||||||
if (teams?.length === 1) {
|
|
||||||
navigate({ to: `/teams/${teams[0].id}` })
|
|
||||||
return null
|
return null
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@@ -40,15 +40,10 @@ function RootComponent() {
|
|||||||
const { uploading } = useUploadStore()
|
const { uploading } = useUploadStore()
|
||||||
const pathname = useRouterState({ select: (s) => s.location.pathname })
|
const pathname = useRouterState({ select: (s) => s.location.pathname })
|
||||||
const navigate = useNavigate()
|
const navigate = useNavigate()
|
||||||
|
const { teamId: storedTeamId, setTeamId } = useTeamContextStore()
|
||||||
|
|
||||||
const showSidebar = user && (pathname.startsWith('/teams/') || pathname.startsWith('/projects/'))
|
const showSidebar = user && (pathname.startsWith('/teams/') || pathname.startsWith('/projects/'))
|
||||||
|
|
||||||
if (!showSidebar) {
|
|
||||||
return <Outlet />
|
|
||||||
}
|
|
||||||
|
|
||||||
const { teamId: storedTeamId, setTeamId } = useTeamContextStore()
|
|
||||||
|
|
||||||
useEffect(() => {
|
useEffect(() => {
|
||||||
resolveTeamIdFromPath(pathname).then((resolvedTeamId) => {
|
resolveTeamIdFromPath(pathname).then((resolvedTeamId) => {
|
||||||
if (resolvedTeamId && resolvedTeamId !== storedTeamId) {
|
if (resolvedTeamId && resolvedTeamId !== storedTeamId) {
|
||||||
@@ -70,6 +65,10 @@ function RootComponent() {
|
|||||||
enabled: !!storedTeamId,
|
enabled: !!storedTeamId,
|
||||||
})
|
})
|
||||||
|
|
||||||
|
if (!showSidebar) {
|
||||||
|
return <Outlet />
|
||||||
|
}
|
||||||
|
|
||||||
const unreadCount = me?.unreadNotificationCount ?? 0
|
const unreadCount = me?.unreadNotificationCount ?? 0
|
||||||
const displayCount = unreadCount > 99 ? '99+' : unreadCount
|
const displayCount = unreadCount > 99 ? '99+' : unreadCount
|
||||||
const badge =
|
const badge =
|
||||||
|
|||||||
Reference in New Issue
Block a user