Skip to content

Commit c532596

Browse files
reducer cleanup, working version
1 parent c43bdc8 commit c532596

File tree

4 files changed

+64
-73
lines changed

4 files changed

+64
-73
lines changed

src/actions/components.js

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -131,8 +131,8 @@ export const changeFocusComponent = ({ title }) => (dispatch) => {
131131
};
132132

133133
// make sure childId is being sent in
134-
export const changeFocusChild = ({ title, childId }) => (dispatch) => {
135-
dispatch({ type: CHANGE_FOCUS_CHILD, payload: { title, childId } });
134+
export const changeFocusChild = ({ childId }) => (dispatch) => {
135+
dispatch({ type: CHANGE_FOCUS_CHILD, payload: { childId } });
136136
};
137137

138138
export const changeComponentFocusChild = ({ componentId, childId }) => (dispatch) => {

src/containers/LeftContainer.jsx

Lines changed: 60 additions & 69 deletions
Original file line numberDiff line numberDiff line change
@@ -1,59 +1,50 @@
1-
import React, { Component } from "react";
2-
import { connect } from "react-redux";
3-
import { compose } from "redux";
4-
import FormControl from "@material-ui/core/FormControl";
5-
import TextField from "@material-ui/core/TextField";
6-
import Button from "@material-ui/core/Button";
7-
import AddIcon from "@material-ui/icons/Add";
8-
import Grid from "@material-ui/core/Grid";
9-
import { withStyles } from "@material-ui/core/styles";
10-
import LeftColExpansionPanel from "../components/LeftColExpansionPanel.jsx";
11-
import HTMLComponentPanel from "../components/HTMLComponentPanel.jsx";
12-
import * as actions from "../actions/components";
1+
import React, { Component } from 'react';
2+
import { connect } from 'react-redux';
3+
import { compose } from 'redux';
4+
import FormControl from '@material-ui/core/FormControl';
5+
import TextField from '@material-ui/core/TextField';
6+
import Button from '@material-ui/core/Button';
7+
import AddIcon from '@material-ui/icons/Add';
8+
import Grid from '@material-ui/core/Grid';
9+
import { withStyles } from '@material-ui/core/styles';
10+
import LeftColExpansionPanel from '../components/LeftColExpansionPanel.jsx';
11+
import HTMLComponentPanel from '../components/HTMLComponentPanel.jsx';
12+
import * as actions from '../actions/components';
1313

1414
const mapDispatchToProps = dispatch => ({
1515
addComponent: ({ title }) => dispatch(actions.addComponent({ title })),
1616
updateComponent: ({
17-
id,
18-
index,
19-
newParentId = null,
20-
color = null,
21-
stateful = null
22-
}) =>
23-
dispatch(
24-
actions.updateComponent({
25-
id,
26-
index,
27-
newParentId,
28-
color,
29-
stateful
30-
})
31-
),
32-
addChild: ({ title, childType, HTMLInfo }) =>
33-
dispatch(actions.addChild({ title, childType, HTMLInfo })),
34-
changeFocusComponent: ({ title }) =>
35-
dispatch(actions.changeFocusComponent({ title })),
36-
changeFocusChild: ({ title, childId }) =>
37-
dispatch(actions.changeFocusChild({ title, childId })),
38-
deleteComponent: ({ componentId, stateComponents }) =>
39-
dispatch(actions.deleteComponent({ componentId, stateComponents }))
17+
id, index, newParentId = null, color = null, stateful = null,
18+
}) => dispatch(
19+
actions.updateComponent({
20+
id,
21+
index,
22+
newParentId,
23+
color,
24+
stateful,
25+
}),
26+
),
27+
addChild: ({ title, childType, HTMLInfo }) => dispatch(actions.addChild({ title, childType, HTMLInfo })),
28+
changeFocusComponent: ({ title }) => dispatch(actions.changeFocusComponent({ title })),
29+
changeFocusChild: ({ childId }) => dispatch(actions.changeFocusChild({ childId })),
30+
deleteComponent: ({ componentId, stateComponents }) => dispatch(actions.deleteComponent({ componentId, stateComponents })),
4031
});
4132

