Skip to content

Commit a14728d

Browse files
committed
Image upload full functionality
1 parent 8a8f3f3 commit a14728d

File tree

5 files changed

+12
-8
lines changed

5 files changed

+12
-8
lines changed

src/components/KonvaStage.tsx

Lines changed: 7 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,6 @@
1+
//This component includes a component for the background image to be uploaded as reference for drawing components
2+
//and also the parent rectangle components.
3+
14
import React, { Component } from "react";
25
import { Stage, Layer, Line, Image } from "react-konva";
36
import Rectangle from "./Rectangle.tsx";
@@ -104,6 +107,7 @@ class KonvaStage extends Component<PropsInt, StateInt> {
104107
}
105108
};
106109

110+
//event handler to handle mouse click
107111
handleStageMouseDown = (e: any) => {
108112
// clicked on stage - clear selection
109113
if (e.target === e.target.getStage()) {
@@ -120,7 +124,6 @@ class KonvaStage extends Component<PropsInt, StateInt> {
120124

121125
// find clicked rect by its name
122126
const rectChildId = e.target.attrs.childId;
123-
// console.log("user clicked on child rectangle with childId: ", rectChildId);
124127
this.props.changeFocusChild({ childId: rectChildId });
125128
this.props.changeComponentFocusChild({
126129
componentId: this.props.focusComponent.id,
@@ -207,7 +210,9 @@ class KonvaStage extends Component<PropsInt, StateInt> {
207210
}}
208211
>
209212
{this.state.grid}
210-
<Image image={image} draggable width={this.state.stageWidth*0.8} height={this.state.stageHeight*0.9}/>
213+
<Image image={this.props.focusComponent.id === 1 ? image : null //only display background image if the focused component is <App>
214+
} draggable width={this.state.stageWidth*0.8} height={this.state.stageHeight*0.9 } //for background image uploaded, fix to fit screen
215+
/>
211216
{!isEmpty(focusComponent) && this.getDirectChildrenCopy(focusComponent)
212217
.map((child: ChildInt, i: number) => (
213218
<Rectangle

src/components/Rectangle.tsx

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -62,7 +62,6 @@ class Rectangle extends Component<PropsInt, StateInt> {
6262
x: target.x() + focChild.position.x,
6363
y: target.y() + focChild.position.y
6464
};
65-
console.log('width:', transformation.width, 'height:', transformation.height, 'x', transformation.x, 'y', transformation.y);
6665
this.props.handleTransform(componentId, childId, transformation);
6766
}
6867

@@ -144,7 +143,7 @@ class Rectangle extends Component<PropsInt, StateInt> {
144143
strokeWidth={childType === 'COMP' ? 4 : 2}
145144
strokeScaleEnabled={false}
146145
draggable={false}
147-
fill={childId === -1 ? 'white' : null}
146+
fill={null}
148147
shadowBlur={childId === -1 ? 6 : null}
149148
fillPatternImage={this.state.image ? this.state.image : null}
150149
fillPatternScaleX={this.state.image ? width / this.state.image.width : 1}

src/containers/MainContainer.tsx

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,6 @@
1+
//The main container includes both the Konva stage for creating component wireframes and
2+
//the bottom panel.
3+
14
import React, { Component } from "react";
25
import { connect } from "react-redux";
36
import { MuiThemeProvider } from "@material-ui/core/styles";
@@ -64,7 +67,6 @@ const mapDispatchToProps = (dispatch: any) => ({
6467
height
6568
})
6669
),
67-
// openPanel: component => dispatch(openExpansionPanel(component)),
6870
changeImagePath: (imageSource: string) => dispatch(actions.changeImagePath(imageSource)),
6971

7072
changeFocusChild: ({ childId }: { childId: number }) =>

src/reducers/componentReducer.ts

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -129,7 +129,6 @@ const componentReducer = (state = initialApplicationState, action: any) => {
129129
return changeComponentFocusChild(state, action.payload);
130130
case CHANGE_IMAGE_SOURCE:
131131
return changeImageSource(state, action.payload);
132-
// case CREATE_APPLICATION:
133132
case EXPORT_FILES:
134133
return { ...state, loading: true };
135134
case EXPORT_FILES_SUCCESS:

src/utils/componentReducer.util.ts

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -310,15 +310,14 @@ export const handleTransform = (
310310
};
311311
};
312312

313+
//change image source
313314
export const changeImageSource = (state: ApplicationStateInt, src :string) => {
314315
return {
315316
...state,
316317
imageSource: src
317318
}
318319
}
319320

320-
321-
322321
//Reducer that deletes the component selected
323322
export const deleteComponent = (state: ApplicationStateInt, { componentId }: { componentId: number }) => {
324323
//select the component from list of components

0 commit comments

Comments
 (0)