Skip to content

Commit 712cb31

Browse files
Tolga MizrakciTolga Mizrakci
authored andcommitted
adding component and child works but can't be dragged
1 parent 97ca836 commit 712cb31

File tree

7 files changed

+48
-19
lines changed

7 files changed

+48
-19
lines changed

src/components/KonvaStage.jsx

Lines changed: 29 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -19,16 +19,16 @@ class KonvaStage extends Component {
1919
}
2020

2121
handleStageMouseDown = (e) => {
22-
// clicked on stage - cler selection
23-
if (e.target === e.target.getStage()) {
24-
this.props.openExpansionPanel({});
25-
return;
26-
}
27-
// clicked on transformer - do nothing
28-
const clickedOnTransformer = e.target.getParent().className === 'Transformer';
29-
if (clickedOnTransformer) {
30-
return;
31-
}
22+
// // clicked on stage - cler selection
23+
// if (e.target === e.target.getStage()) {
24+
// this.props.openExpansionPanel({});
25+
// return;
26+
// }
27+
// // clicked on transformer - do nothing
28+
// const clickedOnTransformer = e.target.getParent().className === 'Transformer';
29+
// if (clickedOnTransformer) {
30+
// return;
31+
// }
3232

3333
// find clicked rect by its name
3434
const id = e.target.name();
@@ -66,6 +66,7 @@ class KonvaStage extends Component {
6666
scaleX,
6767
scaleY,
6868
focusComponent,
69+
focusChild,
6970
} = this.props;
7071
const { selectedShapeName } = this.state;
7172

@@ -87,7 +88,7 @@ class KonvaStage extends Component {
8788
}}
8889
draggable={draggable}
8990
>
90-
{components.map((comp, i) => (
91+
{/* {components.map((comp, i) => (
9192
<Rectangle
9293
draggable={comp.draggable}
9394
selectedShapeName={selectedShapeName}
@@ -101,9 +102,25 @@ class KonvaStage extends Component {
101102
color={comp.color}
102103
handleTransform={handleTransform}
103104
/>
104-
))}
105+
))} */}
106+
{components.find((comp) => comp.title === focusComponent.title)
107+
.childrenArray.map((child, i) => <Rectangle
108+
draggable={child.draggable}
109+
selectedShapeName={selectedShapeName}
110+
key={i + child.componentName}
111+
componentId={child.id}
112+
x={child.position.x}
113+
y={child.position.y}
114+
width={child.position.width}
115+
height={child.position.height}
116+
title={child.childId + child.componentName}
117+
color={'red'}
118+
handleTransform={handleTransform}
119+
/>)}
120+
{/* )} */}
105121
<TransformerComponent
106122
focusComponent={focusComponent}
123+
focusChild={focusChild}
107124
selectedShapeName={selectedShapeName}
108125
/>
109126
</Group>

src/components/LeftColExpansionPanel.jsx

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,6 @@ import IconButton from '@material-ui/core/IconButton';
1515
import Grid from '@material-ui/core/Grid';
1616
import AddIcon from '@material-ui/icons/Add';
1717
import { openExpansionPanel } from '../utils/componentReducer.util';
18-
import { changeFocusChild } from '../actions/components';
1918

2019
const LeftColExpansionPanel = (props) => {
2120
const {
@@ -70,7 +69,6 @@ const LeftColExpansionPanel = (props) => {
7069
onClick={() => {
7170
console.log(title);
7271
addChild({ title });
73-
changeFocusChild({ title });
7472
}}
7573
/>
7674
</IconButton>

src/components/TransformerComponent.jsx

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -13,8 +13,8 @@ export default class TransformerComponent extends Component {
1313

1414
checkNode() {
1515
const stage = this.transformer.getStage();
16-
const { focusComponent } = this.props;
17-
const selectedNode = stage.findOne(`.${focusComponent.id}`);
16+
const { focusChild } = this.props;
17+
const selectedNode = stage.findOne(`.${focusChild.childId}`);
1818

1919
if (selectedNode === this.transformer.node()) {
2020
return;

src/containers/LeftContainer.jsx

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -32,7 +32,6 @@ 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 }) => dispatch(actions.changeFocusChild({ title })),
3635
});
3736

3837
class LeftContainer extends Component {
@@ -48,7 +47,6 @@ class LeftContainer extends Component {
4847

4948
handleAddComponent = () => {
5049
this.props.addComponent({ title: this.state.componentName });
51-
this.props.changeFocusChild({ title: this.state.componentName })
5250
this.setState({
5351
componentName: '',
5452
});

src/containers/MainContainer.jsx

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -33,6 +33,7 @@ const mapDispatchToProps = dispatch => ({
3333
const mapStateToProps = store => ({
3434
totalComponents: store.workspace.totalComponents,
3535
focusComponent: store.workspace.focusComponent,
36+
focusChild: store.workspace.focusChild,
3637
});
3738

3839
class MainContainer extends Component {
@@ -85,6 +86,7 @@ class MainContainer extends Component {
8586
collapseColumn,
8687
rightColumnOpen,
8788
focusComponent,
89+
focusChild,
8890
} = this.props;
8991
const {
9092
increaseHeight,
@@ -112,6 +114,7 @@ class MainContainer extends Component {
112114
handleTransform={handleTransformation}
113115
openExpansionPanel={openPanel}
114116
focusComponent={focusComponent}
117+
focusChild={focusChild}
115118
/>
116119
) : (
117120
<p>Add some components</p>

src/reducers/componentReducer.js

Lines changed: 12 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -91,7 +91,18 @@ const initialApplicationState = {
9191
// imagePath: '',
9292
successOpen: false,
9393
errorOpen: false,
94-
focusComponent: {},
94+
focusComponent: appComponent,
95+
focusChild: {
96+
childId: 0,
97+
componentName: null,
98+
position: {
99+
x: 110,
100+
y: 120,
101+
width: 50,
102+
height: 50,
103+
},
104+
draggable: true,
105+
},
95106
components: [appComponent],
96107
appDir: '',
97108
loading: false,

src/utils/componentReducer.util.js

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -34,6 +34,7 @@ const initialChildState = {
3434
width: 50,
3535
height: 50,
3636
},
37+
draggable: true,
3738
};
3839

3940
export const addComponent = (state, { title }) => {
@@ -104,6 +105,7 @@ export const addChild = (state, { title }) => {
104105
return {
105106
...state,
106107
components,
108+
focusChild: newChild,
107109
};
108110
};
109111

0 commit comments

Comments
 (0)