Skip to content

Commit 9c4f6af

Browse files
committed
fixed image upload
1 parent 2b6dae3 commit 9c4f6af

File tree

4 files changed

+38
-26
lines changed

4 files changed

+38
-26
lines changed

src/actions/components.ts

Lines changed: 8 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
import {
2-
ComponentInt, ComponentsInt, PropInt, ChildInt, Action, ApplicationStateInt
2+
ComponentInt, ComponentsInt, PropInt, ChildInt, Action, ApplicationStateInt, LoadInitData, AddComponent
33
} from '../utils/Interfaces.ts';
44

55
import {
@@ -35,14 +35,13 @@ import { loadState } from '../localStorage';
3535
import createFiles from '../utils/createFiles.util.ts';
3636
import createApplicationUtil from '../utils/createApplication.util.ts';
3737

38-
3938
export const changeImagePath = (imageSource: string) => ({
4039
type: CHANGE_IMAGE_SOURCE,
4140
payload: { imageSource },
4241
})
4342

44-
export const loadInitData = () => (dispatch: (arg: Action) => void) => {
45-
loadState().then((data: ApplicationStateInt) => {
43+
export const loadInitData = () => (dispatch: any) => {
44+
loadState().then((data: any) => {
4645
dispatch({
4746
type: LOAD_INIT_DATA,
4847
payload: {
@@ -52,7 +51,7 @@ export const loadInitData = () => (dispatch: (arg: Action) => void) => {
5251
});
5352
};
5453

55-
export const addComponent = ({ title }: { title: string }) => (dispatch: (arg: Action) => void) => {
54+
export const addComponent = ({ title }: { title: string }) => (dispatch: (arg: AddComponent) => void) => {
5655
dispatch({ type: ADD_COMPONENT, payload: { title } });
5756
};
5857

@@ -146,13 +145,13 @@ exportAppBool: boolean;
146145
});
147146

148147
createFiles(components, path, appName, exportAppBool)
149-
.then(dir =>
148+
.then((dir: string) =>
150149
dispatch({
151150
type: EXPORT_FILES_SUCCESS,
152151
payload: { status: true, dir: dir[0] }
153152
})
154153
)
155-
.catch(err =>
154+
.catch((err: string) =>
156155
dispatch({
157156
type: EXPORT_FILES_ERROR,
158157
payload: { status: true, err }
@@ -232,7 +231,7 @@ exportAppBool: boolean;
232231
})
233232
);
234233
})
235-
.catch(err =>
234+
.catch((err: string) =>
236235
dispatch({
237236
type: CREATE_APPLICATION_ERROR,
238237
payload: { status: true, err }
@@ -254,7 +253,7 @@ export const deleteProp = (propId: number) => (dispatch: (arg: Action) => void)
254253
dispatch({ type: DELETE_PROP, payload: propId });
255254
};
256255

257-
export const toggleComponentState = (index: string) => (dispatch: any) => {
256+
export const toggleComponentState = (index: string) => (dispatch: (arg: Action) => void) => {
258257
dispatch({ type: TOGGLE_STATE, payload: index });
259258
};
260259

src/containers/AppContainer.tsx

Lines changed: 14 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 } from '../utils/Interfaces';
1111
import * as actions from '../actions/components';
1212

1313
// ** Used with electron to render
@@ -20,8 +20,8 @@ type Props = {
2020
totalComponents: number;
2121
loading: boolean;
2222
selectableChildren: Array<number>;
23-
loadInitData: () => void;
24-
changeImagePath: () => void;
23+
loadInitData: any;
24+
changeImagePath: any;
2525
changed: boolean;
2626
};
2727

@@ -42,7 +42,9 @@ const mapStateToProps = (store: any) => ({
4242

4343
const mapDispatchToProps = (dispatch: any) => ({
4444
loadInitData: () => dispatch(actions.loadInitData()),
45-
changeImagePath: (imageSource: string) => dispatch(actions.changeImagePath(imageSource)),
45+
// loadInitData: () => {},
46+
changeImagePath: (imageSource: string) =>
47+
dispatch(actions.changeImagePath(imageSource)),
4648
});
4749

4850
class AppContainer extends Component<Props, State> {
@@ -56,12 +58,12 @@ class AppContainer extends Component<Props, State> {
5658
changed: false
5759
};
5860

59-
IPC.on('new-file', (event, file: string) => {
61+
IPC.on('new-file', (event: any, file: string) => {
6062
const image = new window.Image();
6163
image.src = file;
6264
image.onload = () => {
6365
// update state when the image has been uploaded
64-
this.props.changeImagePath(file);
66+
this.props.changeImagePath(image.src);
6567
this.setState({ image });
6668
};
6769
});
@@ -70,11 +72,11 @@ class AppContainer extends Component<Props, State> {
7072
componentDidUpdate(prevProps: Props) {
7173
const { imageSource } = this.props;
7274
const {changed} = this.state;
73-
if (imageSource == '' && changed) {
74-
this.setState({...this.state, image:null, changed:false});
75+
if (imageSource === '' && changed) {
76+
this.setState({image:null, changed:false});
7577

7678
}
77-
else if (imageSource !== prevProps.imageSource) {
79+
else if (imageSource !== prevProps.imageSource && imageSource !== '') {
7880
this.setImage(imageSource);
7981
}
8082
}

src/reducers/componentReducer.ts

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,8 @@
11
import {
22
ComponentInt,
33
ChildInt,
4-
ApplicationStateInt
4+
ApplicationStateInt,
5+
Action
56
} from '../utils/Interfaces';
67

78

@@ -109,7 +110,7 @@ const initialApplicationState: ApplicationStateInt = {
109110
loading: false
110111
};
111112

112-
const componentReducer = (state = initialApplicationState, action: any) => {
113+
const componentReducer = (state = initialApplicationState, action: Action) => {
113114
switch (action.type) {
114115
case LOAD_INIT_DATA:
115116
return {
@@ -144,7 +145,7 @@ const componentReducer = (state = initialApplicationState, action: any) => {
144145
return deleteImage(state, action.payload);
145146
case EXPORT_FILES_SUCCESS:
146147
return exportFilesSuccess(state, action.payload);
147-
case CREATE_APPLICATION_ERROR:
148+
// case CREATE_APPLICATION_ERROR:
148149
case EXPORT_FILES_ERROR:
149150
return exportFilesError(state, action.payload);
150151
case HANDLE_CLOSE:

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)