|
1 |
| -import React, {useRef, useState, useContext, useEffect } from 'react'; |
| 1 | +import React, {useState, useContext} from 'react'; |
2 | 2 | import Modal from '@material-ui/core/Modal';
|
3 | 3 | import StateContext from '../../context/context';
|
4 | 4 | import TableStateProps from './TableStateProps';
|
5 |
| -import { off } from 'process'; |
| 5 | + |
6 | 6 |
|
7 | 7 | function UseStateModal({ updateAttributeWithState, attributeToChange, childId }) {
|
8 | 8 | const [state, dispatch] = useContext(StateContext);
|
9 | 9 | const [open, setOpen] = useState(false);
|
10 |
| - const [displayObject, setDisplayObject] = useState(null) |
11 | 10 | const [stateKey, setStateKey] = useState('');
|
12 | 11 | const [statePropsId, setStatePropsId] = useState(-1);
|
13 | 12 | const [componentProviderId, setComponentProviderId] = useState(1);
|
14 | 13 |
|
15 |
| - const currentId = state.canvasFocus.componentId; |
16 |
| - const currentComponent = state.components[currentId - 1]; |
17 |
| - const passedInProps = (currentComponent.name !== 'App' && currentComponent.name !== 'index')? currentComponent.passedInProps : ''; |
18 |
| - const currentProps = currentComponent.stateProps; |
19 |
| - |
20 |
| - const allStateToDisplay = { |
21 |
| - ...currentProps, |
22 |
| - ...passedInProps |
23 |
| - }; |
24 |
| - |
25 |
| - console.log({allStateToDisplay}); |
26 |
| - |
27 |
| - // make tabs to choose which component to get state from |
28 |
| - // const componentTabs = []; |
29 |
| - // for (let i = 0; i < state.components.length; i ++) { |
30 |
| - // componentTabs.push(<button |
31 |
| - // onClick={() => { |
32 |
| - // setComponentProviderId(i+1); |
33 |
| - // setDisplayObject(null); |
34 |
| - // setStateKey(''); |
35 |
| - // }}> |
36 |
| - // {state.components[i].name} |
37 |
| - // </button>) |
38 |
| - // } |
39 |
| - |
40 |
| - // const componentTabs = []; |
41 |
| - // componentTabs.push(<button |
42 |
| - // onClick={() => { |
43 |
| - // setComponentProviderId(i+1); |
44 |
| - // setDisplayObject(null); |
45 |
| - // setStateKey(''); |
46 |
| - // }}> |
47 |
| - // {state.components[i].name} |
48 |
| - // </button>) |
49 |
| - // } |
50 |
| - |
51 |
| - //carly: add a button to exit out of the window? |
52 |
| - |
53 | 14 | // table to choose state from
|
54 | 15 | const body = (
|
55 | 16 | <div className="useState-position">
|
56 | 17 | <div className="useState-header">
|
57 | 18 | <span>Choose State</span>
|
58 |
| - {/* <button |
| 19 | + <button |
59 | 20 | style={{ margin: '5px 5px' ,padding: '1px', float: 'right' }}
|
60 | 21 | onClick={() => {
|
61 | 22 | setStateKey('');
|
62 | 23 | setStatePropsId(-1);
|
63 |
| - setDisplayObject(null) |
64 | 24 | setOpen(false)}}
|
65 | 25 | >
|
66 | 26 | X
|
67 |
| - </button> */} |
| 27 | + </button> |
68 | 28 | </div>
|
69 | 29 | <div className="useState-window">
|
70 |
| - {/* <div className="useState-dropdown"> |
71 |
| - {componentTabs} |
72 |
| - </div> */} |
73 | 30 | <div className="useState-stateDisplay">
|
74 | 31 | <TableStateProps
|
75 | 32 | providerId = {componentProviderId}
|
76 | 33 | canDeleteState = {false}
|
77 |
| - //displayObject = {allStateToDisplay["0"]} |
78 | 34 | selectHandler={(table) => {
|
79 |
| - // if object or array => show sub table |
80 |
| - // if (table.row.type === "object") { |
81 |
| - // if (statePropsId < 0) setStatePropsId(table.row.id); |
82 |
| - // setStateKey(stateKey + table.row.key + '.'); |
83 |
| - // setDisplayObject(table.row.value); |
84 |
| - // } else if (table.row.type === "array") { |
85 |
| - // if (statePropsId < 0) setStatePropsId(table.row.id); |
86 |
| - // setStateKey(stateKey + table.row.key) |
87 |
| - // setDisplayObject(table.row.value); |
88 |
| - // } else { |
89 |
| - // if not object or array => update state |
90 |
| - setDisplayObject(null); |
91 | 35 | updateAttributeWithState(attributeToChange, componentProviderId, statePropsId > 0 ? statePropsId : table.row.id, table.row, stateKey + table.row.key);
|
92 | 36 | setStateKey('')
|
93 | 37 | setStatePropsId(-1);
|
94 | 38 | setOpen(false);
|
95 |
| - // } |
96 | 39 | }}
|
97 | 40 | deleteHandler={() => func()}
|
98 | 41 | isThemeLight={true}
|
|
0 commit comments