Skip to content

Commit 6745d7c

Browse files
authored
Merge pull request #13 from tonyito/mvp
Corrected bug in image upload function
2 parents f83af90 + a1e16a2 commit 6745d7c

File tree

7 files changed

+49
-38
lines changed

7 files changed

+49
-38
lines changed

src/actions/components.ts

Lines changed: 8 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,5 @@
11
import {
2-
ComponentInt,
3-
ComponentsInt,
4-
PropInt,
5-
ChildInt,
6-
Action,
7-
ApplicationStateInt
2+
ComponentInt, ComponentsInt, PropInt, ChildInt, Action, ApplicationStateInt, LoadInitData, AddComponent
83
} from '../utils/Interfaces.ts';
94

105
import {
@@ -46,8 +41,7 @@ export const changeImagePath = (imageSource: string) => ({
4641
});
4742

4843
export const loadInitData = () => (dispatch: (arg: Action) => void) => {
49-
loadState().then((data: ApplicationStateInt) => {
50-
console.log('data.workspace', data.workspace);
44+
loadState().then((data: any) => {
5145
dispatch({
5246
type: LOAD_INIT_DATA,
5347
payload: {
@@ -57,7 +51,7 @@ export const loadInitData = () => (dispatch: (arg: Action) => void) => {
5751
});
5852
};
5953

60-
export const addComponent = ({ title }: { title: string }) => (dispatch: (arg: Action) => void) => {
54+
export const addComponent = ({ title }: { title: string }) => (dispatch: (arg: AddComponent) => void) => {
6155
dispatch({ type: ADD_COMPONENT, payload: { title } });
6256
};
6357

@@ -154,13 +148,13 @@ export const exportFiles = ({
154148
});
155149

156150
createFiles(components, path, appName, exportAppBool)
157-
.then(dir =>
151+
.then((dir: string) =>
158152
dispatch({
159153
type: EXPORT_FILES_SUCCESS,
160154
payload: { status: true, dir: dir[0] }
161155
})
162156
)
163-
.catch(err =>
157+
.catch((err: string) =>
164158
dispatch({
165159
type: EXPORT_FILES_ERROR,
166160
payload: { status: true, err }
@@ -235,7 +229,7 @@ export const createApplication = ({
235229
})
236230
);
237231
})
238-
.catch(err =>
232+
.catch((err: string) =>
239233
dispatch({
240234
type: CREATE_APPLICATION_ERROR,
241235
payload: { status: true, err }
@@ -257,11 +251,11 @@ export const deleteProp = (propId: number) => (dispatch: (arg: Action) => void)
257251
dispatch({ type: DELETE_PROP, payload: propId });
258252
};
259253

260-
export const toggleComponentState = (id: string) => (dispatch: any) => {
254+
export const toggleComponentState = (id: string) => (dispatch: (arg: Action) => void) => {
261255
dispatch({ type: TOGGLE_STATE, payload: id });
262256
};
263257

264-
export const toggleComponentClass = (id: string) => (dispatch: any) => {
258+
export const toggleComponentClass = (id: string) => (dispatch: (arg: Action) => void) => {
265259
dispatch({ type: TOGGLE_CLASS, payload: id });
266260
};
267261

src/components/App.tsx

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
import React from 'react';
22
import '../public/styles/style.css';
3-
import AppContainer from '../containers/AppContainer.tsx';
3+
import AppContainer from '../containers/AppContainer';
44

55
export const App: React.SFC = () => (
66
<div className="app">

src/containers/AppContainer.tsx

Lines changed: 13 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -3,11 +3,11 @@ import { connect } from 'react-redux';
33
import { MuiThemeProvider } from '@material-ui/core/styles';
44
import LinearProgress from '@material-ui/core/LinearProgress';
55

6-
import LeftContainer from './LeftContainer.tsx';
7-
import MainContainer from './MainContainer.tsx';
8-
import theme from '../components/theme.ts';
6+
import LeftContainer from './LeftContainer';
7+
import MainContainer from './MainContainer';
8+
import theme from '../components/theme';
99
// import { loadInitData } from '../actions/components.ts';
10-
import { ComponentInt, ComponentsInt } from '../utils/Interfaces.ts';
10+
import { ComponentInt, ComponentsInt, Action } from '../utils/Interfaces';
1111
import * as actions from '../actions/components';
1212

1313
// ** Used with electron to render
@@ -22,7 +22,6 @@ type Props = {
2222
selectableChildren: Array<number>;
2323
loadInitData: () => void;
2424
changeImagePath: () => void;
25-
changed: boolean;
2625
};
2726

2827
type State = {
@@ -40,9 +39,11 @@ const mapStateToProps = (store: any) => ({
4039
selectableChildren: store.workspace.selectableChildren
4140
});
4241

43-
const mapDispatchToProps = (dispatch: any) => ({
42+
const mapDispatchToProps = (dispatch: (arg: a) => void) => ({
4443
loadInitData: () => dispatch(actions.loadInitData()),
45-
changeImagePath: (imageSource: string) => dispatch(actions.changeImagePath(imageSource)),
44+
// loadInitData: () => {},
45+
changeImagePath: (imageSource: string) =>
46+
dispatch(actions.changeImagePath(imageSource)),
4647
});
4748

4849
class AppContainer extends Component<Props, State> {
@@ -56,12 +57,12 @@ class AppContainer extends Component<Props, State> {
5657
changed: false
5758
};
5859

59-
IPC.on('new-file', (event, file: string) => {
60+
IPC.on('new-file', (event: any, file: string) => {
6061
const image = new window.Image();
6162
image.src = file;
6263
image.onload = () => {
6364
// update state when the image has been uploaded
64-
this.props.changeImagePath(file);
65+
this.props.changeImagePath(image.src);
6566
this.setState({ image });
6667
};
6768
});
@@ -70,11 +71,11 @@ class AppContainer extends Component<Props, State> {
7071
componentDidUpdate(prevProps: Props) {
7172
const { imageSource } = this.props;
7273
const {changed} = this.state;
73-
if (imageSource == '' && changed) {
74-
this.setState({...this.state, image:null, changed:false});
74+
if (imageSource === '' && changed) {
75+
this.setState({image:null, changed:false});
7576

7677
}
77-
else if (imageSource !== prevProps.imageSource) {
78+
else if (imageSource !== prevProps.imageSource && imageSource !== '') {
7879
this.setImage(imageSource);
7980
}
8081
}

src/containers/MainContainer.tsx

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -4,23 +4,22 @@
44
import React, { Component } from "react";
55
import { connect } from "react-redux";
66
import { MuiThemeProvider } from "@material-ui/core/styles";
7-
import BottomPanel from "../components/BottomPanel.tsx";
8-
import theme from "../components/theme.ts";
7+
import BottomPanel from "../components/BottomPanel";
8+
import theme from "../components/theme";
99
import {
1010
handleTransform,
1111
changeFocusChild,
1212
changeComponentFocusChild,
1313
deleteChild
14-
} from "../actions/components.ts";
15-
import KonvaStage from "../components/KonvaStage.tsx";
16-
import { ComponentInt, ComponentsInt } from "../utils/Interfaces.ts";
14+
} from "../actions/components";
15+
import KonvaStage from "../components/KonvaStage";
16+
import { ComponentInt, ComponentsInt } from "../utils/Interfaces";
1717
import * as actions from '../actions/components';
1818

1919
interface PropsInt {
2020
image: HTMLImageElement | null;
2121
components: ComponentsInt;
2222
focusComponent: ComponentInt;
23-
selectableChildren: Array<number>;
2423
classes: any;
2524
addComponent: any;
2625
addChild: any;
@@ -34,6 +33,7 @@ interface PropsInt {
3433
focusChild: any;
3534
changeComponentFocusChild: any;
3635
deleteChild: any;
36+
imageSource: string;
3737
}
3838

3939
interface StateInt {

src/reducers/componentReducer.ts

Lines changed: 8 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,10 @@
1-
import { ComponentInt, ChildInt, ApplicationStateInt } from '../utils/Interfaces';
1+
import {
2+
ComponentInt,
3+
ChildInt,
4+
ApplicationStateInt,
5+
Action
6+
} from '../utils/Interfaces';
7+
28

39
import {
410
LOAD_INIT_DATA,
@@ -105,7 +111,7 @@ const initialApplicationState: ApplicationStateInt = {
105111
loading: false
106112
};
107113

108-
const componentReducer = (state = initialApplicationState, action: any) => {
114+
const componentReducer = (state = initialApplicationState, action: Action) => {
109115
switch (action.type) {
110116
case LOAD_INIT_DATA:
111117
return {

src/reducers/index.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
import { combineReducers } from 'redux';
22

3-
import componentReducer from './componentReducer.ts';
3+
import componentReducer from './componentReducer';
44

55
const reducers = combineReducers({
66
workspace: componentReducer,

src/utils/Interfaces.ts

Lines changed: 12 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -44,7 +44,7 @@ export interface ComponentInt {
4444
export interface ComponentsInt extends Array<ComponentInt> {}
4545

4646
export interface ApplicationStateInt {
47-
imageSource: String;
47+
imageSource: string;
4848
totalComponents: number;
4949
nextId: number;
5050
successOpen: boolean;
@@ -61,5 +61,15 @@ export interface ApplicationStateInt {
6161

6262
export interface Action {
6363
type: string;
64-
payload: object;
64+
payload?: any;
6565
}
66+
67+
export interface LoadInitData {
68+
type: string;
69+
payload: { data: ApplicationStateInt | object }
70+
}
71+
72+
export interface AddComponent {
73+
type: string;
74+
payload: { title : string }
75+
}

0 commit comments

Comments
 (0)