|
1 | | -import React from "react"; |
| 1 | +import type { JSX } from "react"; |
2 | 2 |
|
3 | | -import { |
4 | | - type PropertyChangeEvent, |
5 | | - applyPropertyChange, |
6 | | - useContributionModelsRecord, |
7 | | - useContributionStatesRecord, |
8 | | -} from "@/lib"; |
| 3 | +import { type ComponentChangeEvent, handleComponentChange } from "@/lib"; |
| 4 | +import { usePanelStates } from "@/demo/hooks"; |
9 | 5 | import Panel from "./Panel"; |
10 | 6 |
|
11 | | -const contribPoint = "panels"; |
12 | | - |
13 | 7 | function PanelsRow() { |
14 | | - const contributionModelsRecord = useContributionModelsRecord(); |
15 | | - const contributionStatesRecord = useContributionStatesRecord(); |
16 | | - const panelModels = contributionModelsRecord[contribPoint]; |
17 | | - const panelStates = contributionStatesRecord[contribPoint]; |
18 | | - if (!panelModels || !panelStates) { |
| 8 | + const panelStates = usePanelStates(); |
| 9 | + if (!panelStates) { |
19 | 10 | // Ok, not ready yet |
20 | 11 | return null; |
21 | 12 | } |
22 | | - // TODO: assert panelModels.length === panelStates.length |
23 | | - if (panelModels.length != panelStates?.length) { |
24 | | - throw Error("internal state error"); |
25 | | - } |
26 | 13 |
|
27 | | - const handlePropertyChange = ( |
| 14 | + const handlePanelChange = ( |
28 | 15 | panelIndex: number, |
29 | | - panelEvent: PropertyChangeEvent, |
| 16 | + panelEvent: ComponentChangeEvent, |
30 | 17 | ) => { |
31 | | - applyPropertyChange(contribPoint, panelIndex, panelEvent); |
| 18 | + handleComponentChange("panels", panelIndex, panelEvent); |
32 | 19 | }; |
33 | | - const visiblePanels: React.JSX.Element[] = []; |
| 20 | + const visiblePanels: JSX.Element[] = []; |
34 | 21 | panelStates.forEach((panelState, panelIndex) => { |
35 | | - if (panelState.visible) { |
| 22 | + if (panelState.state.visible) { |
36 | 23 | visiblePanels.push( |
37 | 24 | <Panel |
38 | 25 | key={panelIndex} |
39 | | - panelState={panelState} |
40 | | - panelModel={panelModels[panelIndex]} |
41 | | - onPropertyChange={(e) => handlePropertyChange(panelIndex, e)} |
| 26 | + {...panelState} |
| 27 | + onChange={(e) => handlePanelChange(panelIndex, e)} |
42 | 28 | />, |
43 | 29 | ); |
44 | 30 | } |
|
0 commit comments