1- import { useState } from 'react' ;
1+ import { useQueryClient } from '@tanstack/react-query' ;
2+ import { useMemo , useState } from 'react' ;
23import { useTranslation } from 'react-i18next' ;
34import { Link , useParams } from 'react-router-dom' ;
45import { Popover } from 'react-tiny-popover' ;
56import { useCompetition } from '@/hooks/queries/useCompetition' ;
67import { useAuth } from '@/providers/AuthProvider' ;
8+ import { useWCIF } from '@/providers/WCIFProvider' ;
79
810export default function Header ( ) {
911 const { t } = useTranslation ( ) ;
1012 const { user, signIn, signOut } = useAuth ( ) ;
1113 const [ isPopoverOpen , setIsPopoverOpen ] = useState ( false ) ;
1214
1315 const { competitionId } = useParams ( ) ;
16+
17+ const queryClient = useQueryClient ( ) ;
18+
1419 const { data : comp } = useCompetition ( competitionId ) ;
20+ const { wcif } = useWCIF ( ) ;
21+
22+ const competitioName = useMemo ( ( ) => {
23+ if ( comp ?. name ) {
24+ return comp . name ;
25+ }
26+ if ( wcif ?. name ) {
27+ return wcif . name ;
28+ }
29+
30+ const upcomingCompetitions =
31+ queryClient . getQueryData < CondensedApiCompetiton [ ] > ( [ 'upcomingCompetitions' ] ) ?? [ ] ;
32+ const myCompetitions =
33+ queryClient . getQueryData < CondensedApiCompetiton [ ] > ( [ 'userCompetitions' ] ) ?? [ ] ;
34+
35+ const competition =
36+ upcomingCompetitions ?. find ( ( c ) => c . id === competitionId ) ||
37+ myCompetitions ?. find ( ( c ) => c . id === competitionId ) ;
38+
39+ if ( competition ) {
40+ return competition . name ;
41+ }
42+
43+ return undefined ;
44+ } , [ comp , competitionId , queryClient , wcif ] ) ;
1545
1646 return (
1747 < header className = "flex w-full shadow-md p-2 h-12 items-center print:hidden z-20 bg-white" >
@@ -21,7 +51,7 @@ export default function Header() {
2151 </ Link >
2252 < span > { ' / ' } </ span >
2353 < Link to = { `/competitions/${ comp ?. id || competitionId } ` } className = "text-blue-500" >
24- { comp ?. short_name }
54+ { competitioName }
2555 </ Link >
2656 </ div >
2757 < div className = "flex flex-1" />
0 commit comments