@@ -5,7 +5,10 @@ import {
5
5
useDivisionTableQuery ,
6
6
useSetDivisionTableQuery ,
7
7
} from '../../../../context/UserDataContext/properties/simpleProperties' ;
8
- import { ProblemSolutionInfo } from '../../../../models/problem' ;
8
+ import {
9
+ ProblemDifficulty ,
10
+ ProblemSolutionInfo ,
11
+ } from '../../../../models/problem' ;
9
12
import Transition from '../../../Transition' ;
10
13
import { ProblemsList } from '../ProblemsList' ;
11
14
import { DivisionProblemInfo } from './DivisionProblemInfo' ;
@@ -19,7 +22,7 @@ const allYears = `All (${startYear - 1} - ${endYear})`;
19
22
const divisions = [ 'Bronze' , 'Silver' , 'Gold' , 'Platinum' ] ;
20
23
21
24
const getSeasons = ( ) => {
22
- const res = [ ] ;
25
+ const res : string [ ] = [ ] ;
23
26
for ( let i = startYear ; i <= endYear ; ++ i ) {
24
27
res . push ( `${ i - 1 } - ${ i } ` ) ;
25
28
}
@@ -64,10 +67,10 @@ const DivisionButton = ({
64
67
setShow ( false ) ;
65
68
onChange ( option ) ;
66
69
} ;
67
- const ref = React . useRef < HTMLDivElement > ( ) ;
70
+ const ref = React . useRef < HTMLDivElement > ( null ) ;
68
71
React . useEffect ( ( ) => {
69
72
const handleClick = e => {
70
- if ( ref . current . contains ( e . target ) ) return ;
73
+ if ( ref . current ? .contains ( e . target ) ) return ;
71
74
setShow ( false ) ;
72
75
} ;
73
76
document . addEventListener ( 'mousedown' , handleClick ) ;
@@ -155,29 +158,27 @@ const DivisionButton = ({
155
158
} ;
156
159
157
160
export function DivisionList ( props ) : JSX . Element {
158
- const data = useStaticQuery ( graphql `
159
- query {
161
+ const data : Queries . DivisionListQuery = useStaticQuery ( graphql `
162
+ query DivisionList {
160
163
allProblemInfo(
161
164
filter: { source: { in: ["Bronze", "Silver", "Gold", "Platinum"] } }
162
165
) {
163
- edges {
164
- node {
165
- solution {
166
- kind
167
- label
168
- labelTooltip
169
- sketch
170
- url
171
- hasHints
172
- }
173
- uniqueId
166
+ nodes {
167
+ solution {
168
+ kind
169
+ label
170
+ labelTooltip
171
+ sketch
174
172
url
175
- tags
176
- difficulty
177
- module {
178
- frontmatter {
179
- id
180
- }
173
+ hasHints
174
+ }
175
+ uniqueId
176
+ url
177
+ tags
178
+ difficulty
179
+ module {
180
+ frontmatter {
181
+ id
181
182
}
182
183
}
183
184
}
@@ -187,21 +188,21 @@ export function DivisionList(props): JSX.Element {
187
188
const probToLink : { [ key : string ] : string } = { } ;
188
189
const probToURL : { [ key : string ] : string } = { } ;
189
190
const probToTags : { [ key : string ] : string [ ] } = { } ;
190
- const probToDifficulty : { [ key : string ] : string [ ] } = { } ;
191
+ const probToDifficulty : { [ key : string ] : ProblemDifficulty } = { } ;
191
192
const probToSol : { [ key : string ] : ProblemSolutionInfo } = { } ;
192
- for ( const edge of data . allProblemInfo . edges ) {
193
- const problem = edge . node ;
193
+ for ( const node of data . allProblemInfo . nodes ) {
194
+ const problem = node ;
194
195
const uniqueId = problem . uniqueId ;
195
196
probToLink [ uniqueId ] =
196
- problem . module &&
197
+ problem . module ! &&
197
198
`${ moduleIDToURLMap [ problem . module . frontmatter . id ] } /#problem-${ uniqueId } ` ;
198
199
probToURL [ uniqueId ] = problem . url ;
199
200
const prevTags = probToTags [ uniqueId ] || [ ] ;
200
201
const allTags = prevTags . concat ( problem . tags ) ;
201
202
probToTags [ uniqueId ] = [ ...new Set ( allTags ) ] ;
202
- probToDifficulty [ uniqueId ] = problem . difficulty ;
203
+ probToDifficulty [ uniqueId ] = problem . difficulty as ProblemDifficulty ;
203
204
// https://stackoverflow.com/questions/9229645/remove-duplicate-values-from-js-array
204
- probToSol [ uniqueId ] = problem . solution ;
205
+ probToSol [ uniqueId ] = problem . solution as ProblemSolutionInfo ;
205
206
}
206
207
const divisionToSeasonToProbs : {
207
208
[ key : string ] : { [ key : string ] : DivisionProblemInfo [ ] } ;
@@ -228,9 +229,9 @@ export function DivisionList(props): JSX.Element {
228
229
for ( const division of divisions ) {
229
230
for ( const probInfo of divToProbs [ division ] ) {
230
231
const contest = probInfo [ 1 ] ;
231
- let fraction = null ;
232
+ let fraction = 0 ;
232
233
if ( contest in contestToFraction [ division ] ) {
233
- fraction = contestToFraction [ division ] [ contest ] . shift ( ) ;
234
+ fraction = contestToFraction [ division ] [ contest ] . shift ( ) ! ;
234
235
}
235
236
const id = `usaco-${ probInfo [ 0 ] } ` ;
236
237
const prob : DivisionProblemInfo = {
@@ -244,7 +245,7 @@ export function DivisionList(props): JSX.Element {
244
245
moduleLink : probToLink [ id ] ,
245
246
percentageSolved : fraction ,
246
247
tags : probToTags [ id ] ,
247
- difficulty : probToDifficulty [ id ] as any ,
248
+ difficulty : probToDifficulty [ id ] ,
248
249
url :
249
250
probToURL [ id ] ||
250
251
'http://www.usaco.org/index.php?page=viewproblem2&cpid=' +
0 commit comments