Skip to content

Commit 7ec30dd

Browse files
authored
Merge pull request #1214 from andrewn/feature/theme-sync
Keep theme in sync with state across the app
2 parents fbb1e9a + 0d1a4d2 commit 7ec30dd

File tree

3 files changed

+17
-17
lines changed

3 files changed

+17
-17
lines changed

client/modules/App/App.jsx

Lines changed: 17 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,7 @@ class App extends React.Component {
1414

1515
componentDidMount() {
1616
this.setState({ isMounted: true }); // eslint-disable-line react/no-did-mount-set-state
17-
document.body.className = 'light';
17+
document.body.className = this.props.theme;
1818
}
1919

2020
componentWillReceiveProps(nextProps) {
@@ -23,6 +23,12 @@ class App extends React.Component {
2323
}
2424
}
2525

26+
componentDidUpdate(prevProps) {
27+
if (this.props.theme !== prevProps.theme) {
28+
document.body.className = this.props.theme;
29+
}
30+
}
31+
2632
render() {
2733
return (
2834
<div className="app">
@@ -39,10 +45,18 @@ App.propTypes = {
3945
pathname: PropTypes.string
4046
}).isRequired,
4147
setPreviousPath: PropTypes.func.isRequired,
48+
theme: PropTypes.string,
4249
};
4350

4451
App.defaultProps = {
45-
children: null
52+
children: null,
53+
theme: 'light'
4654
};
4755

48-
export default connect(() => ({}), { setPreviousPath })(App);
56+
const mapStateToProps = state => ({
57+
theme: state.preferences.theme,
58+
});
59+
60+
const mapDispatchToProps = { setPreviousPath };
61+
62+
export default connect(mapStateToProps, mapDispatchToProps)(App);

client/modules/IDE/pages/FullView.jsx

Lines changed: 0 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -11,13 +11,6 @@ import * as ProjectActions from '../actions/project';
1111
class FullView extends React.Component {
1212
componentDidMount() {
1313
this.props.getProject(this.props.params.project_id);
14-
document.body.className = this.props.theme;
15-
}
16-
17-
componentWillUpdate(nextProps) {
18-
if (nextProps.theme !== this.props.theme) {
19-
document.body.className = nextProps.theme;
20-
}
2114
}
2215

2316
ident = () => {}
@@ -62,7 +55,6 @@ class FullView extends React.Component {
6255
}
6356

6457
FullView.propTypes = {
65-
theme: PropTypes.string.isRequired,
6658
params: PropTypes.shape({
6759
project_id: PropTypes.string
6860
}).isRequired,
@@ -98,7 +90,6 @@ FullView.propTypes = {
9890
function mapStateToProps(state) {
9991
return {
10092
user: state.user,
101-
theme: state.preferences.theme,
10293
htmlFile: getHTMLFile(state.files),
10394
jsFiles: getJSFiles(state.files),
10495
cssFiles: getCSSFiles(state.files),

client/modules/IDE/pages/IDEView.jsx

Lines changed: 0 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -66,7 +66,6 @@ class IDEView extends React.Component {
6666

6767
window.onbeforeunload = () => this.warnIfUnsavedChanges();
6868

69-
document.body.className = this.props.preferences.theme;
7069
this.autosaveInterval = null;
7170
}
7271

@@ -90,10 +89,6 @@ class IDEView extends React.Component {
9089
this.props.getProject(nextProps.params.project_id);
9190
}
9291
}
93-
94-
if (nextProps.preferences.theme !== this.props.preferences.theme) {
95-
document.body.className = nextProps.preferences.theme;
96-
}
9792
}
9893

9994
componentDidUpdate(prevProps) {

0 commit comments

Comments
 (0)