Browse Source

Only show controls when present

main
Steve Ruiz 4 years ago
parent
commit
9e3d2eb7cd
1 changed files with 21 additions and 26 deletions
  1. 21
    26
      components/controls-panel/controls-panel.tsx

+ 21
- 26
components/controls-panel/controls-panel.tsx View File

2
 import styled from 'styles'
2
 import styled from 'styles'
3
 import React, { useRef } from 'react'
3
 import React, { useRef } from 'react'
4
 import state, { useSelector } from 'state'
4
 import state, { useSelector } from 'state'
5
-import { X, Code } from 'react-feather'
5
+import { X } from 'react-feather'
6
 import { breakpoints, IconButton } from 'components/shared'
6
 import { breakpoints, IconButton } from 'components/shared'
7
 import * as Panel from '../panel'
7
 import * as Panel from '../panel'
8
 import Control from './control'
8
 import Control from './control'
9
 import { deepCompareArrays } from 'utils'
9
 import { deepCompareArrays } from 'utils'
10
 
10
 
11
-function openCodePanel() {
12
-  state.send('CLOSED_CODE_PANEL')
13
-}
14
-
15
-function closeCodePanel() {
16
-  state.send('OPENED_CODE_PANEL')
11
+function handleClose() {
12
+  state.send('CLOSED_CONTROLS')
17
 }
13
 }
18
 
14
 
19
 const stopKeyboardPropagation = (e: KeyboardEvent | React.KeyboardEvent) =>
15
 const stopKeyboardPropagation = (e: KeyboardEvent | React.KeyboardEvent) =>
22
 export default function ControlPanel(): JSX.Element {
18
 export default function ControlPanel(): JSX.Element {
23
   const rContainer = useRef<HTMLDivElement>(null)
19
   const rContainer = useRef<HTMLDivElement>(null)
24
   const isOpen = useSelector((s) => Object.keys(s.data.codeControls).length > 0)
20
   const isOpen = useSelector((s) => Object.keys(s.data.codeControls).length > 0)
21
+
25
   const codeControls = useSelector(
22
   const codeControls = useSelector(
26
     (state) => Object.keys(state.data.codeControls),
23
     (state) => Object.keys(state.data.codeControls),
27
     deepCompareArrays
24
     deepCompareArrays
28
   )
25
   )
29
 
26
 
27
+  if (codeControls.length === 0) {
28
+    return null
29
+  }
30
+
30
   return (
31
   return (
31
     <Panel.Root
32
     <Panel.Root
32
       ref={rContainer}
33
       ref={rContainer}
37
       onKeyDown={stopKeyboardPropagation}
38
       onKeyDown={stopKeyboardPropagation}
38
       onKeyUp={stopKeyboardPropagation}
39
       onKeyUp={stopKeyboardPropagation}
39
     >
40
     >
40
-      {isOpen ? (
41
-        <Panel.Layout>
42
-          <Panel.Header>
43
-            <IconButton bp={breakpoints} size="small" onClick={closeCodePanel}>
44
-              <X />
45
-            </IconButton>
46
-            <h3>Controls</h3>
47
-          </Panel.Header>
48
-          <ControlsList>
49
-            {codeControls.map((id) => (
50
-              <Control key={id} id={id} />
51
-            ))}
52
-          </ControlsList>
53
-        </Panel.Layout>
54
-      ) : (
55
-        <IconButton bp={breakpoints} size="small" onClick={openCodePanel}>
56
-          <Code />
57
-        </IconButton>
58
-      )}
41
+      <Panel.Layout>
42
+        <Panel.Header>
43
+          <IconButton bp={breakpoints} size="small" onClick={handleClose}>
44
+            <X />
45
+          </IconButton>
46
+          <h3>Controls</h3>
47
+        </Panel.Header>
48
+        <ControlsList>
49
+          {codeControls.map((id) => (
50
+            <Control key={id} id={id} />
51
+          ))}
52
+        </ControlsList>
53
+      </Panel.Layout>
59
     </Panel.Root>
54
     </Panel.Root>
60
   )
55
   )
61
 }
56
 }

Loading…
Cancel
Save