1
- import { Col , Row } from "reactstrap" ;
2
- import React from "react" ;
1
+ import { Col , Row , Button , ButtonGroup } from "reactstrap" ;
2
+ import React , { useState } from "react" ;
3
3
import {
4
4
useContestToProblems ,
5
5
useUserSubmission ,
6
+ useContestMap ,
6
7
} from "../../../api/APIClient" ;
7
8
import Problem from "../../../interfaces/Problem" ;
8
9
import Submission from "../../../interfaces/Submission" ;
@@ -12,6 +13,7 @@ import {
12
13
isAccepted ,
13
14
isValidResult ,
14
15
} from "../../../utils" ;
16
+ import { isRatedContest } from "../../../utils/ContestClassifier" ;
15
17
import { SmallPieChart } from "./SmallPieChart" ;
16
18
17
19
enum SubmissionStatus {
@@ -143,18 +145,26 @@ export const PieChartBlock = (props: Props) => {
143
145
) ;
144
146
const contestToProblems =
145
147
useContestToProblems ( ) ?? new Map < ContestId , Problem [ ] > ( ) ;
148
+ const [ onlyRated , setOnlyRated ] = useState ( true ) ;
149
+ const contestMap = useContestMap ( ) ;
146
150
147
151
const abcSolved = solvedCountForPieChart (
148
- Array . from ( contestToProblems ) . filter ( ( [ contestId ] ) =>
149
- contestId . startsWith ( "abc" )
150
- ) ,
152
+ Array . from ( contestToProblems )
153
+ . filter ( ( [ contestId ] ) => contestId . startsWith ( "abc" ) )
154
+ . filter (
155
+ ( [ contestId ] ) =>
156
+ isRatedContest ( contestMap . get ( contestId ) , 2 ) || ! onlyRated
157
+ ) ,
151
158
submissionsMap ,
152
159
props . userId
153
160
) ;
154
161
const arcSolved = solvedCountForPieChart (
155
- Array . from ( contestToProblems ) . filter ( ( [ contestId ] ) =>
156
- contestId . startsWith ( "arc" )
157
- ) ,
162
+ Array . from ( contestToProblems )
163
+ . filter ( ( [ contestId ] ) => contestId . startsWith ( "arc" ) )
164
+ . filter (
165
+ ( [ contestId ] ) =>
166
+ isRatedContest ( contestMap . get ( contestId ) , 2 ) || ! onlyRated
167
+ ) ,
158
168
submissionsMap ,
159
169
props . userId
160
170
) ;
@@ -167,23 +177,50 @@ export const PieChartBlock = (props: Props) => {
167
177
) ;
168
178
return (
169
179
< >
170
- < PieCharts problems = { abcSolved } title = "AtCoder Beginner Contest" />
171
- < PieCharts problems = { arcSolved } title = "AtCoder Regular Contest" />
172
- < PieCharts problems = { agcSolved } title = "AtCoder Grand Contest" />
180
+ < PieCharts
181
+ problems = { abcSolved }
182
+ title = "AtCoder Beginner Contest"
183
+ setOnlyRated = { setOnlyRated }
184
+ onlyRated = { onlyRated }
185
+ />
186
+ < PieCharts
187
+ problems = { arcSolved }
188
+ title = "AtCoder Regular Contest"
189
+ setOnlyRated = { setOnlyRated }
190
+ onlyRated = { onlyRated }
191
+ />
192
+ < PieCharts
193
+ problems = { agcSolved }
194
+ title = "AtCoder Grand Contest"
195
+ setOnlyRated = { setOnlyRated }
196
+ onlyRated = { onlyRated }
197
+ />
173
198
</ >
174
199
) ;
175
200
} ;
176
201
177
202
interface PieChartsProps {
178
203
problems : { total : number ; solved : number ; rejected : number } [ ] ;
179
204
title : string ;
205
+ setOnlyRated : ( onlyRated : boolean ) => void ;
206
+ onlyRated : boolean ;
180
207
}
181
208
182
- const PieCharts : React . FC < PieChartsProps > = ( { problems, title } ) => (
209
+ const PieCharts : React . FC < PieChartsProps > = ( {
210
+ problems,
211
+ title,
212
+ setOnlyRated,
213
+ onlyRated,
214
+ } ) => (
183
215
< div >
184
216
< Row className = "my-2 border-bottom" >
185
217
< h1 > { title } </ h1 >
186
218
</ Row >
219
+ < ButtonGroup className = "mb-2" >
220
+ < Button onClick = { ( ) : void => setOnlyRated ( ! onlyRated ) } >
221
+ { onlyRated ? "Only Rated Contests" : "All Contests" }
222
+ </ Button >
223
+ </ ButtonGroup >
187
224
< Row className = "my-3" >
188
225
{ problems . map ( ( { solved, rejected, total } , i ) => {
189
226
const key = i <= 6 ? "ABCDEFG" . charAt ( i ) : "H/Ex" ;
0 commit comments