1
1
import React , { useState } from 'react' ;
2
+ import styled from 'styled-components' ;
2
3
4
+ import { sleep } from 'webviews/utils/helper' ;
3
5
import { IMRStatus } from 'src/typings/respResult' ;
4
6
import { SectionTitle } from 'webviews/app.styles' ;
5
7
import RefreshIcon from 'webviews/assets/refresh.svg' ;
6
8
import IconButton from 'webviews/components/IconButton' ;
7
9
8
10
interface Props {
9
11
data : IMRStatus | null ;
10
- onRefresh : ( ) => Promise < any > ;
12
+ onRefresh : ( ... args : any [ ] ) => Promise < any > ;
11
13
}
12
14
15
+ const ListItem = styled . li `
16
+ i {
17
+ margin-left: 2ex;
18
+ }
19
+ ` ;
20
+
13
21
function StatusCheck ( props : Props ) {
22
+ const { data } = props ;
14
23
const [ refreshing , setRefreshing ] = useState ( false ) ;
15
24
16
25
const onRefresh = async ( ) => {
26
+ if ( refreshing ) {
27
+ return ;
28
+ }
29
+
17
30
setRefreshing ( true ) ;
18
- await Promise . allSettled ( [ props . onRefresh ] ) ;
31
+ // minimum 1s
32
+ await Promise . allSettled ( [ props . onRefresh , sleep ( 1000 ) ] ) ;
19
33
setRefreshing ( false ) ;
20
34
} ;
21
35
@@ -33,14 +47,20 @@ function StatusCheck(props: Props) {
33
47
</ IconButton >
34
48
</ SectionTitle >
35
49
< ul >
36
- { props . data ?. statuses . map ( ( i ) => {
37
- return (
38
- < li key = { i . context } >
39
- { i . context }
40
- < i > { i . description } </ i >
41
- </ li >
42
- ) ;
43
- } ) }
50
+ { data ?. statuses ? (
51
+ data ?. statuses . map ( ( i ) => {
52
+ return (
53
+ < ListItem key = { i . context } >
54
+ { i . context }
55
+ < i >
56
+ < a href = { i . target_url } > { i . description } </ a >
57
+ </ i >
58
+ </ ListItem >
59
+ ) ;
60
+ } )
61
+ ) : (
62
+ < li > No Job for now</ li >
63
+ ) }
44
64
</ ul >
45
65
</ >
46
66
) ;
0 commit comments