/
app.js
executable file
·75 lines (60 loc) · 1.41 KB
/
app.js
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
import React, { useEffect, memo } from 'react'
import { useMachine } from '../xstate-custom/useMyMachine'
import { MainMachine, MainTypes } from '../fsm/mainMachine'
import Row from './row'
import './styles.css'
import { StateChart } from '@statecharts/xstate-viz'
import whyDidYouRender from '@welldone-software/why-did-you-render'
whyDidYouRender(React)
let uid = 0
const App = () => {
const [state, send] = useMachine(MainMachine, { debug: false })
const { songs, completed } = state.context
// console.log(
// '\n\n[Parent State] = ',
// state.value,
// '\n[context] = ',
// state.context,
// )
const rows = songs.map((it, idx) => {
return <Row item={it} key={it.name} />
})
const allDone = songs.length === completed.length
const handleAddFile = () => {
send({
type: MainTypes.addFile,
song: {
id: ++uid,
name: `Song_${uid}.flac`,
progress: 0,
},
})
}
// add some jobs to run
useEffect(() => {
// handleAddFile()
// handleAddFile()
// handleAddFile()
// handleAddFile()
// handleAddFile()
}, [])
const jobStyle = {
border: allDone ? '10px solid red' : null,
width: 150,
}
// return <StateChart machine={MainMachine} />
return (
<div>
<button
data-testid='btnAdd'
onClick={handleAddFile}>Add Job</button>
<div
data-testid='rows'
style={jobStyle}>
{rows}
</div>
</div>
)
}
App.whyDidYouRender = true
export default memo(App)