Skip to content

Commit e134051

Browse files
committed
Extract ThemeProvider and connect to redux store
1 parent 96ecb3e commit e134051

File tree

2 files changed

+31
-8
lines changed

2 files changed

+31
-8
lines changed

client/index.jsx

Lines changed: 5 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -3,11 +3,10 @@ import { render } from 'react-dom';
33
import { hot } from 'react-hot-loader/root';
44
import { Provider } from 'react-redux';
55
import { Router, browserHistory } from 'react-router';
6-
import { ThemeProvider } from 'styled-components';
76

87
import configureStore from './store';
98
import routes from './routes';
10-
import theme, { Theme } from './theme';
9+
import ThemeProvider from './modules/App/components/ThemeProvider';
1110

1211
require('./styles/main.scss');
1312

@@ -19,14 +18,12 @@ const initialState = window.__INITIAL_STATE__;
1918

2019
const store = configureStore(initialState);
2120

22-
const currentTheme = Theme.light;
23-
2421
const App = () => (
25-
<ThemeProvider theme={{ ...theme[currentTheme] }}>
26-
<Provider store={store}>
22+
<Provider store={store}>
23+
<ThemeProvider>
2724
<Router history={history} routes={routes(store)} />
28-
</Provider>
29-
</ThemeProvider>
25+
</ThemeProvider>
26+
</Provider>
3027
);
3128

3229
const HotApp = hot(App);
Lines changed: 26 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,26 @@
1+
import React from 'react';
2+
import PropTypes from 'prop-types';
3+
import { connect } from 'react-redux';
4+
import { ThemeProvider } from 'styled-components';
5+
6+
import theme, { Theme } from '../../../theme';
7+
8+
const Provider = ({ children, currentTheme }) => (
9+
<ThemeProvider theme={{ ...theme[currentTheme] }}>
10+
{children}
11+
</ThemeProvider>
12+
);
13+
14+
Provider.propTypes = {
15+
children: PropTypes.node.isRequired,
16+
currentTheme: PropTypes.oneOf(Object.keys(Theme)).isRequired,
17+
};
18+
19+
function mapStateToProps(state) {
20+
return {
21+
currentTheme: state.preferences.theme,
22+
};
23+
}
24+
25+
26+
export default connect(mapStateToProps)(Provider);

0 commit comments

Comments
 (0)