Skip to content

Commit f83af90

Browse files
authored
Merge pull request #12 from sean1292/staging
Added class toggle functionality
2 parents 8ba7c20 + 5b73a46 commit f83af90

File tree

7 files changed

+156
-78
lines changed

7 files changed

+156
-78
lines changed

src/actionTypes/index.ts

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -30,3 +30,4 @@ export const UPDATE_CHILDREN_SORT: string = 'UPDATE_CHILDREN_SORT';
3030
export const CHANGE_IMAGE_SOURCE: string = 'CHANGE_IMAGE_SOURCE';
3131
export const DELETE_IMAGE: string = 'DELETE_IMAGE';
3232
export const TOGGLE_STATE: string = 'TOGGLE_STATE';
33+
export const TOGGLE_CLASS: string = 'TOGGLE_CLASS';

src/actions/components.ts

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

510
import {
@@ -9,6 +14,7 @@ import {
914
DELETE_CHILD,
1015
DELETE_COMPONENT,
1116
TOGGLE_STATE,
17+
TOGGLE_CLASS,
1218
CHANGE_FOCUS_COMPONENT,
1319
CHANGE_FOCUS_CHILD,
1420
CHANGE_COMPONENT_FOCUS_CHILD,
@@ -36,18 +42,19 @@ import createApplicationUtil from '../utils/createApplication.util.ts';
3642

3743
export const changeImagePath = (imageSource: string) => ({
3844
type: CHANGE_IMAGE_SOURCE,
39-
payload: { imageSource },
40-
})
45+
payload: { imageSource }
46+
});
4147

4248
export const loadInitData = () => (dispatch: (arg: Action) => void) => {
4349
loadState().then((data: ApplicationStateInt) => {
50+
console.log('data.workspace', data.workspace);
4451
dispatch({
45-
type: LOAD_INIT_DATA,
46-
payload: {
47-
data: data ? data.workspace : {},
48-
},
52+
type: LOAD_INIT_DATA,
53+
payload: {
54+
data: data ? data.workspace : {}
55+
}
56+
});
4957
});
50-
});
5158
};
5259

