forked from cerebral/overmind
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathindex.tsx
More file actions
67 lines (61 loc) · 1.83 KB
/
index.tsx
File metadata and controls
67 lines (61 loc) · 1.83 KB
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
import { createElement, FunctionComponent, Fragment, useEffect } from 'react'
import { useOvermind } from '../../overmind'
import * as styles from './styles'
import * as text from '../../styles/text'
import { colors } from '../../theme'
import Workspace from '../Workspace'
import { css } from 'emotion'
const Devtools: FunctionComponent = () => {
const { state, actions } = useOvermind()
useEffect(() => {
const listener = (event: KeyboardEvent) => {
if (event.metaKey && event.keyCode === 82) {
actions.refreshApp()
}
}
document.addEventListener('keydown', listener)
return () => {
document.removeEventListener('keydown', listener)
}
}, [])
if (state.error) {
return (
<div className={styles.wrapper}>
<div className={styles.container}>
<div className={css(text.header, text.white)}>
Ops, there is an error :(
</div>
<div className={text.red}>{state.error}</div>
</div>
</div>
)
}
return state.isConnecting ? (
<div className={styles.wrapper}>
<h1>Waiting for an app to connect to {state.port}...</h1>
<pre className={styles.code}>
<span style={{ color: colors.purple }}>const</span> overmind ={' '}
{state.port === 3031 ? (
<Fragment>
<span style={{ color: colors.green }}>createOvermind</span>(config)
</Fragment>
) : (
<Fragment>
<span style={{ color: colors.green }}>createOvermind</span>(config,{' '}
{'{'}
{`\n`}
{' '}devtools:{' '}
<span style={{ color: colors.yellow }}>
"localhost:{state.port}"
</span>
{`\n`}
{'}'})
</Fragment>
)}
</pre>
</div>
) : (
<Workspace />
)
}
export default Devtools