Skip to content

Development #16

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 3 commits into from
Apr 20, 2019
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 2 additions & 0 deletions main.js
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,8 @@ const {
ipcMain,
} = require('electron');

require('electron-reload')(__dirname);

// const isDev = true;
const isDev = process.env.NODE_ENV === 'development' || process.env.NODE_ENV === 'test';

Expand Down
1 change: 1 addition & 0 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -85,6 +85,7 @@
"cli-spinner": "^0.2.8",
"commander": "^2.17.1",
"electron": "^2.0.7",
"electron-reload": "^1.4.0",
"enzyme": "^3.4.1",
"konva": "^2.1.7",
"localforage": "^1.7.2",
Expand Down
1 change: 1 addition & 0 deletions src/actionTypes/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@ export const ADD_COMPONENT = 'ADD_COMPONENT';
export const ADD_CHILD = 'ADD_CHILD';
export const UPDATE_COMPONENT = 'UPDATE_COMPONENT';
export const DELETE_COMPONENT = 'DELETE_COMPONENT';
export const CHANGE_FOCUS_COMPONENT = 'CHANGE_FOCUS_COMPONENT';
export const UPDATE_CHILDREN = 'UPDATE_CHILDREN';
export const REASSIGN_PARENT = 'REASSIGN_PARENT';
export const SET_SELECTABLE_PARENTS = 'SET_SELECTABLE_PARENTS';
Expand Down
5 changes: 5 additions & 0 deletions src/actions/components.js
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@ import {
ADD_CHILD,
UPDATE_COMPONENT,
DELETE_COMPONENT,
CHANGE_FOCUS_COMPONENT,
UPDATE_CHILDREN,
REASSIGN_PARENT,
SET_SELECTABLE_PARENTS,
Expand Down Expand Up @@ -97,6 +98,10 @@ export const updateComponent = ({
dispatch({ type: SET_SELECTABLE_PARENTS });
};

export const changeFocusComponent = ({ title }) => (dispatch) => {
dispatch({ type: CHANGE_FOCUS_COMPONENT, payload: { title } });
};

// export const exportFiles = ({ components, path }) => (dispatch) => {
// dispatch({
// type: EXPORT_FILES,
Expand Down
94 changes: 55 additions & 39 deletions src/components/KonvaStage.jsx
Original file line number Diff line number Diff line change
@@ -1,12 +1,12 @@
import React, { Component, createRef, Fragment } from 'react';
import React, { Component, createRef } from 'react';
// import PropTypes from 'prop-types';
import {
Stage, Layer, Image, Group, Label, Text, Tag,
Stage, Layer, Image, Group,
} from 'react-konva';
import Konva from 'konva';
import TransformerComponent from './TransformerComponent.jsx';
import Rectangle from './Rectangle.jsx';


class KonvaStage extends Component {
state = {
x: undefined,
Expand All @@ -19,10 +19,6 @@ class KonvaStage extends Component {
this.group = createRef();
}

// Christian - this function causes the expansionPanel of the clicked rect to open
// (and focusedComponent to change, which we don't want)
// could reuse this logic for affecting state of children array
// ADD FOCUS CHILD FUNCTIONALITY HERE
handleStageMouseDown = (e) => {
// clicked on stage - cler selection
if (e.target === e.target.getStage()) {
Expand All @@ -46,11 +42,27 @@ class KonvaStage extends Component {
}
};

// WAS ALREADY COMMENTED OUT
// handleStageDrag = () => {
// // const mainWindowHeight = this.main.current.clientHeight;
// // const mainWindowWidth = this.main.current.clientWidth;
// // const groupX = this.refs.group.attrs.x;
// // const groupY = this.refs.group.attrs.y;

// // const componentX = (mainWindowWidth / 2) - groupX;
// // const componentY = (mainWindowHeight / 2) - groupY;
// // console.log(componentX, componentY);
// }

componentDidMount() {
// this.props.setImage();
}

render() {
const {
components, handleTransform, draggable, scaleX, scaleY, focusComponent,
components, handleTransform, image, draggable, scaleX, scaleY, focusComponent,
} = this.props;
// const { selectedShapeName } = this.state;
const { selectedShapeName } = this.state;

return (
<Stage
Expand All @@ -68,41 +80,45 @@ class KonvaStage extends Component {
ref={(node) => {
this.group = node;
}}
draggable={draggable}
>
{components.map((comp, i) => (
<Fragment key={i}>
<Rectangle
draggable={comp.draggable}
key={i}
componentId={comp.id}
x={comp.position.x}
y={comp.position.y}
width={comp.position.width}
height={comp.position.height}
title={comp.title}
color={comp.color}
handleTransform={handleTransform}
/>
<Label x={comp.position.x} y={comp.position.y}>
<Text
text={`${comp.title},${comp.position.x.toPrecision(
3,
)},${comp.position.y.toPrecision(3)}`}
fontFamily="Calibri"
fontSize={12}
padding={5}
fill="green"
/>
</Label>
</Fragment>
))}
<TransformerComponent focusComponent={focusComponent} />
draggable={draggable}>
<Image image={image} />
{components.map((comp, i) => <Rectangle
draggable={comp.draggable}
selectedShapeName={selectedShapeName}
key={i}
componentId={comp.id}
x={comp.position.x}
y={comp.position.y}
width={comp.position.width}
height={comp.position.height}
title={comp.title}
color={comp.color}
handleTransform={handleTransform}
/>)}
<TransformerComponent
focusComponent={focusComponent}
selectedShapeName={selectedShapeName}
/>
</Group>
</Layer>
</Stage>
);
}
}

// KonvaStage.propTypes = {
// draggable: PropTypes.bool.isRequired,
// components: PropTypes.array.isRequired,
// handleTransform: PropTypes.func.isRequired,
// image: PropTypes.oneOfType([
// PropTypes.string,
// PropTypes.object,
// ]),
// scaleX: PropTypes.number.isRequired,
// scaleY: PropTypes.number.isRequired,
// openExpansionPanel: PropTypes.func.isRequired,
// setImage: PropTypes.func.isRequired,
// focusComponent: PropTypes.object.isRequired,
// };

export default KonvaStage;
43 changes: 29 additions & 14 deletions src/components/LeftColExpansionPanel.jsx
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
import React, { Fragment } from 'react';
import PropTypes from 'prop-types';
// import PropTypes from 'prop-types';
import { withStyles } from '@material-ui/core/styles';
// import ExpansionPanel from '@material-ui/core/ExpansionPanel';
// import ExpansionPanelSummary from '@material-ui/core/ExpansionPanelSummary';
Expand All @@ -14,18 +14,32 @@ import ListItemText from '@material-ui/core/ListItemText';
import IconButton from '@material-ui/core/IconButton';
import Grid from '@material-ui/core/Grid';
import AddIcon from '@material-ui/icons/Add';
import { openExpansionPanel } from '../utils/componentReducer.util';
import { changeFocusChild } from '../actions/components';

const LeftColExpansionPanel = (props) => {
const {
index, classes, focusComponent, component, deleteComponent, addChild,
} = props;
changeFocusComponent } = props;
const { title, id, color } = component;

return (
<div className={classes.root}>
<Grid item xs={12} md={6}>
<List>
<ListItem button component="a">
<Grid item xs={12} md={6} style={{color: 'red'}}>
<List
style={{color: 'red'}}
>
<ListItem button component="a"
// style={
// if (components.find(comp => comp.title === focusComponent.title))
// }
style={{color: 'red'}}
onClick={()=> {
console.log({ title })
changeFocusComponent({ title })

}}
>
<ListItemText
disableTypography
className={classes.light}
Expand All @@ -44,6 +58,7 @@ const LeftColExpansionPanel = (props) => {
onClick={() => {
console.log(title);
addChild( { title } );
changeFocusChild( { title } );
}}
/>
</IconButton>
Expand Down Expand Up @@ -90,15 +105,15 @@ export default withStyles(styles)(LeftColExpansionPanel);
</div>
*/

LeftColExpansionPanel.propTypes = {
classes: PropTypes.object.isRequired,
component: PropTypes.object,
index: PropTypes.number,
focusComponent: PropTypes.object.isRequired,
onExpansionPanelChange: PropTypes.func,
updateComponent: PropTypes.func,
deleteComponent: PropTypes.func,
};
// LeftColExpansionPanel.propTypes = {
// classes: PropTypes.object.isRequired,
// component: PropTypes.object,
// index: PropTypes.number,
// focusComponent: PropTypes.object.isRequired,
// onExpansionPanelChange: PropTypes.func,
// updateComponent: PropTypes.func,
// deleteComponent: PropTypes.func,
// };

function styles(theme) {
return {
Expand Down
5 changes: 5 additions & 0 deletions src/containers/LeftContainer.jsx
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,8 @@ const mapDispatchToProps = dispatch => ({
// openExpansionPanel: component => dispatch(actions.openExpansionPanel(component)),
// deleteAllData: () => dispatch(actions.deleteAllData()),
addChild: ({ title }) => dispatch(actions.addChild({ title })),
changeFocusComponent: ({ title }) => dispatch(actions.changeFocusComponent({ title })),
changeFocusChild: ({ title }) => dispatch(actions.changeFocusChild({ title })),
});

class LeftContainer extends Component {
Expand All @@ -46,6 +48,7 @@ class LeftContainer extends Component {

handleAddComponent = () => {
this.props.addComponent({ title: this.state.componentName });
this.props.changeFocusChild({ title: this.state.componentName })
this.setState({
componentName: '',
});
Expand All @@ -60,6 +63,7 @@ class LeftContainer extends Component {
totalComponents,
classes,
addChild,
changeFocusComponent,
} = this.props;
const { componentName } = this.state;

Expand All @@ -72,6 +76,7 @@ class LeftContainer extends Component {
component={component}
focusComponent={focusComponent}
addChild={addChild}
changeFocusComponent={changeFocusComponent}
/>
));

Expand Down
4 changes: 4 additions & 0 deletions src/reducers/componentReducer.js
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@ import {
ADD_CHILD,
UPDATE_COMPONENT,
DELETE_COMPONENT,
CHANGE_FOCUS_COMPONENT,
UPDATE_CHILDREN,
REASSIGN_PARENT,
SET_SELECTABLE_PARENTS,
Expand All @@ -29,6 +30,7 @@ import {
addChild,
updateComponent,
deleteComponent,
changeFocusComponent,
updateChildren,
reassignParent,
setSelectableP,
Expand Down Expand Up @@ -114,6 +116,8 @@ const componentReducer = (state = initialApplicationState, action) => {
return updateComponent(state, action.payload);
case DELETE_COMPONENT:
return deleteComponent(state, action.payload);
case CHANGE_FOCUS_COMPONENT:
return changeFocusComponent(state, action.payload);
case UPDATE_CHILDREN:
return updateChildren(state, action.payload);
case REASSIGN_PARENT:
Expand Down
10 changes: 10 additions & 0 deletions src/utils/componentReducer.util.js
Original file line number Diff line number Diff line change
Expand Up @@ -159,6 +159,16 @@ export const deleteComponent = (state, { index, id }) => {
};
};

export const changeFocusComponent = (state, { title }) => {

let focusComp = state.components.filter((comp) => {if (comp.title === title) return comp})[0]

return {
...state,
focusComponent: focusComp,
};
};

// Add or remove children
export const updateChildren = (state, { parentIds, childId }) => {
const components = state.components.map((component) => {
Expand Down
Loading