Skip to content

Commit c17a8cc

Browse files
committed
merged dev changes into comment branch
2 parents b44a267 + 76bb3e8 commit c17a8cc

27 files changed

+833
-648
lines changed

main.js

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -19,9 +19,9 @@ const {
1919
// ** Uncomment below for hot reloading during development **
2020

2121
// below hard-resets the entire electron process so is more of a catch-all in terms of dev mode:
22-
// require('electron-reload')(__dirname, {
23-
// electron: path.join(__dirname, 'node_modules', '.bin', 'electron')
24-
// });
22+
require('electron-reload')(__dirname, {
23+
electron: path.join(__dirname, 'node_modules', '.bin', 'electron')
24+
});
2525

2626
// below loads contents of all active BrowserWindows within electron when the source files are changed.
2727
// ** You'll want to use this one when working in most files other than main.js

package.json

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -83,7 +83,7 @@
8383
]
8484
},
8585
"dependencies": {
86-
"@material-ui/core": "^3.9.3",
86+
"@material-ui/core": "^3.9.4",
8787
"@material-ui/icons": "^2.0.0",
8888
"@types/react": "^16.8.14",
8989
"@types/react-dom": "^16.8.4",
@@ -153,4 +153,4 @@
153153
"style-loader": "^0.20.3",
154154
"typescript": "^2.8.3"
155155
}
156-
}
156+
}

src/App.tsx

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,12 +1,10 @@
11
import React from 'react';
22
import './public/styles/style.css';
33
import AppContainer from './containers/AppContainer';
4-
// import Test from './components/Test';
54

65
const App: React.FC = () => (
76
<div className="app">
87
<AppContainer />
9-
{/* <Test /> */}
108
</div>
119
);
1210

src/actions/actions.ts

Lines changed: 60 additions & 36 deletions
Original file line numberDiff line numberDiff line change
@@ -1,18 +1,12 @@
11
import { createComponent } from '../utils/reducer.util';
2-
import { ComponentState } from '../types/types';
2+
import { ComponentState, ChildState } from '../types/types';
33
import * as types from '../types/actionTypes';
44
import { loadState } from '../localStorage.js';
55
import createFiles from '../utils/createFiles.util';
66
import createApplicationUtil from '../utils/createApplication.util';
77

88
// ** ACTION CREATORS ** \\
99

