Skip to content

Commit 3a598de

Browse files
committed
commit for now
1 parent c0a9ae1 commit 3a598de

File tree

1 file changed

+33
-32
lines changed

1 file changed

+33
-32
lines changed

src/components/markdown/ProblemsList/DivisionList/DivisionList.tsx

+33-32
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,10 @@ import {
55
useDivisionTableQuery,
66
useSetDivisionTableQuery,
77
} from '../../../../context/UserDataContext/properties/simpleProperties';
8-
import { ProblemSolutionInfo } from '../../../../models/problem';
8+
import {
9+
ProblemDifficulty,
10+
ProblemSolutionInfo,
11+
} from '../../../../models/problem';
912
import Transition from '../../../Transition';
1013
import { ProblemsList } from '../ProblemsList';
1114
import { DivisionProblemInfo } from './DivisionProblemInfo';
@@ -19,7 +22,7 @@ const allYears = `All (${startYear - 1} - ${endYear})`;
1922
const divisions = ['Bronze', 'Silver', 'Gold', 'Platinum'];
2023

2124
const getSeasons = () => {
22-
const res = [];
25+
const res: string[] = [];
2326
for (let i = startYear; i <= endYear; ++i) {
2427
res.push(`${i - 1} - ${i}`);
2528
}
@@ -64,10 +67,10 @@ const DivisionButton = ({
6467
setShow(false);
6568
onChange(option);
6669
};
67-
const ref = React.useRef<HTMLDivElement>();
70+
const ref = React.useRef<HTMLDivElement>(null);
6871
React.useEffect(() => {
6972
const handleClick = e => {
70-
if (ref.current.contains(e.target)) return;
73+
if (ref.current?.contains(e.target)) return;
7174
setShow(false);
7275
};
7376
document.addEventListener('mousedown', handleClick);
@@ -155,29 +158,27 @@ const DivisionButton = ({
155158
};
156159

157160
export function DivisionList(props): JSX.Element {
158-
const data = useStaticQuery(graphql`
159-
query {
161+
const data: Queries.DivisionListQuery = useStaticQuery(graphql`
162+
query DivisionList {
160163
allProblemInfo(
161164
filter: { source: { in: ["Bronze", "Silver", "Gold", "Platinum"] } }
162165
) {
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
174172
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
181182
}
182183
}
183184
}
@@ -187,21 +188,21 @@ export function DivisionList(props): JSX.Element {
187188
const probToLink: { [key: string]: string } = {};
188189
const probToURL: { [key: string]: string } = {};
189190
const probToTags: { [key: string]: string[] } = {};
190-
const probToDifficulty: { [key: string]: string[] } = {};
191+
const probToDifficulty: { [key: string]: ProblemDifficulty } = {};
191192
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;
194195
const uniqueId = problem.uniqueId;
195196
probToLink[uniqueId] =
196-
problem.module &&
197+
problem.module! &&
197198
`${moduleIDToURLMap[problem.module.frontmatter.id]}/#problem-${uniqueId}`;
198199
probToURL[uniqueId] = problem.url;
199200
const prevTags = probToTags[uniqueId] || [];
200201
const allTags = prevTags.concat(problem.tags);
201202
probToTags[uniqueId] = [...new Set(allTags)];
202-
probToDifficulty[uniqueId] = problem.difficulty;
203+
probToDifficulty[uniqueId] = problem.difficulty as ProblemDifficulty;
203204
// https://stackoverflow.com/questions/9229645/remove-duplicate-values-from-js-array
204-
probToSol[uniqueId] = problem.solution;
205+
probToSol[uniqueId] = problem.solution as ProblemSolutionInfo;
205206
}
206207
const divisionToSeasonToProbs: {
207208
[key: string]: { [key: string]: DivisionProblemInfo[] };
@@ -228,9 +229,9 @@ export function DivisionList(props): JSX.Element {
228229
for (const division of divisions) {
229230
for (const probInfo of divToProbs[division]) {
230231
const contest = probInfo[1];
231-
let fraction = null;
232+
let fraction = 0;
232233
if (contest in contestToFraction[division]) {
233-
fraction = contestToFraction[division][contest].shift();
234+
fraction = contestToFraction[division][contest].shift()!;
234235
}
235236
const id = `usaco-${probInfo[0]}`;
236237
const prob: DivisionProblemInfo = {
@@ -244,7 +245,7 @@ export function DivisionList(props): JSX.Element {
244245
moduleLink: probToLink[id],
245246
percentageSolved: fraction,
246247
tags: probToTags[id],
247-
difficulty: probToDifficulty[id] as any,
248+
difficulty: probToDifficulty[id],
248249
url:
249250
probToURL[id] ||
250251
'http://www.usaco.org/index.php?page=viewproblem2&cpid=' +

0 commit comments

Comments
 (0)