@@ -21,6 +21,7 @@ import {
2121 Selection ,
2222 SelectionSchema ,
2323} from "../../../queries/leaderboards" ;
24+ import { getServerConfigurationQueryOptions } from "../../../queries/server-configuration" ;
2425import {
2526 getActivePage ,
2627 getCurrentPage ,
@@ -36,7 +37,7 @@ import { Title } from "./Title";
3637import { UserRank } from "./UserRank" ;
3738
3839//TODO change
39- const pageName = "about" ;
40+ export const pageName = "about" ;
4041
4142export const LeaderboardUrlParamsSchema = z
4243 . object ( {
@@ -79,34 +80,39 @@ export function LeaderboardPage(): JSXElement {
7980
8081 createEffect ( ( ) => {
8182 //update url after the data is loaded
82- if ( query . isSuccess ) updateGetParameters ( selection ( ) , page ( ) ) ;
83+ if ( dataQuery . isSuccess ) updateGetParameters ( selection ( ) , page ( ) ) ;
8384 } ) ;
8485
8586 createEffect ( ( ) => {
8687 //update url after the data is loaded
87- if ( rank . isSuccess ) syncLbMemory ( ) ;
88+ if ( rankQuery . isSuccess ) syncLbMemory ( ) ;
8889 } ) ;
8990
90- const query = useQuery ( ( ) => ( {
91+ const dataQuery = useQuery ( ( ) => ( {
9192 ...getLeaderboardQueryOptions ( {
9293 ...selection ( ) ,
9394 page : page ( ) ?? 0 ,
9495 } ) ,
9596 enabled : isOpen ( ) ,
9697 } ) ) ;
9798
98- const rank = useQuery ( ( ) => ( {
99+ const rankQuery = useQuery ( ( ) => ( {
99100 ...getRankQueryOptions ( selection ( ) ) ,
100101 enabled : isLoggedIn ( ) && isOpen ( ) ,
101102 } ) ) ;
102103
104+ const serverConfigurationQuery = useQuery ( ( ) => ( {
105+ ...getServerConfigurationQueryOptions ( ) ,
106+ enabled : isOpen ( ) ,
107+ } ) ) ;
108+
103109 const onSelectionChange = ( newSelection : Selection ) : void => {
104110 setSelection ( newSelection ) ;
105111 setPage ( 0 ) ;
106112 } ;
107113
108114 const userPage = ( ) : number | undefined => {
109- const userRank = rank . data ?. friendsRank ?? rank . data ?. rank ;
115+ const userRank = rankQuery . data ?. friendsRank ?? rankQuery . data ?. rank ;
110116 if ( userRank === undefined ) return undefined ;
111117 const page = Math . ceil ( userRank / 50 ) - 1 ;
112118 return page ;
@@ -116,7 +122,15 @@ export function LeaderboardPage(): JSXElement {
116122 < div class = "content-grid grid" >
117123 < div class = "flex flex-col gap-8 lg:flex-row" >
118124 < div class = "w-full lg:w-60" >
119- < Sidebar selection = { selection } onSelect = { onSelectionChange } />
125+ < AsyncContent query = { serverConfigurationQuery } >
126+ { ( config ) => (
127+ < Sidebar
128+ selection = { selection }
129+ onSelect = { onSelectionChange }
130+ validModeRules = { config . dailyLeaderboards . validModeRules ?? [ ] }
131+ />
132+ ) }
133+ </ AsyncContent >
120134 </ div >
121135
122136 < div class = "flex w-full flex-1 flex-col gap-4" >
@@ -131,16 +145,16 @@ export function LeaderboardPage(): JSXElement {
131145 />
132146
133147 < Show when = { isLoggedIn ( ) } >
134- < AsyncContent query = { rank } alwaysShowContent >
148+ < AsyncContent query = { rankQuery } alwaysShowContent >
135149 { ( data ) => (
136150 < UserRank
137151 type = { selection ( ) . type === "weekly" ? "xp" : "wpm" }
138152 data = { data }
139153 friendsOnly = { selection ( ) . friendsOnly }
140- total = { query . data ?. count }
154+ total = { dataQuery . data ?. count }
141155 minWpm = {
142- query . data && "minWpm" in query . data
143- ? ( query . data . minWpm as number )
156+ dataQuery . data && "minWpm" in dataQuery . data
157+ ? ( dataQuery . data . minWpm as number )
144158 : undefined
145159 }
146160 memoryDifference = { getLbMemoryDifference (
@@ -154,16 +168,18 @@ export function LeaderboardPage(): JSXElement {
154168
155169 < TableNavigation
156170 type = { selection ( ) . type }
157- lastPage = { Math . ceil ( ( query . data ?. count ?? 0 ) / 50 ) }
171+ lastPage = { Math . ceil ( ( dataQuery . data ?. count ?? 0 ) / 50 ) }
158172 currentPage = { page ( ) }
159173 onPageChange = { setPage }
160174 userPage = { userPage ( ) }
161175 onScrollToUser = { setScrollToUser }
162176 isLoading = {
163- query . isLoading || query . isFetching || query . isRefetching
177+ dataQuery . isLoading ||
178+ dataQuery . isFetching ||
179+ dataQuery . isRefetching
164180 }
165181 >
166- < AsyncContent query = { query } alwaysShowContent >
182+ < AsyncContent query = { dataQuery } alwaysShowContent >
167183 { ( data ) => (
168184 < Table
169185 type = { selection ( ) . type === "weekly" ? "xp" : "wpm" }
@@ -182,19 +198,19 @@ export function LeaderboardPage(): JSXElement {
182198
183199 function syncLbMemory ( ) : void {
184200 if (
185- rank . data !== undefined &&
186- rank . data !== null &&
201+ rankQuery . data !== undefined &&
202+ rankQuery . data !== null &&
187203 selection !== undefined &&
188204 selection ( ) . type === "allTime"
189205 ) {
190- const diff = getLbMemoryDifference ( selection ( ) , rank . data . rank ) ;
206+ const diff = getLbMemoryDifference ( selection ( ) , rankQuery . data . rank ) ;
191207
192208 if ( diff !== 0 ) {
193209 void updateLbMemory (
194210 "time" ,
195211 selection ( ) . mode2 as string ,
196212 "english" ,
197- rank . data . rank ,
213+ rankQuery . data . rank ,
198214 true ,
199215 ) ;
200216 }
0 commit comments