Skip to content

Commit 5612573

Browse files
committed
Image upload button added but no functionality
1 parent c731709 commit 5612573

File tree

6 files changed

+61
-18
lines changed

6 files changed

+61
-18
lines changed

src/actionTypes/index.js

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -26,4 +26,5 @@ export const ADD_PROP = 'ADD_PROP';
2626
export const DELETE_ALL_DATA = 'DELETE_ALL_DATA';
2727
export const CHANGE_IMAGE_PATH = 'CHANGE_IMAGE_PATH';
2828
export const UPDATE_HTML_ATTR = 'UPDATE_HTML_ATTR';
29-
export const UPDATE_CHILDREN_SORT = 'UPDATE_CHILDREN_SORT'
29+
export const UPDATE_CHILDREN_SORT = 'UPDATE_CHILDREN_SORT';
30+
export const CHANGE_IMAGE_SOURCE = 'CHANGE_IMAGE_SOURCE';

src/actions/components.ts

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -25,12 +25,18 @@ import {
2525
DELETE_ALL_DATA,
2626
UPDATE_HTML_ATTR,
2727
UPDATE_CHILDREN_SORT,
28+
CHANGE_IMAGE_SOURCE
2829
} from '../actionTypes/index.js';
2930

3031
import { loadState } from '../localStorage';
3132
import createFiles from '../utils/createFiles.util.ts';
3233
import createApplicationUtil from '../utils/createApplication.util.ts';
3334

35+
export const changeImagePath = (imageSource: string) => ({
36+
type: CHANGE_IMAGE_SOURCE,
37+
payload: { imageSource },
38+
})
39+
3440
export const loadInitData = () => (dispatch: any) => {
3541
loadState().then((data: any) => dispatch({
3642
type: LOAD_INIT_DATA,

src/containers/AppContainer.tsx

Lines changed: 22 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -1,14 +1,17 @@
1-
import React, { Component } from "react";
2-
import { connect } from "react-redux";
3-
import { MuiThemeProvider } from "@material-ui/core/styles";
4-
import LinearProgress from "@material-ui/core/LinearProgress";
5-
import LeftContainer from "./LeftContainer.tsx";
6-
import MainContainer from "./MainContainer.tsx";
7-
import theme from "../components/theme.ts";
8-
import { loadInitData } from "../actions/components.ts";
9-
import { ComponentInt, ComponentsInt } from "../utils/Interfaces.ts";
1+
import React, { Component } from 'react';
2+
import { connect } from 'react-redux';
3+
import { MuiThemeProvider } from '@material-ui/core/styles';
4+
import LinearProgress from '@material-ui/core/LinearProgress';
5+
import LeftContainer from './LeftContainer.tsx';
6+
import MainContainer from './MainContainer.tsx';
7+
import theme from '../components/theme.ts';
8+
import { loadInitData } from '../actions/components.ts';
9+
import { ComponentInt, ComponentsInt } from '../utils/Interfaces.ts';
10+
import * as actions from '../actions/components';
11+
1012

1113
type Props = {
14+
imageSource: string;
1215
components: ComponentsInt;
1316
focusComponent: ComponentInt;
1417
totalComponents: number;
@@ -18,14 +21,19 @@ type Props = {
1821
};
1922

2023
const mapStateToProps = (store: any) => ({
24+
imageSource: store.workspace.imageSource,
2125
components: store.workspace.components,
2226
totalComponents: store.workspace.totalComponents,
2327
focusComponent: store.workspace.focusComponent,
2428
loading: store.workspace.loading,
2529
selectableChildren: store.workspace.selectableChildren
2630
});
2731

28-
const mapDispatchToProps = { loadInitData };
32+
const mapDispatchToProps = (dispatch: any) => ({
33+
loadInitData,
34+
//CHECK
35+
changeImagePath: (imageSource: string) => dispatch(actions.changeImagePath(imageSource)),
36+
});
2937

3038
class AppContainer extends Component<Props> {
3139
state = {
@@ -61,9 +69,9 @@ class AppContainer extends Component<Props> {
6169
{loading ? (
6270
<div
6371
style={{
64-
alignSelf: "flex-end",
65-
position: "fixed",
66-
width: "100%"
72+
alignSelf: 'flex-end',
73+
position: 'fixed',
74+
width: '100%'
6775
}}
6876
>
6977
<LinearProgress color="secondary" />
@@ -75,7 +83,4 @@ class AppContainer extends Component<Props> {
7583
}
7684
}
7785

78-
export default connect(
79-
mapStateToProps,
80-
mapDispatchToProps
81-
)(AppContainer);
86+
export default connect(mapStateToProps, mapDispatchToProps)(AppContainer);

src/containers/LeftContainer.tsx

Lines changed: 29 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -21,6 +21,7 @@ import cloneDeep from "../utils/cloneDeep.ts";
2121
const IPC = require("electron").ipcRenderer;
2222

2323
interface PropsInt {
24+
imageSource: string;
2425
components: ComponentsInt;
2526
focusComponent: ComponentInt;
2627
selectableChildren: Array<number>;
@@ -156,6 +157,7 @@ class LeftContainer extends Component<PropsInt, StateInt> {
156157
};
157158

158159
chooseAppDir = () => IPC.send("choose_app_dir");
160+
addImage = () => IPC.send('update-file');
159161

160162
showGenerateAppModal = () => {
161163
const { closeModal, chooseGenOptions } = this;
@@ -194,6 +196,7 @@ class LeftContainer extends Component<PropsInt, StateInt> {
194196

195197
render(): JSX.Element {
196198
const {
199+
imageSource,
197200
components,
198201
deleteComponent,
199202
focusComponent,
@@ -222,6 +225,7 @@ class LeftContainer extends Component<PropsInt, StateInt> {
222225
components={components}
223226
/>
224227
));
228+
const { addImage } = this;
225229

226230
return (
227231
<div className="column left">
@@ -292,6 +296,31 @@ class LeftContainer extends Component<PropsInt, StateInt> {
292296
flexDirection: "column"
293297
}}
294298
>
299+
{
300+
imageSource ? (
301+
<Button
302+
aria-label="Remove Image"
303+
variant="contained"
304+
fullWidth
305+
onClick={clearImage}
306+
className={classes.clearButton}
307+
style={{ borderRadius: 0, top: 0, backgroundColor: '#dc004e', color: '#fff' }}
308+
>
309+
Remove Image
310+
</Button>
311+
) : (
312+
<Button
313+
aria-label="Upload Image"
314+
variant="contained"
315+
fullWidth
316+
onClick={addImage}
317+
className={classes.clearButton}
318+
style={{ borderRadius: 0, top: 0, backgroundColor: '#dc004e', color: '#fff' }}
319+
>
320+
Upload Image
321+
</Button>
322+
)
323+
}
295324
<Button
296325
color="secondary"
297326
aria-label="Delete All"

src/reducers/componentReducer.ts

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -85,6 +85,7 @@ const initialApplicationFocusChild: ChildInt = {
8585
};
8686

8787
const initialApplicationState: ApplicationStateInt = {
88+
imageSource: '',
8889
totalComponents: 1,
8990
nextId: 2,
9091
successOpen: false,

src/utils/Interfaces.ts

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -43,6 +43,7 @@ export interface ComponentInt {
4343
export interface ComponentsInt extends Array<ComponentInt> {}
4444

4545
export interface ApplicationStateInt {
46+
imageSource: String;
4647
totalComponents: number;
4748
nextId: number;
4849
successOpen: boolean;

0 commit comments

Comments
 (0)