5360
export const addComponent = ({ title }: { title: string }) => (dispatch: (arg: Action) => void) => {
@@ -59,9 +66,9 @@ export const addChild = ({
5966
childType,
6067
HTMLInfo
6168
}: {
62-
title: string;
63-
childType: string;
64-
HTMLInfo: object;
69+
title: string;
70+
childType: string;
71+
HTMLInfo: object;
6572
}) => (dispatch: (arg: Action) => void) => {
6673
dispatch({ type: ADD_CHILD, payload: { title, childType, HTMLInfo } });
6774
};
@@ -75,8 +82,8 @@ export const deleteComponent = ({
7582
componentId,
7683
stateComponents
7784
}: {
78-
componentId: number;
79-
stateComponents: ComponentsInt;
85+
componentId: number;
86+
stateComponents: ComponentsInt;
8087
}) => (dispatch: (arg: Action) => void) => {
8188
// find all places where the "to be deleted" is a child and do what u gotta do
8289
stateComponents.forEach((parent: ComponentInt) => {
@@ -100,21 +107,25 @@ stateComponents: ComponentsInt;
100107
dispatch({ type: DELETE_COMPONENT, payload: { componentId } });
101108
};
102109

103-
export const changeFocusComponent = ({ title }: { title: string }) => (dispatch: (arg: Action) => void) => {
110+
export const changeFocusComponent = ({ title }: { title: string }) => (
111+
dispatch: (arg: Action) => void
112+
) => {
104113
dispatch({ type: CHANGE_FOCUS_COMPONENT, payload: { title } });
105114
};
106115

107116
// make sure childId is being sent in
108-
export const changeFocusChild = ({ childId }: { childId: number }) => (dispatch: (arg: Action) => void) => {
117+
export const changeFocusChild = ({ childId }: { childId: number }) => (
118+
dispatch: (arg: Action) => void
119+
) => {
109120
dispatch({ type: CHANGE_FOCUS_CHILD, payload: { childId } });
110121
};
111122

112123
export const changeComponentFocusChild = ({
113124
componentId,
114125
childId
115126
}: {
116-
componentId: number;
117-
childId: number;
127+
componentId: number;
128+
childId: number;
118129
}) => (dispatch: (arg: Action) => void) => {
119130
dispatch({
120131
type: CHANGE_COMPONENT_FOCUS_CHILD,
@@ -124,18 +135,18 @@ childId: number;
124135

125136
export const deleteImage = () => ({
126137
type: DELETE_IMAGE
127-
})
138+
});
128139

129140
export const exportFiles = ({
130141
components,
131142
path,
132143
appName,
133144
exportAppBool
134145
}: {
135-
components: ComponentsInt;
136-
path: string;
137-
appName: string;
138-
exportAppBool: boolean;
146+
components: ComponentsInt;
147+
path: string;
148+
appName: string;
149+
exportAppBool: boolean;
139150
}) => (dispatch: (arg: Action) => void) => {
140151
// this dispatch sets the global state property 'loading' to true until the createFiles call resolves below
141152
dispatch({
@@ -185,11 +196,11 @@ export const createApplication = ({
185196
appName = 'reactype_app',
186197
exportAppBool
187198
}: {
188-
path: string;
189-
components: ComponentsInt;
190-
genOption: number;
191-
appName: string;
192-
exportAppBool: boolean;
199+
path: string;
200+
components: ComponentsInt;
201+
genOption: number;
202+
appName: string;
203+
exportAppBool: boolean;
193204
}) => (dispatch: (arg: Action) => void) => {
194205
if (genOption === 0) {
195206
exportAppBool = false;
@@ -209,7 +220,7 @@ exportAppBool: boolean;
209220
createApplicationUtil({
210221
path,
211222
appName,
212-
genOption,
223+
genOption
213224
})
214225
.then(() => {
215226
dispatch({
@@ -246,8 +257,12 @@ export const deleteProp = (propId: number) => (dispatch: (arg: Action) => void)
246257
dispatch({ type: DELETE_PROP, payload: propId });
247258
};
248259

249-
export const toggleComponentState = (index: string) => (dispatch: any) => {
250-
dispatch({ type: TOGGLE_STATE, payload: index });
260+
export const toggleComponentState = (id: string) => (dispatch: any) => {
261+
dispatch({ type: TOGGLE_STATE, payload: id });
262+
};
263+
264+
export const toggleComponentClass = (id: string) => (dispatch: any) => {
265+
dispatch({ type: TOGGLE_CLASS, payload: id });
251266
};
252267

253268
export const addProp = (prop: PropInt) => ({
@@ -256,7 +271,7 @@ export const addProp = (prop: PropInt) => ({
256271
});
257272

258273
export const updateHtmlAttr = ({ attr, value }: { attr: string; value: string }) => (
259-
dispatch: (arg: Action) => void,
274+
dispatch: (arg: Action) => void
260275
) => {
261276
dispatch({
262277
type: UPDATE_HTML_ATTR,
@@ -272,4 +287,4 @@ export const updateHtmlAttr = ({ attr, value }: { attr: string; value: string })
272287
// type: UPDATE_CHILDREN_SORT,
273288
// payload: { newSortValues },
274289
// });
275-
// };
290+
// };

src/components/LeftColExpansionPanel.tsx

Lines changed: 10 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -26,10 +26,11 @@ const LeftColExpansionPanel = (props: any) => {
2626
selectableChildren,
2727
components,
2828
deleteComponent,
29-
toggleComponentState
29+
toggleComponentState,
30+
toggleComponentClass
3031
} = props;
3132

32-
const { title, id, color } = component;
33+
const { title, id, color, stateful, classBased } = component;
3334
useEffect(() => {
3435
console.log('title: ', title);
3536
});
@@ -81,8 +82,9 @@ const LeftColExpansionPanel = (props: any) => {
8182
peview
8283
*/}
8384
<Switch
85+
checked={stateful}
8486
onChange={e => {
85-
toggleComponentState(props.id);
87+
toggleComponentState(id);
8688
changeFocusComponent(title);
8789
}}
8890
value="stateful"
@@ -106,13 +108,13 @@ const LeftColExpansionPanel = (props: any) => {
106108
Class?
107109
</InputLabel>
108110
<Switch
109-
// checked={classBased}
110-
// onChange={e => ONCHANGE FUNCTION PENDING ON CLASS REDUCER
111-
// updateComponent(id, { classBased: e.target.checked })
112-
// }
111+
checked={classBased}
112+
onChange={e => {
113+
toggleComponentClass(id);
114+
changeFocusComponent(title);
115+
}}
113116
value="classBased"
114117
color="primary"
115-
id={props.index.toString()}
116118
/>
117119
</div>
118120
</div>

src/containers/LeftContainer.tsx

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -34,6 +34,7 @@ interface PropsInt {
3434
createApp: any;
3535
deleteAllData: any;
3636
toggleComponentState: any;
37+
toggleComponentClass: any;
3738
deleteImage: any;
3839
}
3940

@@ -72,6 +73,7 @@ const mapDispatchToProps = (dispatch: any) => ({
7273
stateComponents: ComponentsInt;
7374
}) => dispatch(actions.deleteComponent({ componentId, stateComponents })),
7475
toggleComponentState: (id: string) => dispatch(actions.toggleComponentState(id)),
76+
toggleComponentClass: (id: string) => dispatch(actions.toggleComponentClass(id)),
7577
deleteAllData: () => dispatch(actions.deleteAllData()),
7678
deleteImage: () => dispatch(actions.deleteImage()),
7779
createApp: ({
@@ -214,6 +216,7 @@ class LeftContainer extends Component<PropsInt, StateInt> {
214216
changeFocusChild,
215217
selectableChildren,
216218
toggleComponentState,
219+
toggleComponentClass,
217220
deleteImage
218221
} = this.props;
219222
const { componentName, modal } = this.state;
@@ -234,6 +237,7 @@ class LeftContainer extends Component<PropsInt, StateInt> {
234237
deleteComponent={deleteComponent}
235238
components={components}
236239
toggleComponentState={toggleComponentState}
240+
toggleComponentClass={toggleComponentClass}
237241
/>
238242
));
239243
const { addImage, clearImage } = this;
@@ -408,4 +412,5 @@ function styles(): any {
408412

409413
export default compose(
410414
withStyles(styles),
411-
connect(mapStateToProps, mapDispatchToProps))(LeftContainer);
415+
connect(mapStateToProps, mapDispatchToProps)
416+
)(LeftContainer);

src/reducers/componentReducer.ts

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,7 @@ import {
77
DELETE_CHILD,
88
DELETE_COMPONENT,
99
TOGGLE_STATE,
10+
TOGGLE_CLASS,
1011
CHANGE_FOCUS_COMPONENT,
1112
CHANGE_FOCUS_CHILD,
1213
CHANGE_COMPONENT_FOCUS_CHILD,
@@ -47,7 +48,8 @@ import {
4748
deleteProp,
4849
updateHtmlAttr,
4950
updateChildrenSort,
50-
toggleComponentState
51+
toggleComponentState,
52+
toggleComponentClass
5153
} from '../utils/componentReducer.util.ts';
5254
import cloneDeep from '../utils/cloneDeep.ts';
5355

@@ -124,6 +126,8 @@ const componentReducer = (state = initialApplicationState, action: any) => {
124126
return deleteComponent(state, action.payload);
125127
case TOGGLE_STATE:
126128
return toggleComponentState(state, action.payload);
129+
case TOGGLE_CLASS:
130+
return toggleComponentClass(state, action.payload);
127131
case CHANGE_FOCUS_COMPONENT:
128132
return changeFocusComponent(state, action.payload);
129133
case CHANGE_FOCUS_CHILD:

0 commit comments

Comments
 (0)