10-
// ** openExpansionPanel just takes the id of the current component and toggles the expanded value to either true or false
11-
export const toggleExpansionPanel = (id: number) => ({
12-
type: types.TOGGLE_EXPANSION_PANEL,
13-
payload: { id },
14-
});
15-
1610
// ! Redux thunk action
1711
export const loadInitData = () => {
1812
return (dispatch: any) => {
@@ -25,23 +19,32 @@ export const loadInitData = () => {
2519
}
2620
};
2721

22+
// ** openExpansionPanel just takes the id of the current component and toggles the expanded value to either true or false
23+
export const toggleExpansionPanel = (id: number) => ({
24+
type: types.TOGGLE_EXPANSION_PANEL,
25+
payload: { id },
26+
});
27+
28+
export const changeImagePath = (imageSource: string) => ({
29+
type: types.CHANGE_IMAGE_SOURCE,
30+
payload: { imageSource },
31+
})
32+
2833
// ! Redux thunk action
2934
// ** addComponent waits for createComponent to dispatch then createComponent returns a promise with the new component object created
3035
export const addComponent = (title: string) => {
3136
return (dispatch, getState) => {
3237
// ** grab state from our reducer to see how many components currently exist in our array
33-
const appComponentState = getState().application.components;
34-
// ** Conditionally assigning a variable componentId. If any components exist in the array find the last component's id and increment it else initialize at 1.
35-
const componentId = appComponentState.length ? appComponentState[appComponentState.length - 1].id + 1 : 1;
36-
dispatch(createComponent(componentId, title, appComponentState))
38+
const app = getState().application;
39+
const componentId = app.nextComponentId;
40+
const components = app.components;
41+
dispatch(createComponent(componentId, title, components))
3742
.then((component: ComponentState) => {
38-
// ** the dispatch to createComponent will return a promise. The promise will return either the new createdComponent or just the generic state object (which will have an id of 0 by default)
39-
if (component.id !== 0) {
40-
dispatch({
41-
type: types.ADD_COMPONENT,
42-
payload: { component }
43-
});
44-
}
43+
// ** the dispatch to createComponent will return a promise. The promise will return either the new createdComponent.
44+
dispatch({
45+
type: types.ADD_COMPONENT,
46+
payload: { component }
47+
});
4548
})
4649
.catch((err: Error) => console.log(err));
4750
};
@@ -57,26 +60,47 @@ export const updateComponent = (id: number, update: {}) => ({
5760
});
5861

5962
// ** deleteComponent deletes a component from our global state component array
60-
export const deleteComponent = (id: number) => ({
61-
type: types.DELETE_COMPONENT,
62-
payload: { id }
63-
});
64-
65-
export const addChild = ({
66-
title,
67-
childType,
68-
HTMLInfo,
69-
}: {
70-
title: string;
71-
childType: string;
72-
HTMLInfo: object;
73-
}) => (dispatch: any) => {
74-
dispatch({ type: types.ADD_CHILD, payload: { title, childType, HTMLInfo } });
63+
export const deleteComponent = (id: number) => {
64+
return (dispatch, getState) => {
65+
const appComponents = getState().application.components;
66+
appComponents.forEach((parent: ComponentState) => {
67+
parent.children
68+
.filter((child: ChildState) => child.childComponentId === id)
69+
.forEach((child: ChildState) => {
70+
dispatch({
71+
type: types.DELETE_CHILD,
72+
payload: {
73+
parentId: parent.id,
74+
childId: child.childId,
75+
// calledFromDeleteComponent: true,
76+
},
77+
});
78+
});
79+
});
80+
dispatch({
81+
type: types.DELETE_COMPONENT,
82+
payload: { id }
83+
});
84+
}
7585
};
7686

77-
export const deleteChild = ({}) => (dispatch: any) => {
78-
// with no payload, it will delete focusd child
79-
dispatch({ type: types.DELETE_CHILD, payload: {} });
87+
export const addChild = (title: string, childType: string, HTMLInfo?: {}) => ({
88+
type: types.ADD_CHILD,
89+
payload: { title, childType, HTMLInfo }
90+
});
91+
92+
export const deleteChild = (id: number) => {
93+
return (dispatch, getState) => {
94+
const parent = getState().application.focusComponent;
95+
const child = parent.children.find((currentChild: ChildState) => id === currentChild.childComponentId);
96+
dispatch({
97+
type: types.DELETE_CHILD,
98+
payload: {
99+
parentId: parent.id,
100+
childId: child.childId,
101+
},
102+
});
103+
}
80104
};
81105

82106
export const changeFocusComponent = ({ title }: { title: string }) => (dispatch: any) => {

src/components/CodePreview.tsx

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,21 +1,21 @@
11
import React, { Component } from 'react';
22
import { format } from 'prettier';
33
import componentRender from '../utils/componentRender.util';
4-
import { ComponentInt, ComponentsInt } from '../utils/Interfaces';
4+
import { ComponentState } from '../types/types';
55
/** ** SortCHildren will be fixed , dont XXX the file *** */
66
// import SortChildren from './SortChildren.jsx';
77
import SyntaxHighlighter from 'react-syntax-highlighter';
88
import { hybrid } from 'react-syntax-highlighter/dist/styles/hljs/';
99

1010
type Props = {
11-
focusComponent: ComponentInt;
12-
components: ComponentsInt;
11+
focusComponent: ComponentState;
12+
components: Array<ComponentState>;
1313
};
1414

1515
class CodePreview extends Component<Props> {
1616
render(): JSX.Element {
17-
const focusComponent: ComponentInt = this.props.focusComponent;
18-
const components: ComponentsInt = this.props.components;
17+
const focusComponent: ComponentState = this.props.focusComponent;
18+
const components: Array<ComponentState> = this.props.components;
1919

2020
return (
2121
<div

src/components/DataTable.tsx

Lines changed: 1 addition & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -1,13 +1,5 @@
11
import React from 'react';
2-
import { withStyles } from '@material-ui/core/styles';
3-
import Table from '@material-ui/core/Table';
4-
import TableBody from '@material-ui/core/TableBody';
5-
import TableCell from '@material-ui/core/TableCell';
6-
import TableHead from '@material-ui/core/TableHead';
7-
import TableRow from '@material-ui/core/TableRow';
8-
import Paper from '@material-ui/core/Paper';
9-
import DeleteIcon from '@material-ui/icons/Delete';
10-
import { IconButton } from '@material-ui/core';
2+
import { withStyles, Table, TableBody, TableCell, TableHead, TableRow, Paper, DeleteIcon, IconButton } from '../utils/material.util';
113

124
const styles = (theme: any) => ({
135
root: {

src/components/Dropzone.tsx

Lines changed: 8 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,12 +1,16 @@
1-
import React from "react";
1+
import React, { Component } from "react";
22
import Dropzone from "react-dropzone";
33

44
const IPC = require('electron').ipcRenderer;
55

6-
class FileDrop extends React.Component {
7-
onDrop = (file) => {
6+
type Props = {
7+
changeImagePath: any;
8+
}
9+
10+
class FileDrop extends Component<Props> {
11+
onDrop = (file: any) => {
812
const { path } = file[0];
9-
console.log(path);
13+
this.props.changeImagePath(path);
1014
};
1115

1216
render() {

src/components/GrandchildRectangle.tsx

Lines changed: 19 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -1,12 +1,14 @@
11
import React, { Component } from 'react';
22
import { Rect, Group } from 'react-konva';
33
// Konva = JavaScript library for drawing complex canvas graphics using React
4-
import { ComponentsInt, ComponentInt, ChildInt } from '../utils/interfaces';
4+
import { ComponentState, ChildState } from '../types/types';
55

66
// ** this file might restrict you from making the child of a component one of its references - prevents circular references
77
// Component does enable nesting of arbitrary numbers of child components, but it does NOT prevent circular references
88
// Only check for that is in LeftColExpansionPanel on or around line 138
9-
interface PropsInt {
9+
10+
11+
type Props = {
1012
x: number;
1113
y: number;
1214
scaleX: number;
@@ -19,33 +21,36 @@ interface PropsInt {
1921
height: number;
2022
title: string;
2123
focusChild: any;
22-
components: ComponentsInt;
24+
components: ComponentState[];
2325
draggable: boolean;
2426
blockSnapSize: number;
2527
childType: string;
2628
imageSource: string;
2729
handleTransform: any;
2830
}
2931

30-
interface StateInt {
31-
image: any;
32+
type State = {
33+
image: HTMLImageElement | null;
3234
}
3335

34-
class GrandchildRectangle extends Component<PropsInt, StateInt> {
35-
state = {
36-
image: null
37-
};
36+
class GrandchildRectangle extends Component<Props, State> {
37+
constructor(props: Props) {
38+
super(props);
39+
this.state = {
40+
image: null
41+
};
42+
}
3843

3944
getComponentColor(componentId: number) {
4045
const color = this.props.components.find(
41-
(comp: ComponentInt) => comp.id === componentId
46+
(comp: ComponentState) => comp.id === componentId
4247
).color;
4348
return color;
4449
}
4550

4651
getPseudoChild() {
4752
return this.props.components.find(
48-
(comp: ComponentInt) => comp.id === this.props.childComponentId
53+
(comp: ComponentState) => comp.id === this.props.childComponentId
4954
);
5055
}
5156

@@ -118,9 +123,9 @@ class GrandchildRectangle extends Component<PropsInt, StateInt> {
118123
/>
119124
{childType === 'COMP' &&
120125
components
121-
.find((comp: ComponentInt) => comp.title === childComponentName)
122-
.children.filter((child: ChildInt) => child.childId !== -1)
123-
.map((grandchild: ChildInt, i: number) => (
126+
.find((comp: ComponentState) => comp.title === childComponentName)
127+
.children.filter((child: ChildState) => child.childId !== -1)
128+
.map((grandchild: ChildState, i: number) => (
124129
<GrandchildRectangle
125130
key={i}
126131
components={components}

src/components/HTMLComponentPanel.tsx

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -32,7 +32,7 @@ class HTMLComponentPanel extends Component<PropsInt, StateInt> {
3232
};
3333

3434
handleCreateHTMLChild = (type: string) => {
35-
this.props.addChild({ title: type, childType: type, HTMLInfo: {} });
35+
this.props.addChild(type, type, {});
3636
};
3737

3838
render() {

src/components/HtmlAttr.tsx

Lines changed: 16 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -1,25 +1,20 @@
11
import React, { Component } from 'react';
22
import { connect } from 'react-redux';
3-
import { withStyles } from '@material-ui/core/styles';
4-
import Grid from '@material-ui/core/Grid';
5-
import TextField from '@material-ui/core/TextField';
6-
import SaveIcon from '@material-ui/icons/Save';
7-
import Paper from '@material-ui/core/Paper';
8-
import Fab from '@material-ui/core/Fab';
9-
import { updateHtmlAttr } from '../actions/actions.ts';
10-
import { HTMLelements } from '../utils/htmlElements.util.ts';
11-
import { ComponentInt, ChildInt } from '../utils/interfaces.ts';
3+
import { withStyles, Grid, TextField, SaveIcon, Paper, Fab } from '../utils/material.util';
4+
import { updateHtmlAttr } from '../actions/actions';
5+
import { HTMLelements } from '../utils/htmlElements.util';
6+
import { ComponentState, ChildState } from '../types/types';
127

13-
interface PropsInt {
8+
type Props = {
149
updateHtmlAttr: any;
15-
focusComponent: ComponentInt;
10+
focusComponent: ComponentState;
1611
classes: any;
1712
deleteProp: any;
1813
addProp: any;
19-
focusChild: ChildInt;
14+
focusChild: ChildState;
2015
}
2116

22-
interface StateInt {}
17+
type State = { }
2318

2419
const styles = (theme: any): any => ({
2520
root: {
@@ -49,11 +44,14 @@ const mapStateToProps = (store: any) => ({
4944
focusChild: store.application.focusChild,
5045
});
5146

52-
class HtmlAttr extends Component<PropsInt, StateInt> {
53-
state = HTMLelements[this.props.focusChild.htmlElement].attributes.reduce((acc, attr) => {
54-
acc[attr] = '';
55-
return acc;
56-
}, {});
47+
class HtmlAttr extends Component<Props, State> {
48+
constructor(props: Props) {
49+
super(props);
50+
this.state = HTMLelements[this.props.focusChild.htmlElement].attributes.reduce((acc, attr) => {
51+
acc[attr] = '';
52+
return acc;
53+
}, {});
54+
}
5755

5856
handleSave = (attr: string) => {
5957
this.props.updateHtmlAttr({ attr, value: this.state[attr] });

0 commit comments

Comments
 (0)