Skip to content

Commit 8441aa6

Browse files
Merge pull request #16 from tolgamizrakci/development
Development
2 parents a77d0e7 + 917ecc2 commit 8441aa6

File tree

10 files changed

+193
-55
lines changed

10 files changed

+193
-55
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: 55 additions & 39 deletions
Original file line numberDiff line numberDiff line change
@@ -1,12 +1,12 @@
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

9+
1010
class KonvaStage extends Component {
1111
state = {
1212
x: undefined,
@@ -19,10 +19,6 @@ class KonvaStage extends Component {
1919
this.group = createRef();
2020
}
2121

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
2622
handleStageMouseDown = (e) => {
2723
// clicked on stage - cler selection
2824
if (e.target === e.target.getStage()) {
@@ -46,11 +42,27 @@ class KonvaStage extends Component {
4642
}
4743
};
4844

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

5567
return (
5668
<Stage
@@ -68,41 +80,45 @@ class KonvaStage extends Component {
6880
ref={(node) => {
6981
this.group = node;
7082
}}
71-
draggable={draggable}
72-
>
73-
{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>
99-
))}
100-
<TransformerComponent focusComponent={focusComponent} />
83+
draggable={draggable}>
84+
<Image image={image} />
85+
{components.map((comp, i) => <Rectangle
86+
draggable={comp.draggable}
87+
selectedShapeName={selectedShapeName}
88+
key={i}
89+
componentId={comp.id}
90+
x={comp.position.x}
91+
y={comp.position.y}
92+
width={comp.position.width}
93+
height={comp.position.height}
94+
title={comp.title}
95+
color={comp.color}
96+
handleTransform={handleTransform}
97+
/>)}
98+
<TransformerComponent
99+
focusComponent={focusComponent}
100+
selectedShapeName={selectedShapeName}
101+
/>
101102
</Group>
102103
</Layer>
103104
</Stage>
104105
);
105106
}
106107
}
107108

109+
// KonvaStage.propTypes = {
110+
// draggable: PropTypes.bool.isRequired,
111+
// components: PropTypes.array.isRequired,
112+
// handleTransform: PropTypes.func.isRequired,
113+
// image: PropTypes.oneOfType([
114+
// PropTypes.string,
115+
// PropTypes.object,
116+
// ]),
117+
// scaleX: PropTypes.number.isRequired,
118+
// scaleY: PropTypes.number.isRequired,
119+
// openExpansionPanel: PropTypes.func.isRequired,
120+
// setImage: PropTypes.func.isRequired,
121+
// focusComponent: PropTypes.object.isRequired,
122+
// };
123+
108124
export default KonvaStage;

src/components/LeftColExpansionPanel.jsx

Lines changed: 29 additions & 14 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,18 +14,32 @@ 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 {
2022
index, classes, focusComponent, component, deleteComponent, addChild,
21-
} = props;
23+
changeFocusComponent } = props;
2224
const { title, id, color } = component;
2325

2426
return (
2527
<div className={classes.root}>
26-
<Grid item xs={12} md={6}>
27-
<List>
28-
<ListItem button component="a">
28+
<Grid item xs={12} md={6} style={{color: 'red'}}>
29+
<List
30+
style={{color: 'red'}}
31+
>
32+
<ListItem button component="a"
33+
// style={
34+
// if (components.find(comp => comp.title === focusComponent.title))
35+
// }
36+
style={{color: 'red'}}
37+
onClick={()=> {
38+
console.log({ title })
39+
changeFocusComponent({ title })
40+
41+
}}
42+
>
2943
<ListItemText
3044
disableTypography
3145
className={classes.light}
@@ -44,6 +58,7 @@ const LeftColExpansionPanel = (props) => {
4458
onClick={() => {
4559
console.log(title);
4660
addChild( { title } );
61+
changeFocusChild( { title } );
4762
}}
4863
/>
4964
</IconButton>
@@ -90,15 +105,15 @@ export default withStyles(styles)(LeftColExpansionPanel);
90105
</div>
91106
*/
92107

93-
LeftColExpansionPanel.propTypes = {
94-
classes: PropTypes.object.isRequired,
95-
component: PropTypes.object,
96-
index: PropTypes.number,
97-
focusComponent: PropTypes.object.isRequired,
98-
onExpansionPanelChange: PropTypes.func,
99-
updateComponent: PropTypes.func,
100-
deleteComponent: PropTypes.func,
101-
};
108+
// LeftColExpansionPanel.propTypes = {
109+
// classes: PropTypes.object.isRequired,
110+
// component: PropTypes.object,
111+
// index: PropTypes.number,
112+
// focusComponent: PropTypes.object.isRequired,
113+
// onExpansionPanelChange: PropTypes.func,
114+
// updateComponent: PropTypes.func,
115+
// deleteComponent: PropTypes.func,
116+
// };
102117

103118
function styles(theme) {
104119
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)