Skip to content

Commit 9fa05dc

Browse files
committed
Some more broken functionality
1 parent 5612573 commit 9fa05dc

File tree

5 files changed

+74
-16
lines changed

5 files changed

+74
-16
lines changed

src/actions/components.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -34,7 +34,7 @@ import createApplicationUtil from '../utils/createApplication.util.ts';
3434

3535
export const changeImagePath = (imageSource: string) => ({
3636
type: CHANGE_IMAGE_SOURCE,
37-
payload: { imageSource },
37+
payload: imageSource,
3838
})
3939

4040
export const loadInitData = () => (dispatch: any) => {

src/containers/AppContainer.tsx

Lines changed: 52 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,8 @@ import { loadInitData } from '../actions/components.ts';
99
import { ComponentInt, ComponentsInt } from '../utils/Interfaces.ts';
1010
import * as actions from '../actions/components';
1111

12+
// ** Used with electron to render
13+
const IPC = require('electron').ipcRenderer;
1214

1315
type Props = {
1416
imageSource: string;
@@ -18,8 +20,14 @@ type Props = {
1820
loading: boolean;
1921
selectableChildren: Array<number>;
2022
loadInitData: any;
23+
changeImagePath: any;
2124
};
2225

26+
type State = {
27+
image: HTMLImageElement | null;
28+
width: number;
29+
}
30+
2331
const mapStateToProps = (store: any) => ({
2432
imageSource: store.workspace.imageSource,
2533
components: store.workspace.components,
@@ -31,14 +39,50 @@ const mapStateToProps = (store: any) => ({
3139

3240
const mapDispatchToProps = (dispatch: any) => ({
3341
loadInitData,
34-
//CHECK
3542
changeImagePath: (imageSource: string) => dispatch(actions.changeImagePath(imageSource)),
3643
});
3744

38-
class AppContainer extends Component<Props> {
39-
state = {
40-
width: 25,
41-
rightColumnOpen: true
45+
class AppContainer extends Component<Props, State> {
46+
47+
constructor(props: Props) {
48+
super(props);
49+
// ** state here to create a collapsable right column where bottom panel currently lives
50+
this.state = {
51+
image: null,
52+
width: 25,
53+
};
54+
55+
IPC.on('new-file', (event, file: string) => {
56+
const image = new window.Image();
57+
image.src = file;
58+
image.onload = () => {
59+
// update state when the image has been uploaded
60+
this.props.changeImagePath(file);
61+
this.setState({ image });
62+
};
63+
});
64+
}
65+
66+
// state = {
67+
// width: 25,
68+
// rightColumnOpen: true
69+
// };
70+
componentDidUpdate(prevProps: Props) {
71+
const { imageSource } = this.props;
72+
if (imageSource !== prevProps.imageSource) {
73+
this.setImage(imageSource);
74+
}
75+
}
76+
77+
setImage = (imageSource: string) => {
78+
let image: HTMLImageElement;
79+
image = new window.Image();
80+
image.src = imageSource;
81+
image.onload = () => {
82+
// setState will redraw layer
83+
// because "image" property is changed
84+
this.setState({ image });
85+
};
4286
};
4387

4488
componentDidMount() {
@@ -64,8 +108,10 @@ class AppContainer extends Component<Props> {
64108
totalComponents={totalComponents}
65109
focusComponent={focusComponent}
66110
selectableChildren={selectableChildren}
111+
setImage={this.setImage}
67112
/>
68-
<MainContainer components={components} />
113+
<MainContainer components={components} image={this.state.image}
114+
imageSource={this.props.imageSource}/>
69115
{loading ? (
70116
<div
71117
style={{

src/containers/LeftContainer.tsx

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -302,7 +302,7 @@ class LeftContainer extends Component<PropsInt, StateInt> {
302302
aria-label="Remove Image"
303303
variant="contained"
304304
fullWidth
305-
onClick={clearImage}
305+
onClick={() => {}}
306306
className={classes.clearButton}
307307
style={{ borderRadius: 0, top: 0, backgroundColor: '#dc004e', color: '#fff' }}
308308
>

src/reducers/componentReducer.ts

Lines changed: 12 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@ import {
22
ComponentInt,
33
ChildInt,
44
ApplicationStateInt
5-
} from "../utils/Interfaces.ts";
5+
} from '../utils/Interfaces.ts';
66

77
import {
88
LOAD_INIT_DATA,
@@ -13,6 +13,7 @@ import {
1313
CHANGE_FOCUS_COMPONENT,
1414
CHANGE_FOCUS_CHILD,
1515
CHANGE_COMPONENT_FOCUS_CHILD,
16+
CHANGE_IMAGE_SOURCE,
1617
EXPORT_FILES,
1718
CREATE_APPLICATION,
1819
EXPORT_FILES_SUCCESS,
@@ -27,7 +28,7 @@ import {
2728
DELETE_PROP,
2829
UPDATE_HTML_ATTR,
2930
UPDATE_CHILDREN_SORT
30-
} from "../actionTypes";
31+
} from '../actionTypes';
3132

3233
import {
3334
addComponent,
@@ -37,6 +38,7 @@ import {
3738
changeFocusComponent,
3839
changeComponentFocusChild,
3940
changeFocusChild,
41+
changeImageSource,
4042
exportFilesSuccess,
4143
exportFilesError,
4244
handleClose,
@@ -46,14 +48,14 @@ import {
4648
deleteProp,
4749
updateHtmlAttr,
4850
updateChildrenSort
49-
} from "../utils/componentReducer.util.ts";
50-
import cloneDeep from "../utils/cloneDeep.ts";
51+
} from '../utils/componentReducer.util.ts';
52+
import cloneDeep from '../utils/cloneDeep.ts';
5153

5254
const appComponent: ComponentInt = {
5355
id: 1,
5456
stateful: false,
55-
title: "App",
56-
color: "#FF6D00",
57+
title: 'App',
58+
color: '#FF6D00',
5759
props: [],
5860
nextPropId: 1,
5961
position: {
@@ -96,7 +98,7 @@ const initialApplicationState: ApplicationStateInt = {
9698
initialApplicationFocusChild,
9799
focusChild: cloneDeep(initialApplicationFocusChild),
98100
components: [appComponent],
99-
appDir: "",
101+
appDir: '',
100102
loading: false
101103
};
102104

@@ -107,7 +109,7 @@ const componentReducer = (state = initialApplicationState, action: any) => {
107109
...state,
108110
...action.payload.data,
109111
loading: false,
110-
appDir: "",
112+
appDir: '',
111113
successOpen: false,
112114
errorOpen: false
113115
};
@@ -125,6 +127,8 @@ const componentReducer = (state = initialApplicationState, action: any) => {
125127
return changeFocusChild(state, action.payload);
126128
case CHANGE_COMPONENT_FOCUS_CHILD:
127129
return changeComponentFocusChild(state, action.payload);
130+
case CHANGE_IMAGE_SOURCE:
131+
return changeImageSource(state, action.payload);
128132
case CREATE_APPLICATION:
129133
case EXPORT_FILES:
130134
return { ...state, loading: true };

src/utils/componentReducer.util.ts

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -309,6 +309,14 @@ export const handleTransform = (
309309
focusChild: newFocusChild,
310310
};
311311
};
312+
export const changeImageSource = (state: ApplicationStateInt, { src }: { src: string }) => {
313+
return {
314+
...state,
315+
imageSource: src
316+
}
317+
}
318+
319+
312320

313321
//Reducer that deletes the component selected
314322
export const deleteComponent = (state: ApplicationStateInt, { componentId }: { componentId: number }) => {

0 commit comments

Comments
 (0)