Skip to content

Commit aefbc33

Browse files
Tolga MizrakciTolga Mizrakci
authored andcommitted
Merge branch 'development' of https://github.com/team-reactype/ReacType into development
2 parents 4390855 + ae9a7ca commit aefbc33

File tree

8 files changed

+134
-117
lines changed

8 files changed

+134
-117
lines changed

src/actionTypes/index.js

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

src/actions/components.js

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,7 @@ import {
55
UPDATE_COMPONENT,
66
DELETE_COMPONENT,
77
CHANGE_FOCUS_COMPONENT,
8+
CHANGE_FOCUS_CHILD,
89
UPDATE_CHILDREN,
910
REASSIGN_PARENT,
1011
SET_SELECTABLE_PARENTS,
@@ -109,6 +110,11 @@ export const changeFocusComponent = ({ title }) => (dispatch) => {
109110
dispatch({ type: CHANGE_FOCUS_COMPONENT, payload: { title } });
110111
};
111112

113+
// make sure childId is being sent in
114+
export const changeFocusChild = ({ title, childId }) => (dispatch) => {
115+
dispatch({ type: CHANGE_FOCUS_CHILD, payload: { title, childId } });
116+
};
117+
112118
// export const exportFiles = ({ components, path }) => (dispatch) => {
113119
// dispatch({
114120
// type: EXPORT_FILES,

src/components/KonvaStage.jsx

Lines changed: 25 additions & 44 deletions
Original file line numberDiff line numberDiff line change
@@ -1,13 +1,15 @@
1-
import React, { Component, createRef } from "react";
1+
import React, { Component, createRef } from 'react';
22
// import PropTypes from 'prop-types';
3-
import { Stage, Layer, Image, Group } from "react-konva";
4-
import TransformerComponent from "./TransformerComponent.jsx";
5-
import Rectangle from "./Rectangle.jsx";
3+
import {
4+
Stage, Layer, Image, Group,
5+
} from 'react-konva';
6+
import TransformerComponent from './TransformerComponent.jsx';
7+
import Rectangle from './Rectangle.jsx';
68

79
class KonvaStage extends Component {
810
state = {
911
x: undefined,
10-
y: undefined
12+
y: undefined,
1113
};
1214

1315
constructor(props) {
@@ -16,46 +18,24 @@ class KonvaStage extends Component {
1618
this.group = createRef();
1719
}
1820

19-
// Christian - this function causes the expansionPanel of the clicked rect to open
20-
// (and focusedComponent to change, which we don't want)
21-
// could reuse this logic for affecting state of children array
22-
// ADD CHANG FOCUS CHILD FUNCTIONALITY HERE
23-
handleStageMouseDown = e => {
24-
// // clicked on stage - cler selection
25-
// if (e.target === e.target.getStage()) {
26-
// this.props.openExpansionPanel({});
27-
// return;
28-
// }
21+
handleStageMouseDown = (e) => {
22+
// // clicked on stage - clear selection
23+
if (e.target === e.target.getStage()) {
24+
// add functionality for allowing no focusChild
25+
return;
26+
}
2927
// // clicked on transformer - do nothing
30-
// const clickedOnTransformer = e.target.getParent().className === 'Transformer';
31-
// if (clickedOnTransformer) {
32-
// return;
33-
// }
28+
const clickedOnTransformer = e.target.getParent().className === 'Transformer';
29+
if (clickedOnTransformer) {
30+
return;
31+
}
3432

3533
// find clicked rect by its name
36-
const id = e.target.name();
37-
console.log(e.target);
38-
const rect = this.props.components.find(r => r.id === id);
39-
40-
// if (rect) {
41-
// this.props.openExpansionPanel(rect || this.props.focusComponent);
42-
// } else {
43-
// this.props.openExpansionPanel(this.props.focusComponent);
44-
// }
34+
const rectChildId = e.target.attrs.childId;
35+
console.log('e.target : ', rectChildId);
36+
this.props.changeFocusChild({ childId: rectChildId });
4537
};
4638

47-
// WAS ALREADY COMMENTED OUT
48-
// handleStageDrag = () => {
49-
// // const mainWindowHeight = this.main.current.clientHeight;
50-
// // const mainWindowWidth = this.main.current.clientWidth;
51-
// // const groupX = this.refs.group.attrs.x;
52-
// // const groupY = this.refs.group.attrs.y;
53-
54-
// // const componentX = (mainWindowWidth / 2) - groupX;
55-
// // const componentY = (mainWindowHeight / 2) - groupY;
56-
// // console.log(componentX, componentY);
57-
// }
58-
5939
componentDidMount() {
6040
// this.props.setImage();
6141
}
@@ -69,13 +49,14 @@ class KonvaStage extends Component {
6949
scaleX,
7050
scaleY,
7151
focusComponent,
72-
focusChild
52+
focusChild,
53+
changeFocusChild,
7354
} = this.props;
7455
const { selectedShapeName } = this.state;
7556

7657
return (
7758
<Stage
78-
ref={node => {
59+
ref={(node) => {
7960
this.stage = node;
8061
}}
8162
onMouseDown={this.handleStageMouseDown}
@@ -86,7 +67,7 @@ class KonvaStage extends Component {
8667
<Group
8768
scaleX={scaleX}
8869
scaleY={scaleY}
89-
ref={node => {
70+
ref={(node) => {
9071
this.group = node;
9172
}}
9273
draggable={draggable}
@@ -97,7 +78,7 @@ class KonvaStage extends Component {
9778
<Rectangle
9879
draggable={child.draggable}
9980
selectedShapeName={selectedShapeName}
100-
key={i + `${child.componentName}`}
81+
key={`${i}${child.componentName}`}
10182
childId={child.childId}
10283
componentId={focusComponent.id}
10384
x={child.position.x}

src/components/LeftColExpansionPanel.jsx

Lines changed: 9 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -25,13 +25,19 @@ const LeftColExpansionPanel = (props) => {
2525
deleteComponent,
2626
addChild,
2727
changeFocusComponent,
28+
changeFocusChild,
2829
} = props;
2930
const { title, id, color } = component;
3031

3132
function isFocused() {
3233
return focusComponent.title === title ? 'focused' : '';
3334
}
3435

36+
function isAncestor() {
37+
// add logic for determining if given component is an ancestor of focusedComponent
38+
return false;
39+
}
40+
3541
return (
3642
<div className={classes.root}>
3743
<Grid item xs={12} md={6} style={{ color: 'red' }}>
@@ -57,7 +63,7 @@ const LeftColExpansionPanel = (props) => {
5763
style={{ color }}
5864
/>
5965
<ListItemSecondaryAction>
60-
{isFocused() ? (
66+
{isFocused() || isAncestor() ? (
6167
<div />
6268
) : (
6369
<IconButton aria-label="Add">
@@ -66,6 +72,8 @@ const LeftColExpansionPanel = (props) => {
6672
onClick={() => {
6773
console.log(title);
6874
addChild({ title });
75+
// get childId somewhere, or call changeFocusChild within addChild (better idea)
76+
// changeFocusChild({ title });
6977
}}
7078
/>
7179
</IconButton>

src/containers/LeftContainer.jsx

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -32,6 +32,7 @@ const mapDispatchToProps = dispatch => ({
3232
// deleteAllData: () => dispatch(actions.deleteAllData()),
3333
addChild: ({ title }) => dispatch(actions.addChild({ title })),
3434
changeFocusComponent: ({ title }) => dispatch(actions.changeFocusComponent({ title })),
35+
changeFocusChild: ({ title, childId }) => dispatch(actions.changeFocusChild({ title, childId })),
3536
});
3637

3738
class LeftContainer extends Component {
@@ -62,6 +63,7 @@ class LeftContainer extends Component {
6263
classes,
6364
addChild,
6465
changeFocusComponent,
66+
changeFocusChild,
6567
} = this.props;
6668
const { componentName } = this.state;
6769

@@ -75,6 +77,7 @@ class LeftContainer extends Component {
7577
focusComponent={focusComponent}
7678
addChild={addChild}
7779
changeFocusComponent={changeFocusComponent}
80+
changeFocusChild={changeFocusChild}
7881
/>
7982
));
8083

src/containers/MainContainer.jsx

Lines changed: 9 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,12 @@ import { connect } from 'react-redux';
77
// import TextField from '@material-ui/core/TextField';
88
import { MuiThemeProvider } from '@material-ui/core/styles';
99
import theme from '../components/theme';
10-
import { toggleDragging, openExpansionPanel, handleTransform } from '../actions/components';
10+
import {
11+
toggleDragging,
12+
openExpansionPanel,
13+
handleTransform,
14+
changeFocusChild,
15+
} from '../actions/components';
1116
import KonvaStage from '../components/KonvaStage.jsx';
1217
// import MainContainerHeader from '../components/MainContainerHeader.jsx';
1318
// import createModal from '../utils/createModal.util';
@@ -28,6 +33,7 @@ const mapDispatchToProps = dispatch => ({
2833
),
2934
toggleComponentDragging: status => dispatch(toggleDragging(status)),
3035
openPanel: component => dispatch(openExpansionPanel(component)),
36+
changeFocusChild: ({ title, childId }) => dispatch(changeFocusChild({ title, childId })),
3137
});
3238

3339
const mapStateToProps = store => ({
@@ -87,6 +93,7 @@ class MainContainer extends Component {
8793
rightColumnOpen,
8894
focusComponent,
8995
focusChild,
96+
changeFocusChild,
9097
} = this.props;
9198
const {
9299
increaseHeight,
@@ -115,6 +122,7 @@ class MainContainer extends Component {
115122
openExpansionPanel={openPanel}
116123
focusComponent={focusComponent}
117124
focusChild={focusChild}
125+
changeFocusChild={changeFocusChild}
118126
/>
119127
) : (
120128
<p>Add some components</p>

src/reducers/componentReducer.js

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,7 @@ import {
55
UPDATE_COMPONENT,
66
DELETE_COMPONENT,
77
CHANGE_FOCUS_COMPONENT,
8+
CHANGE_FOCUS_CHILD,
89
UPDATE_CHILDREN,
910
REASSIGN_PARENT,
1011
SET_SELECTABLE_PARENTS,
@@ -31,6 +32,7 @@ import {
3132
updateComponent,
3233
deleteComponent,
3334
changeFocusComponent,
35+
changeFocusChild,
3436
updateChildren,
3537
reassignParent,
3638
setSelectableP,
@@ -83,7 +85,7 @@ const appComponent = {
8385
childrenArray: [],
8486
nextChildId: 1,
8587
focusChild: null,
86-
}
88+
};
8789

8890
const initialApplicationState = {
8991
totalComponents: 1,
@@ -92,7 +94,7 @@ const initialApplicationState = {
9294
successOpen: false,
9395
errorOpen: false,
9496
focusComponent: appComponent,
95-
focusChild: {
97+
focusChild: {
9698
childId: 0,
9799
componentName: null,
98100
position: {
@@ -129,6 +131,8 @@ const componentReducer = (state = initialApplicationState, action) => {
129131
return deleteComponent(state, action.payload);
130132
case CHANGE_FOCUS_COMPONENT:
131133
return changeFocusComponent(state, action.payload);
134+
case CHANGE_FOCUS_CHILD:
135+
return changeFocusChild(state, action.payload);
132136
case UPDATE_CHILDREN:
133137
return updateChildren(state, action.payload);
134138
case REASSIGN_PARENT:

0 commit comments

Comments
 (0)