4233
class LeftContainer extends Component {
4334
state = {
44-
componentName: ""
35+
componentName: '',
4536
};
4637

47-
handleChange = event => {
38+
handleChange = (event) => {
4839
this.setState({
49-
[event.target.name]: event.target.value
40+
[event.target.name]: event.target.value,
5041
});
5142
};
5243

5344
handleAddComponent = () => {
5445
this.props.addComponent({ title: this.state.componentName });
5546
this.setState({
56-
componentName: ""
47+
componentName: '',
5748
});
5849
};
5950

@@ -68,7 +59,7 @@ class LeftContainer extends Component {
6859
addChild,
6960
changeFocusComponent,
7061
changeFocusChild,
71-
selectableChildren
62+
selectableChildren,
7263
} = this.props;
7364
const { componentName } = this.state;
7465

@@ -101,8 +92,8 @@ class LeftContainer extends Component {
10192
margin="normal"
10293
autoFocus
10394
onChange={this.handleChange}
104-
onKeyPress={ev => {
105-
if (ev.key === "Enter") {
95+
onKeyPress={(ev) => {
96+
if (ev.key === 'Enter') {
10697
// Do code here
10798
this.handleAddComponent();
10899
ev.preventDefault();
@@ -112,10 +103,10 @@ class LeftContainer extends Component {
112103
name="componentName"
113104
className={classes.light}
114105
InputProps={{
115-
className: classes.input
106+
className: classes.input,
116107
}}
117108
InputLabelProps={{
118-
className: classes.input
109+
className: classes.input,
119110
}}
120111
/>
121112
</Grid>
@@ -151,48 +142,48 @@ function styles() {
151142
// height: "200px"
152143
// },
153144
cssLabel: {
154-
color: "white",
145+
color: 'white',
155146

156-
"&$cssFocused": {
157-
color: "green"
158-
}
147+
'&$cssFocused': {
148+
color: 'green',
149+
},
159150
},
160151
cssFocused: {},
161152
input: {
162-
color: "#fff",
163-
opacity: "0.7",
164-
marginBottom: "10px"
153+
color: '#fff',
154+
opacity: '0.7',
155+
marginBottom: '10px',
165156
},
166157
underline: {
167-
color: "white",
168-
"&::before": {
169-
color: "white"
170-
}
158+
color: 'white',
159+
'&::before': {
160+
color: 'white',
161+
},
171162
},
172163
button: {
173-
color: "#fff",
164+
color: '#fff',
174165

175-
"&:disabled": {
176-
color: "grey"
177-
}
166+
'&:disabled': {
167+
color: 'grey',
168+
},
178169
},
179170
clearButton: {
180-
top: "96%",
181-
position: "sticky!important",
182-
zIndex: "1",
171+
top: '96%',
172+
position: 'sticky!important',
173+
zIndex: '1',
183174

184-
"&:disabled": {
185-
color: "grey",
186-
backgroundColor: "#424242"
187-
}
188-
}
175+
'&:disabled': {
176+
color: 'grey',
177+
backgroundColor: '#424242',
178+
},
179+
},
189180
};
190181
}
191182

192183
export default compose(
193184
withStyles(styles),
194185
connect(
195186
null,
196-
mapDispatchToProps
197-
)
187+
mapDispatchToProps,
188+
),
198189
)(LeftContainer);

src/containers/MainContainer.jsx

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -34,7 +34,7 @@ const mapDispatchToProps = dispatch => ({
3434
}),
3535
),
3636
openPanel: component => dispatch(openExpansionPanel(component)),
37-
changeFocusChild: ({ title, childId }) => dispatch(changeFocusChild({ title, childId })),
37+
changeFocusChild: ({ childId }) => dispatch(changeFocusChild({ childId })),
3838
changeComponentFocusChild: ({ componentId, childId }) => dispatch(changeComponentFocusChild({ componentId, childId })),
3939
deleteChild: ({}) => dispatch(deleteChild({})), // if u send no prms, function will delete focus child.
4040
deleteComponent: ({ componentId, stateComponents }) => dispatch(deleteComponent({ componentId, stateComponents })),

src/utils/componentReducer.util.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -398,7 +398,7 @@ export const changeFocusComponent = (state, { title = state.focusComponent.title
398398
};
399399
};
400400

401-
export const changeFocusChild = (state, { title, childId }) => {
401+
export const changeFocusChild = (state, { childId }) => {
402402
const focComp = state.components.find(comp => comp.title === state.focusComponent.title);
403403
let newFocusChild = focComp.childrenArray.find(child => child.childId === childId);
404404

0 commit comments

Comments
 (0)