Skip to content

Commit ff58c71

Browse files
authored
Merge pull request #173 from ShMcK/feature/dont-flash-loading
dont flash loader
2 parents a9fb1ec + 4ac50ba commit ff58c71

File tree

1 file changed

+22
-5
lines changed

1 file changed

+22
-5
lines changed

web-app/src/containers/Loading/index.tsx

+22-5
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@ import Message from '../../components/Message'
66

77
interface Props {
88
text: string
9-
context: T.MachineContext
9+
context?: T.MachineContext
1010
}
1111

1212
const styles = {
@@ -16,19 +16,36 @@ const styles = {
1616
flexDirection: 'column' as 'column',
1717
alignItems: 'center',
1818
justifyContent: 'center',
19-
width: '100%',
19+
height: '100%',
2020
},
2121
}
2222

2323
const LoadingPage = ({ text, context }: Props) => {
24-
const { error } = context
25-
if (error) {
24+
const [showLoading, setShowHiding] = React.useState(false)
25+
26+
React.useEffect(() => {
27+
// wait some time before showing loading indicator
28+
const timeout = setTimeout(() => {
29+
setShowHiding(true)
30+
}, 600)
31+
return () => {
32+
clearTimeout(timeout)
33+
}
34+
}, [])
35+
36+
if (context && context.error) {
2637
return (
2738
<div css={styles.page}>
28-
<Message type="error" title={error.title} content={error.description} />
39+
<Message type="error" title={context.error.title} content={context.error.description} />
2940
</div>
3041
)
3142
}
43+
44+
// don't flash loader
45+
if (!showLoading) {
46+
return null
47+
}
48+
3249
return (
3350
<div css={styles.page}>
3451
<Loading text={text} />

0 commit comments

Comments
 (0)