Skip to content

Commit 4621bd3

Browse files
colors of recursive children are correct now
1 parent af227d8 commit 4621bd3

File tree

4 files changed

+36
-25
lines changed

4 files changed

+36
-25
lines changed

src/components/GrandchildRectangle.jsx

Lines changed: 14 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,14 @@ import { Rect, Group } from 'react-konva';
33
// import PropTypes from 'prop-types';
44

55
class GrandchildRectangle extends Component {
6+
getComponentColor(componentId) {
7+
console.log('siodfbsldfk', componentId);
8+
const color = this.props.components.find(comp => comp.id == componentId).color;
9+
console.log(color);
10+
11+
return color;
12+
}
13+
614
render() {
715
const {
816
color,
@@ -12,12 +20,12 @@ class GrandchildRectangle extends Component {
1220
scaleY,
1321
childId,
1422
componentId,
15-
componentName,
23+
childComponentName,
24+
childComponentId,
1625
width,
1726
height,
1827
focusChild,
1928
components,
20-
draggable,
2129
} = this.props;
2230

2331
// the Group is responsible for dragging of all children
@@ -44,21 +52,22 @@ class GrandchildRectangle extends Component {
4452
width={width}
4553
height={height}
4654
stroke={color}
47-
color={color}
55+
color={this.getComponentColor(childComponentId)}
4856
// fill={color}
4957
// opacity={0.8}
5058
strokeWidth={4}
5159
strokeScaleEnabled={false}
5260
draggable={false}
5361
/>
5462
{components
55-
.find(comp => comp.title === componentName)
63+
.find(comp => comp.title === childComponentName)
5664
.childrenArray.map((grandchild, i) => (
5765
<GrandchildRectangle
5866
key={i}
5967
components={components}
6068
componentId={componentId}
61-
componentName={grandchild.componentName}
69+
childComponentName={grandchild.componentName}
70+
childComponentId={grandchild.childComponentId}
6271
focusChild={focusChild}
6372
// childId={grandchild.childId}
6473
x={grandchild.position.x * (width / (window.innerWidth / 2))}

src/components/KonvaStage.jsx

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -59,6 +59,7 @@ class KonvaStage extends Component {
5959
const rectChildId = e.target.attrs.childId;
6060
console.log('e.target : ', rectChildId);
6161
this.props.changeFocusChild({ childId: rectChildId });
62+
// put individual component's focus child logic here
6263
};
6364

6465
render() {
@@ -96,13 +97,14 @@ class KonvaStage extends Component {
9697
>
9798
<Layer>
9899
{components
99-
.find(comp => comp.title === focusComponent.title)
100+
.find(comp => comp.id === focusComponent.id)
100101
.childrenArray.map((child, i) => (
101102
<Rectangle
102103
key={`${i}${child.componentName}`}
103104
components={components}
104105
componentId={focusComponent.id}
105-
componentName={child.componentName}
106+
childComponentName={child.componentName}
107+
childComponentId={child.childComponentId}
106108
focusChild={focusChild}
107109
childId={child.childId}
108110
x={child.position.x}

src/components/Rectangle.jsx

Lines changed: 17 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,14 @@ import GrandchildRectangle from './GrandchildRectangle.jsx';
77
// import PropTypes from 'prop-types';
88

99
class Rectangle extends Component {
10+
getComponentColor(componentId) {
11+
console.log('siodfbsldfk', componentId);
12+
const color = this.props.components.find(comp => comp.id == componentId).color;
13+
console.log(color);
14+
15+
return color;
16+
}
17+
1018
handleResize(componentId, childId, target) {
1119
const focChild = this.props.components
1220
.find(comp => comp.id === componentId)
@@ -32,14 +40,6 @@ class Rectangle extends Component {
3240
this.props.handleTransform(componentId, childId, transformation);
3341
}
3442

35-
getComponentOfThisChild() {
36-
console.log('title of this child: ', componentName);
37-
console.log(
38-
'component of this child: ',
39-
this.props.components.find(comp => comp.title === componentName),
40-
);
41-
}
42-
4343
render() {
4444
const {
4545
color,
@@ -49,7 +49,8 @@ class Rectangle extends Component {
4949
scaleY,
5050
childId,
5151
componentId,
52-
componentName,
52+
childComponentName,
53+
childComponentId,
5354
width,
5455
height,
5556
title,
@@ -84,7 +85,7 @@ class Rectangle extends Component {
8485
width={width}
8586
height={height}
8687
stroke={color}
87-
color={color}
88+
color={this.getComponentColor(childComponentId)}
8889
// fill={color}
8990
// opacity={0.8}
9091
onTransformEnd={event => this.handleResize(componentId, childId, event.target)}
@@ -96,24 +97,24 @@ class Rectangle extends Component {
9697
<Text text={title} fill={'white'} />
9798
</Label>
9899
{components
99-
.find(comp => comp.title === componentName)
100+
.find(comp => comp.title === childComponentName)
100101
.childrenArray.map((grandchild, i) => (
101102
<GrandchildRectangle
102103
key={i}
103104
components={components}
104105
componentId={componentId}
105-
componentName={grandchild.componentName}
106+
childComponentName={grandchild.componentName}
107+
childComponentId={grandchild.childComponentId}
106108
focusChild={focusChild}
107109
// childId={childId}
108110
x={grandchild.position.x * (width / (window.innerWidth / 2))}
109-
y={grandchild.position.y * (height / (window.innerHeight))}
111+
y={grandchild.position.y * (height / window.innerHeight)}
110112
scaleX={1}
111113
scaleY={1}
112114
width={grandchild.position.width * (width / (window.innerWidth / 2))}
113-
height={grandchild.position.height * (height / (window.innerHeight))}
115+
height={grandchild.position.height * (height / window.innerHeight)}
114116
// title={child.componentName + child.childId}
115-
color={color}
116-
draggable={false}
117+
color={grandchild.color}
117118
/>
118119
))}
119120
{focusChild.childId === childId && draggable ? (

src/utils/componentReducer.util.js

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -20,10 +20,9 @@ const initialComponentState = {
2020
width: 50,
2121
height: 50,
2222
},
23-
2423
childrenArray: [],
2524
nextChildId: 1,
26-
focusChild: null,
25+
focusChildId: 0,
2726
};
2827

2928
export const addComponent = (state, { title }) => {

0 commit comments

Comments
 (0)