1- import React , { FormEvent , useRef , useState } from 'react' ;
1+ import React , { FormEvent , useEffect , useRef , useState , useCallback } from 'react' ;
22import { view } from '@risingstack/react-easy-state' ;
33
4+ import { IMRStatus } from 'src/typings/respResult' ;
5+
46import appStore from 'webviews/store/appStore' ;
57import persistDataHook from 'webviews/hooks/persistDataHook' ;
6- import Activities from 'webviews/components/Activities' ;
7- import Reviewers from 'webviews/components/Reviewers' ;
88import initDataHook from 'webviews/hooks/initDataHook' ;
9- import EditButton from 'webviews/components/EditButton' ;
10- // import { requestUpdateMRContent } from 'webviews/service/mrService';
9+
10+ import Activities from 'webviews/components/mr/Activities' ;
11+ import Reviewers from 'webviews/components/mr/Reviewers' ;
12+ import EditButton from 'webviews/components/mr/EditButton' ;
13+ import StatusCheck from 'webviews/components/mr/StatusCheck' ;
1114
1215import {
1316 EmptyWrapper ,
@@ -25,18 +28,46 @@ import {
2528} from 'webviews/app.styles' ;
2629
2730function App ( ) {
28- const { currentMR, updateMRTitle, toggleUpdatingDesc, updateMRDesc } = appStore ;
31+ const { currentMR, updateMRTitle, toggleUpdatingDesc, updateMRDesc, fetchMRStatus } = appStore ;
2932 const [ isEditingTitle , setEditingTitle ] = useState ( false ) ;
3033 const [ title , setTitle ] = useState ( currentMR ?. data ?. merge_request ?. title ) ;
3134 const inputRef = useRef < HTMLInputElement | null > ( null ) ;
3235 const [ desc , setDesc ] = useState ( `` ) ;
36+ const statusChecker = useRef < undefined | number > ( ) ;
37+ const [ statusData , setStatusData ] = useState < IMRStatus | null > ( null ) ;
3338
3439 const { repoInfo, data } = currentMR ;
3540 const { merge_request : mergeRequest } = data || { } ;
3641
3742 persistDataHook ( ) ;
3843 initDataHook ( ) ;
3944
45+ useEffect ( ( ) => {
46+ statusChecker . current = window . setTimeout ( async ( ) => {
47+ try {
48+ await onRefreshStatus ( ) ;
49+ } finally {
50+ window . clearTimeout ( statusChecker . current ) ;
51+
52+ statusChecker . current = window . setInterval ( async ( ) => {
53+ await onRefreshStatus ( ) ;
54+ } , 30 * 1000 ) ;
55+ }
56+ } , 3 * 1000 ) ;
57+
58+ return ( ) => {
59+ window . clearTimeout ( statusChecker . current ) ;
60+ window . clearInterval ( statusChecker . current ) ;
61+ setStatusData ( null ) ;
62+ } ;
63+ } , [ currentMR . iid ] ) ;
64+
65+ const onRefreshStatus = useCallback ( async ( ) => {
66+ const resp = await fetchMRStatus ( currentMR . iid ) ;
67+ setStatusData ( resp ) ;
68+ return null ;
69+ } , [ currentMR . iid ] ) ;
70+
4071 const handleKeyDown = async ( event : any ) => {
4172 if ( event . key === 'Enter' ) {
4273 await updateMRTitle ( title ) ;
@@ -146,6 +177,9 @@ function App() {
146177 onChange = { onChangeDesc }
147178 />
148179 ) }
180+
181+ < StatusCheck data = { statusData } onRefresh = { onRefreshStatus } />
182+
149183 < SectionTitle > Activities</ SectionTitle >
150184 < Activities />
151185 </ Body >
0 commit comments