@@ -17,9 +17,9 @@ import { STATEFUL_BUTTON_STATES } from '../constants';
17
17
import messages from './messages' ;
18
18
import {
19
19
getCurrentStage , getError , getLinkCheckInProgress , getLoadingStatus , getSavingStatus , getLinkCheckResult ,
20
- getLastScannedAt ,
20
+ getLastScannedAt , getRerunLinkUpdateInProgress , getRerunLinkUpdateResult ,
21
21
} from './data/selectors' ;
22
- import { startLinkCheck , fetchLinkCheckStatus } from './data/thunks' ;
22
+ import { startLinkCheck , fetchLinkCheckStatus , fetchRerunLinkUpdateStatus } from './data/thunks' ;
23
23
import { useModel } from '../generic/model-store' ;
24
24
import ScanResults from './scan-results' ;
25
25
@@ -30,6 +30,32 @@ const pollLinkCheckStatus = (dispatch: any, courseId: string, delay: number): nu
30
30
return interval as unknown as number ;
31
31
} ;
32
32
33
+ const pollRerunLinkUpdateStatus = ( dispatch : any , courseId : string , delay : number ) : number => {
34
+ const interval = setInterval ( ( ) => {
35
+ dispatch ( fetchRerunLinkUpdateStatus ( courseId ) ) ;
36
+ } , delay ) ;
37
+ return interval as unknown as number ;
38
+ } ;
39
+
40
+ export function pollRerunLinkUpdateDuringUpdate (
41
+ rerunLinkUpdateInProgress : boolean | null ,
42
+ rerunLinkUpdateResult : any ,
43
+ interval : MutableRefObject < number | undefined > ,
44
+ dispatch : any ,
45
+ courseId : string ,
46
+ ) {
47
+ const shouldPoll = rerunLinkUpdateInProgress === true
48
+ || ( rerunLinkUpdateResult && rerunLinkUpdateResult . status && rerunLinkUpdateResult . status !== 'Succeeded' ) ;
49
+
50
+ if ( shouldPoll ) {
51
+ clearInterval ( interval . current as number | undefined ) ;
52
+ interval . current = pollRerunLinkUpdateStatus ( dispatch , courseId , 2000 ) ;
53
+ } else if ( interval . current ) {
54
+ clearInterval ( interval . current ) ;
55
+ interval . current = undefined ;
56
+ }
57
+ }
58
+
33
59
export function pollLinkCheckDuringScan (
34
60
linkCheckInProgress : boolean | null ,
35
61
interval : MutableRefObject < number | undefined > ,
@@ -48,6 +74,8 @@ export function pollLinkCheckDuringScan(
48
74
const CourseOptimizerPage : FC < { courseId : string } > = ( { courseId } ) => {
49
75
const dispatch = useDispatch ( ) ;
50
76
const linkCheckInProgress = useSelector ( getLinkCheckInProgress ) ;
77
+ const rerunLinkUpdateInProgress = useSelector ( getRerunLinkUpdateInProgress ) ;
78
+ const rerunLinkUpdateResult = useSelector ( getRerunLinkUpdateResult ) ;
51
79
const loadingStatus = useSelector ( getLoadingStatus ) ;
52
80
const savingStatus = useSelector ( getSavingStatus ) ;
53
81
const currentStage = useSelector ( getCurrentStage ) ;
@@ -56,6 +84,7 @@ const CourseOptimizerPage: FC<{ courseId: string }> = ({ courseId }) => {
56
84
const { msg : errorMessage } = useSelector ( getError ) ;
57
85
const isLoadingDenied = ( RequestFailureStatuses as string [ ] ) . includes ( loadingStatus ) ;
58
86
const interval = useRef < number | undefined > ( undefined ) ;
87
+ const rerunUpdateInterval = useRef < number | undefined > ( undefined ) ;
59
88
const courseDetails = useModel ( 'courseDetails' , courseId ) ;
60
89
const linkCheckPresent = currentStage != null ? currentStage >= 0 : ! ! currentStage ;
61
90
const [ showStepper , setShowStepper ] = useState ( false ) ;
@@ -101,6 +130,20 @@ const CourseOptimizerPage: FC<{ courseId: string }> = ({ courseId }) => {
101
130
} ;
102
131
} , [ linkCheckInProgress , linkCheckResult ] ) ;
103
132
133
+ useEffect ( ( ) => {
134
+ pollRerunLinkUpdateDuringUpdate (
135
+ rerunLinkUpdateInProgress ,
136
+ rerunLinkUpdateResult ,
137
+ rerunUpdateInterval ,
138
+ dispatch ,
139
+ courseId ,
140
+ ) ;
141
+
142
+ return ( ) => {
143
+ if ( rerunUpdateInterval . current ) { clearInterval ( rerunUpdateInterval . current ) ; }
144
+ } ;
145
+ } , [ rerunLinkUpdateInProgress , rerunLinkUpdateResult ] ) ;
146
+
104
147
const stepperVisibleCondition = linkCheckPresent && ( ( ! linkCheckResult || linkCheckInProgress ) && currentStage !== 2 ) ;
105
148
useEffect ( ( ) => {
106
149
let timeout : NodeJS . Timeout ;
@@ -119,6 +162,7 @@ const CourseOptimizerPage: FC<{ courseId: string }> = ({ courseId }) => {
119
162
120
163
if ( isLoadingDenied || isSavingDenied ) {
121
164
if ( interval . current ) { clearInterval ( interval . current ) ; }
165
+ if ( rerunUpdateInterval . current ) { clearInterval ( rerunUpdateInterval . current ) ; }
122
166
123
167
return (
124
168
// <Container size="xl" className="course-unit px-4 mt-4">
@@ -217,6 +261,8 @@ const CourseOptimizerPage: FC<{ courseId: string }> = ({ courseId }) => {
217
261
data = { linkCheckResult }
218
262
courseId = { courseId }
219
263
onErrorStateChange = { setScanResultsError }
264
+ rerunLinkUpdateInProgress = { rerunLinkUpdateInProgress }
265
+ rerunLinkUpdateResult = { rerunLinkUpdateResult }
220
266
/>
221
267
) }
222
268
</ article >
0 commit comments