Skip to content

Commit 22c15e0

Browse files
addChild button not visible when focused
2 parents eb6f8d5 + 8441aa6 commit 22c15e0

File tree

10 files changed

+214
-60
lines changed

10 files changed

+214
-60
lines changed

main.js

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,8 @@ const {
77
ipcMain,
88
} = require('electron');
99

10+
require('electron-reload')(__dirname);
11+
1012
// const isDev = true;
1113
const isDev = process.env.NODE_ENV === 'development' || process.env.NODE_ENV === 'test';
1214

package.json

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -85,6 +85,7 @@
8585
"cli-spinner": "^0.2.8",
8686
"commander": "^2.17.1",
8787
"electron": "^2.0.7",
88+
"electron-reload": "^1.4.0",
8889
"enzyme": "^3.4.1",
8990
"konva": "^2.1.7",
9091
"localforage": "^1.7.2",

src/actionTypes/index.js

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,7 @@ export const ADD_COMPONENT = 'ADD_COMPONENT';
33
export const ADD_CHILD = 'ADD_CHILD';
44
export const UPDATE_COMPONENT = 'UPDATE_COMPONENT';
55
export const DELETE_COMPONENT = 'DELETE_COMPONENT';
6+
export const CHANGE_FOCUS_COMPONENT = 'CHANGE_FOCUS_COMPONENT';
67
export const UPDATE_CHILDREN = 'UPDATE_CHILDREN';
78
export const REASSIGN_PARENT = 'REASSIGN_PARENT';
89
export const SET_SELECTABLE_PARENTS = 'SET_SELECTABLE_PARENTS';

