This repository has been archived by the owner on Jun 14, 2021. It is now read-only.
-
-
Notifications
You must be signed in to change notification settings - Fork 9
/
index.tsx
79 lines (70 loc) · 2.9 KB
/
index.tsx
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
import { useStore } from '@fleur/fleur-react'
import { RenderingProgress, RenderingStep } from '@ragg/deream'
import * as classnames from 'classnames'
import * as React from 'react'
import { animated, useTransition } from 'react-spring'
import Button from '../../components/Button/Button'
import RendererStore from '../../domain/Renderer/RendererStore'
import t from './RenderingWaiter.i18n'
import * as s from './style.styl'
const statusToText = (progress: RenderingProgress) => {
switch (progress.step) {
case RenderingStep.Started:
return t(t.k.step.started)
case RenderingStep.Rendering:
return t(t.k.step.rendering, {
progression: Math.floor(progress.progression * 100),
})
case RenderingStep.Encoding:
return t(t.k.step.encoding)
case RenderingStep.Concat:
return t(t.k.step.concat)
case RenderingStep.Completed:
return t(t.k.step.completed)
}
}
export const RenderingWaiter = () => {
const [show, setShow] = React.useState(true)
const { inRendering, status } = useStore([RendererStore], getStore => ({
inRendering: getStore(RendererStore).isInRendering(),
status: getStore(RendererStore).getExportingState(),
}))
const handleClickDone = React.useCallback(() => {
setShow(false)
}, [])
React.useEffect(() => {
setShow(true)
}, [inRendering])
const transitions = useTransition(show && !!status, null, {
from: { opacity: 0 },
enter: { opacity: 1 },
leave: { opacity: 0 },
})
return (
<>
{transitions.map(
({ item, key, props: style }) =>
item && (
<animated.div key={key} className={s.RenderingWaiter} style={style}>
{status.step === RenderingStep.Completed ? (
<>
<div className={s.status}>
<img className={s.completedParrot} src={require('./parrot.gif')} />
<div className={s.statusText}>{statusToText(status)}</div>
</div>
<Button type="primary" className={s.doneButton} onClick={handleClickDone}>
{t(t.k.close)}
</Button>
</>
) : (
<div className={s.status}>
<i className={classnames('fa fa-circle-o-notch fa-3x', s.spinner)} />
<div className={s.statusText}>{statusToText(status)}</div>
</div>
)}
</animated.div>
),
)}
</>
)
}