1
1
import { Button , Col , Row , Table } from "reactstrap" ;
2
2
import React from "react" ;
3
- import { connect , PromiseState } from "react-refetch" ;
4
3
import { GoTrashcan } from "react-icons/go" ;
5
4
import { useProblems } from "../../../api/APIClient" ;
6
5
import { ProblemSearchBox } from "../../../components/ProblemSearchBox" ;
7
- import { ProgressResetList } from "../types" ;
8
- import {
9
- PROGRESS_RESET_ADD ,
10
- PROGRESS_RESET_DELETE ,
11
- PROGRESS_RESET_LIST ,
12
- } from "../ApiUrl" ;
13
6
import { ProblemLink } from "../../../components/ProblemLink" ;
14
- import {
15
- formatMomentDateTime ,
16
- parseSecond ,
17
- getCurrentUnixtimeInSecond ,
18
- } from "../../../utils/DateUtil" ;
7
+ import { formatMomentDateTime , parseSecond } from "../../../utils/DateUtil" ;
8
+ import { useProgressResetList } from "../../../api/InternalAPIClient" ;
9
+ import { addResetProgress , deleteResetProgress } from "./ApiClient" ;
19
10
20
- interface Props {
21
- progressResetList : PromiseState < ProgressResetList | null > ;
22
- addResetProgress : ( problemId : string ) => void ;
23
- addResetProgressResponse : PromiseState < Record < string , unknown > | null > ;
24
- deleteResetProgress : ( problemId : string ) => void ;
25
- deleteResetProgressResponse : PromiseState < Record < string , unknown > | null > ;
26
- }
27
-
28
- const InnerResetProgress : React . FC < Props > = ( props ) => {
29
- const progressResetList =
30
- props . progressResetList . fulfilled && props . progressResetList . value
31
- ? props . progressResetList . value . items
32
- : [ ] ;
11
+ export const ResetProgress : React . FC = ( ) => {
12
+ const progressResetListFetch = useProgressResetList ( ) ;
13
+ const progressResetList = progressResetListFetch . data ?. items || [ ] ;
33
14
progressResetList . sort ( ( a , b ) => a . reset_epoch_second - b . reset_epoch_second ) ;
34
15
const problems = useProblems ( ) ?? [ ] ;
35
16
return (
@@ -43,7 +24,11 @@ const InnerResetProgress: React.FC<Props> = (props) => {
43
24
< Col sm = "12" >
44
25
< ProblemSearchBox
45
26
problems = { problems }
46
- selectProblem = { ( problm ) : void => props . addResetProgress ( problm . id ) }
27
+ selectProblem = { async ( problem ) =>
28
+ await addResetProgress ( problem . id ) . then ( ( ) =>
29
+ progressResetListFetch . mutate ( )
30
+ )
31
+ }
47
32
/>
48
33
</ Col >
49
34
</ Row >
@@ -81,8 +66,10 @@ const InnerResetProgress: React.FC<Props> = (props) => {
81
66
< td >
82
67
< Button
83
68
color = "danger"
84
- onClick = { ( ) : void =>
85
- props . deleteResetProgress ( item . problem_id )
69
+ onClick = { async ( ) =>
70
+ await deleteResetProgress ( item . problem_id ) . then ( ( ) =>
71
+ progressResetListFetch . mutate ( )
72
+ )
86
73
}
87
74
>
88
75
< GoTrashcan />
@@ -98,46 +85,3 @@ const InnerResetProgress: React.FC<Props> = (props) => {
98
85
</ >
99
86
) ;
100
87
} ;
101
-
102
- export const ResetProgress = connect < unknown , Props > ( ( ) => ( {
103
- progressResetList : {
104
- url : PROGRESS_RESET_LIST ,
105
- } ,
106
- addResetProgressResponse : { value : null } ,
107
- addResetProgress : ( problemId : string ) => ( {
108
- addResetProgressResponse : {
109
- force : true ,
110
- refreshing : true ,
111
- url : PROGRESS_RESET_ADD ,
112
- method : "POST" ,
113
- body : JSON . stringify ( {
114
- problem_id : problemId ,
115
- reset_epoch_second : getCurrentUnixtimeInSecond ( ) ,
116
- } ) ,
117
- andThen : ( ) => ( {
118
- progressResetList : {
119
- force : true ,
120
- url : PROGRESS_RESET_LIST ,
121
- } ,
122
- } ) ,
123
- } ,
124
- } ) ,
125
- deleteResetProgress : ( problemId : string ) => ( {
126
- deleteResetProgressResponse : {
127
- force : true ,
128
- refreshing : true ,
129
- url : PROGRESS_RESET_DELETE ,
130
- method : "POST" ,
131
- body : JSON . stringify ( {
132
- problem_id : problemId ,
133
- } ) ,
134
- andThen : ( ) => ( {
135
- progressResetList : {
136
- force : true ,
137
- url : PROGRESS_RESET_LIST ,
138
- } ,
139
- } ) ,
140
- } ,
141
- } ) ,
142
- deleteResetProgressResponse : { value : null } ,
143
- } ) ) ( InnerResetProgress ) ;
0 commit comments