src/actions/components.js

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,7 @@ import {
44
ADD_CHILD,
55
UPDATE_COMPONENT,
66
DELETE_COMPONENT,
7+
CHANGE_FOCUS_COMPONENT,
78
UPDATE_CHILDREN,
89
REASSIGN_PARENT,
910
SET_SELECTABLE_PARENTS,
@@ -97,6 +98,10 @@ export const updateComponent = ({
9798
dispatch({ type: SET_SELECTABLE_PARENTS });
9899
};
99100

101+
export const changeFocusComponent = ({ title }) => (dispatch) => {
102+
dispatch({ type: CHANGE_FOCUS_COMPONENT, payload: { title } });
103+
};
104+
100105
// export const exportFiles = ({ components, path }) => (dispatch) => {
101106
// dispatch({
102107
// type: EXPORT_FILES,

src/components/KonvaStage.jsx

Lines changed: 58 additions & 35 deletions
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,8 @@
1-
import React, { Component, createRef, Fragment } from 'react';
1+
import React, { Component, createRef } from 'react';
22
// import PropTypes from 'prop-types';
33
import {
4-
Stage, Layer, Image, Group, Label, Text, Tag,
4+
Stage, Layer, Image, Group,
55
} from 'react-konva';
6-
import Konva from 'konva';
76
import TransformerComponent from './TransformerComponent.jsx';
87
import Rectangle from './Rectangle.jsx';
98

@@ -19,10 +18,6 @@ class KonvaStage extends Component {
1918
this.group = createRef();
2019
}
2120

22-
// Christian - this function causes the expansionPanel of the clicked rect to open
23-
// (and focusedComponent to change, which we don't want)
24-
// could reuse this logic for affecting state of children array
25-
// ADD FOCUS CHILD FUNCTIONALITY HERE
2621
handleStageMouseDown = (e) => {
2722
// clicked on stage - cler selection
2823
if (e.target === e.target.getStage()) {
@@ -46,11 +41,33 @@ class KonvaStage extends Component {
4641
}
4742
};
4843

44+
// WAS ALREADY COMMENTED OUT
45+
// handleStageDrag = () => {
46+
// // const mainWindowHeight = this.main.current.clientHeight;
47+
// // const mainWindowWidth = this.main.current.clientWidth;
48+
// // const groupX = this.refs.group.attrs.x;
49+
// // const groupY = this.refs.group.attrs.y;
50+
51+
// // const componentX = (mainWindowWidth / 2) - groupX;
52+
// // const componentY = (mainWindowHeight / 2) - groupY;
53+
// // console.log(componentX, componentY);
54+
// }
55+
56+
componentDidMount() {
57+
// this.props.setImage();
58+
}
59+
4960
render() {
5061
const {
51-
components, handleTransform, draggable, scaleX, scaleY, focusComponent,
62+
components,
63+
handleTransform,
64+
image,
65+
draggable,
66+
scaleX,
67+
scaleY,
68+
focusComponent,
5269
} = this.props;
53-
// const { selectedShapeName } = this.state;
70+
const { selectedShapeName } = this.state;
5471

5572
return (
5673
<Stage
@@ -71,38 +88,44 @@ class KonvaStage extends Component {
7188
draggable={draggable}
7289
>
7390
{components.map((comp, i) => (
74-
<Fragment key={i}>
75-
<Rectangle
76-
draggable={comp.draggable}
77-
key={i}
78-
componentId={comp.id}
79-
x={comp.position.x}
80-
y={comp.position.y}
81-
width={comp.position.width}
82-
height={comp.position.height}
83-
title={comp.title}
84-
color={comp.color}
85-
handleTransform={handleTransform}
86-
/>
87-
<Label x={comp.position.x} y={comp.position.y}>
88-
<Text
89-
text={`${comp.title},${comp.position.x.toPrecision(
90-
3,
91-
)},${comp.position.y.toPrecision(3)}`}
92-
fontFamily="Calibri"
93-
fontSize={12}
94-
padding={5}
95-
fill="green"
96-
/>
97-
</Label>
98-
</Fragment>
91+
<Rectangle
92+
draggable={comp.draggable}
93+
selectedShapeName={selectedShapeName}
94+
key={i}
95+
componentId={comp.id}
96+
x={comp.position.x}
97+
y={comp.position.y}
98+
width={comp.position.width}
99+
height={comp.position.height}
100+
title={comp.title}
101+
color={comp.color}
102+
handleTransform={handleTransform}
103+
/>
99104
))}
100-
<TransformerComponent focusComponent={focusComponent} />
105+
<TransformerComponent
106+
focusComponent={focusComponent}
107+
selectedShapeName={selectedShapeName}
108+
/>
101109
</Group>
102110
</Layer>
103111
</Stage>
104112
);
105113
}
106114
}
107115

116+
// KonvaStage.propTypes = {
117+
// draggable: PropTypes.bool.isRequired,
118+
// components: PropTypes.array.isRequired,
119+
// handleTransform: PropTypes.func.isRequired,
120+
// image: PropTypes.oneOfType([
121+
// PropTypes.string,
122+
// PropTypes.object,
123+
// ]),
124+
// scaleX: PropTypes.number.isRequired,
125+
// scaleY: PropTypes.number.isRequired,
126+
// openExpansionPanel: PropTypes.func.isRequired,
127+
// setImage: PropTypes.func.isRequired,
128+
// focusComponent: PropTypes.object.isRequired,
129+
// };
130+
108131
export default KonvaStage;

src/components/LeftColExpansionPanel.jsx

Lines changed: 47 additions & 23 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
import React, { Fragment } from 'react';
2-
import PropTypes from 'prop-types';
2+
// import PropTypes from 'prop-types';
33
import { withStyles } from '@material-ui/core/styles';
44
// import ExpansionPanel from '@material-ui/core/ExpansionPanel';
55
// import ExpansionPanelSummary from '@material-ui/core/ExpansionPanelSummary';
@@ -14,10 +14,18 @@ import ListItemText from '@material-ui/core/ListItemText';
1414
import IconButton from '@material-ui/core/IconButton';
1515
import Grid from '@material-ui/core/Grid';
1616
import AddIcon from '@material-ui/icons/Add';
17+
import { openExpansionPanel } from '../utils/componentReducer.util';
18+
import { changeFocusChild } from '../actions/components';
1719

1820
const LeftColExpansionPanel = (props) => {
1921
const {
20-
index, classes, focusComponent, component, deleteComponent, addChild,
22+
index,
23+
classes,
24+
focusComponent,
25+
component,
26+
deleteComponent,
27+
addChild,
28+
changeFocusComponent,
2129
} = props;
2230
const { title, id, color } = component;
2331

@@ -27,9 +35,20 @@ const LeftColExpansionPanel = (props) => {
2735

2836
return (
2937
<div className={classes.root}>
30-
<Grid item xs={12} md={6}>
31-
<List>
32-
<ListItem button component="a">
38+
<Grid item xs={12} md={6} style={{ color: 'red' }}>
39+
<List style={{ color: 'red' }}>
40+
<ListItem
41+
button
42+
component="a"
43+
// style={
44+
// if (components.find(comp => comp.title === focusComponent.title))
45+
// }
46+
style={{ color: 'red' }}
47+
onClick={() => {
48+
console.log({ title });
49+
changeFocusComponent({ title });
50+
}}
51+
>
3352
<ListItemText
3453
disableTypography
3554
className={classes.light}
@@ -42,15 +61,20 @@ const LeftColExpansionPanel = (props) => {
4261
style={{ color }}
4362
/>
4463
<ListItemSecondaryAction>
45-
<IconButton aria-label="Add">
46-
<AddIcon
47-
style={{ color, float: 'right' }}
48-
onClick={() => {
49-
console.log(title);
50-
addChild({ title });
51-
}}
52-
/>
53-
</IconButton>
64+
{isFocused() ? (
65+
<div />
66+
) : (
67+
<IconButton aria-label="Add">
68+
<AddIcon
69+
style={{ color, float: 'right' }}
70+
onClick={() => {
71+
console.log(title);
72+
addChild({ title });
73+
changeFocusChild({ title });
74+
}}
75+
/>
76+
</IconButton>
77+
)}
5478
</ListItemSecondaryAction>
5579
</ListItem>
5680
</List>
@@ -94,15 +118,15 @@ export default withStyles(styles)(LeftColExpansionPanel);
94118
</div>
95119
*/
96120

97-
LeftColExpansionPanel.propTypes = {
98-
classes: PropTypes.object.isRequired,
99-
component: PropTypes.object,
100-
index: PropTypes.number,
101-
focusComponent: PropTypes.object.isRequired,
102-
onExpansionPanelChange: PropTypes.func,
103-
updateComponent: PropTypes.func,
104-
deleteComponent: PropTypes.func,
105-
};
121+
// LeftColExpansionPanel.propTypes = {
122+
// classes: PropTypes.object.isRequired,
123+
// component: PropTypes.object,
124+
// index: PropTypes.number,
125+
// focusComponent: PropTypes.object.isRequired,
126+
// onExpansionPanelChange: PropTypes.func,
127+
// updateComponent: PropTypes.func,
128+
// deleteComponent: PropTypes.func,
129+
// };
106130

107131
function styles(theme) {
108132
return {

src/containers/LeftContainer.jsx

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -31,6 +31,8 @@ const mapDispatchToProps = dispatch => ({
3131
// openExpansionPanel: component => dispatch(actions.openExpansionPanel(component)),
3232
// deleteAllData: () => dispatch(actions.deleteAllData()),
3333
addChild: ({ title }) => dispatch(actions.addChild({ title })),
34+
changeFocusComponent: ({ title }) => dispatch(actions.changeFocusComponent({ title })),
35+
changeFocusChild: ({ title }) => dispatch(actions.changeFocusChild({ title })),
3436
});
3537

3638
class LeftContainer extends Component {
@@ -46,6 +48,7 @@ class LeftContainer extends Component {
4648

4749
handleAddComponent = () => {
4850
this.props.addComponent({ title: this.state.componentName });
51+
this.props.changeFocusChild({ title: this.state.componentName })
4952
this.setState({
5053
componentName: '',
5154
});
@@ -60,6 +63,7 @@ class LeftContainer extends Component {
6063
totalComponents,
6164
classes,
6265
addChild,
66+
changeFocusComponent,
6367
} = this.props;
6468
const { componentName } = this.state;
6569

@@ -72,6 +76,7 @@ class LeftContainer extends Component {
7276
component={component}
7377
focusComponent={focusComponent}
7478
addChild={addChild}
79+
changeFocusComponent={changeFocusComponent}
7580
/>
7681
));
7782

src/reducers/componentReducer.js

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,7 @@ import {
44
ADD_CHILD,
55
UPDATE_COMPONENT,
66
DELETE_COMPONENT,
7+
CHANGE_FOCUS_COMPONENT,
78
UPDATE_CHILDREN,
89
REASSIGN_PARENT,
910
SET_SELECTABLE_PARENTS,
@@ -29,6 +30,7 @@ import {
2930
addChild,
3031
updateComponent,
3132
deleteComponent,
33+
changeFocusComponent,
3234
updateChildren,
3335
reassignParent,
3436
setSelectableP,
@@ -114,6 +116,8 @@ const componentReducer = (state = initialApplicationState, action) => {
114116
return updateComponent(state, action.payload);
115117
case DELETE_COMPONENT:
116118
return deleteComponent(state, action.payload);
119+
case CHANGE_FOCUS_COMPONENT:
120+
return changeFocusComponent(state, action.payload);
117121
case UPDATE_CHILDREN:
118122
return updateChildren(state, action.payload);
119123
case REASSIGN_PARENT:

src/utils/componentReducer.util.js

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -159,6 +159,16 @@ export const deleteComponent = (state, { index, id }) => {
159159
};
160160
};
161161

162+
export const changeFocusComponent = (state, { title }) => {
163+
164+
let focusComp = state.components.filter((comp) => {if (comp.title === title) return comp})[0]
165+
166+
return {
167+
...state,
168+
focusComponent: focusComp,
169+
};
170+
};
171+
162172
// Add or remove children
163173
export const updateChildren = (state, { parentIds, childId }) => {
164174
const components = state.components.map((component) => {

0 commit comments

Comments
 (0)