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,18 +2,14 @@
2 2
 import styled from 'styles'
3 3
 import React, { useRef } from 'react'
4 4
 import state, { useSelector } from 'state'
5
-import { X, Code } from 'react-feather'
5
+import { X } from 'react-feather'
6 6
 import { breakpoints, IconButton } from 'components/shared'
7 7
 import * as Panel from '../panel'
8 8
 import Control from './control'
9 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 15
 const stopKeyboardPropagation = (e: KeyboardEvent | React.KeyboardEvent) =>
@@ -22,11 +18,16 @@ const stopKeyboardPropagation = (e: KeyboardEvent | React.KeyboardEvent) =>
22 18
 export default function ControlPanel(): JSX.Element {
23 19
   const rContainer = useRef<HTMLDivElement>(null)
24 20
   const isOpen = useSelector((s) => Object.keys(s.data.codeControls).length > 0)
21
+
25 22
   const codeControls = useSelector(
26 23
     (state) => Object.keys(state.data.codeControls),
27 24
     deepCompareArrays
28 25
   )
29 26
 
27
+  if (codeControls.length === 0) {
28
+    return null
29
+  }
30
+
30 31
   return (
31 32
     <Panel.Root
32 33
       ref={rContainer}
@@ -37,25 +38,19 @@ export default function ControlPanel(): JSX.Element {
37 38
       onKeyDown={stopKeyboardPropagation}
38 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 54
     </Panel.Root>
60 55
   )
61 56
 }

Loading…
Cancel
Save