-
Notifications
You must be signed in to change notification settings - Fork 27
Expand file tree
/
Copy pathActiveSketch.tsx
More file actions
104 lines (94 loc) · 3.11 KB
/
Copy pathActiveSketch.tsx
File metadata and controls
104 lines (94 loc) · 3.11 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
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
import {
Button,
ViewHeader,
Icon,
paramIcon,
Panel,
PanelBody,
PanelHeader,
PopoutMenu,
HedronErrorBoundary,
useAppStore,
useOnSelectNode,
NodeContainer,
} from '@hedron-gl/ui-core'
import { Node } from '@hedron-gl/engine'
import c from './ActiveSketch.module.css'
import { openSketchSourceFile } from './openSketchSourceFile'
import { useActiveSketch } from '@components/hooks/useActiveSketch'
import { engineStore } from '@renderer/engine'
import { SketchControls } from '@components/SketchControls/SketchControls'
import { useGroupedNodes } from '@components/hooks/useGroupedNodes'
import { useSelectedNode } from '@components/hooks/useSelectedNode'
import { SelectedNode } from '@components/SelectedNode/SelectedNode'
interface ControlItemProps {
node: Node
sketchId: string
}
const ControlItem = ({ node, sketchId }: ControlItemProps) => {
const isActive = useAppStore((state) => state.selectedNodes[sketchId] === node.id)
const onSelectNode = useOnSelectNode(sketchId, node.id)
return <NodeContainer onClick={onSelectNode} nodeId={node.id} isActive={isActive} />
}
export const ActiveSketch = () => {
const activeSketch = useActiveSketch()
if (!activeSketch) {
throw new Error('ActiveSketch component: No activesketch found')
}
const nodeGroups = useGroupedNodes(activeSketch.nodeIds, activeSketch.moduleId)
const selectedNode = useSelectedNode()
const closeSelectedNodePanel = useOnSelectNode(activeSketch.id, null)
return (
<div className={c.container}>
<ViewHeader>
<Icon name="token" /> {activeSketch.title}
<PopoutMenu
className="ml-auto"
items={[
{
label: 'Move Up',
icon: 'arrow_upward',
onClick: () => engineStore.getState().moveSketchUp(activeSketch.id),
},
{
label: 'Move Down',
icon: 'arrow_downward',
onClick: () => engineStore.getState().moveSketchDown(activeSketch.id),
},
{
label: 'Open Source',
icon: 'code',
onClick: () => openSketchSourceFile(activeSketch.moduleId),
},
{
label: 'Delete Sketch',
icon: 'delete',
onClick: () => engineStore.getState().deleteSketch(activeSketch.id),
},
]}
>
<Button type="ghost" iconName="more_horiz" />
</PopoutMenu>
</ViewHeader>
<HedronErrorBoundary key={activeSketch.id}>
<div className={c.section}>
<SketchControls
sketchId={activeSketch.id}
nodeGroups={nodeGroups}
ControlItem={ControlItem}
/>
</div>
{selectedNode && (
<Panel snugPosition="bottom" spacing="slim" width="full" className={c.bottomPanel}>
<PanelHeader iconName={paramIcon} buttonOnClick={closeSelectedNodePanel}>
{selectedNode.title}
</PanelHeader>
<PanelBody>
<SelectedNode />
</PanelBody>
</Panel>
)}
</HedronErrorBoundary>
</div>
)
}