Skip to content

Commit f66db2b

Browse files
Merge pull request #11 from ReacType-2-0/redux-image
Image support added in Redux
2 parents 87ce3ca + 74eae90 commit f66db2b

20 files changed

+410
-339
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/actions/actions.ts

Lines changed: 11 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -7,12 +7,6 @@ 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,6 +19,17 @@ 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) => {

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/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: 17 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -1,11 +1,11 @@
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

8-
interface PropsInt {
8+
type Props = {
99
x: number;
1010
y: number;
1111
scaleX: number;
@@ -18,33 +18,36 @@ interface PropsInt {
1818
height: number;
1919
title: string;
2020
focusChild: any;
21-
components: ComponentsInt;
21+
components: ComponentState[];
2222
draggable: boolean;
2323
blockSnapSize: number;
2424
childType: string;
2525
imageSource: string;
2626
handleTransform: any;
2727
}
2828

29-
interface StateInt {
30-
image: any;
29+
type State = {
30+
image: HTMLImageElement | null;
3131
}
3232

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

3841
getComponentColor(componentId: number) {
3942
const color = this.props.components.find(
40-
(comp: ComponentInt) => comp.id === componentId
43+
(comp: ComponentState) => comp.id === componentId
4144
).color;
4245
return color;
4346
}
4447

4548
getPseudoChild() {
4649
return this.props.components.find(
47-
(comp: ComponentInt) => comp.id === this.props.childComponentId
50+
(comp: ComponentState) => comp.id === this.props.childComponentId
4851
);
4952
}
5053

@@ -117,9 +120,9 @@ class GrandchildRectangle extends Component<PropsInt, StateInt> {
117120
/>
118121
{childType === 'COMP' &&
119122
components
120-
.find((comp: ComponentInt) => comp.title === childComponentName)
121-
.children.filter((child: ChildInt) => child.childId !== -1)
122-
.map((grandchild: ChildInt, i: number) => (
123+
.find((comp: ComponentState) => comp.title === childComponentName)
124+
.children.filter((child: ChildState) => child.childId !== -1)
125+
.map((grandchild: ChildState, i: number) => (
123126
<GrandchildRectangle
124127
key={i}
125128
components={components}

src/components/HtmlAttr.tsx

Lines changed: 15 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -6,20 +6,20 @@ import TextField from '@material-ui/core/TextField';
66
import SaveIcon from '@material-ui/icons/Save';
77
import Paper from '@material-ui/core/Paper';
88
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';
9+
import { updateHtmlAttr } from '../actions/actions';
10+
import { HTMLelements } from '../utils/htmlElements.util';
11+
import { ComponentState, ChildState } from '../types/types';
1212

13-
interface PropsInt {
13+
type Props = {
1414
updateHtmlAttr: any;
15-
focusComponent: ComponentInt;
15+
focusComponent: ComponentState;
1616
classes: any;
1717
deleteProp: any;
1818
addProp: any;
19-
focusChild: ChildInt;
19+
focusChild: ChildState;
2020
}
2121

22-
interface StateInt {}
22+
type State = { }
2323

2424
const styles = (theme: any): any => ({
2525
root: {
@@ -49,11 +49,14 @@ const mapStateToProps = (store: any) => ({
4949
focusChild: store.application.focusChild,
5050
});
5151

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-
}, {});
52+
class HtmlAttr extends Component<Props, State> {
53+
constructor(props: Props) {
54+
super(props);
55+
this.state = HTMLelements[this.props.focusChild.htmlElement].attributes.reduce((acc, attr) => {
56+
acc[attr] = '';
57+
return acc;
58+
}, {});
59+
}
5760

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

0 commit comments

Comments
 (0)