-
Notifications
You must be signed in to change notification settings - Fork 43
/
Copy pathindex.js
100 lines (88 loc) · 2.87 KB
/
index.js
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
import React, { PropTypes } from 'react';
import { connect } from 'react-redux';
import HTML5Backend from 'react-dnd-html5-backend';
import { DragDropContext } from 'react-dnd';
import flow from 'lodash.flow';
import Header from 'components/Header';
import LeftPanel from 'components/LeftPanel';
import Request from 'components/Request';
import Response from 'components/Response';
import Footer from 'components/Footer';
import Modal from 'components/Modal';
import updateTheme from 'utils/updateTheme';
import updateHighlightStyle from 'utils/updateHighlightStyle';
import { getTheme, getHighlightStyle, getCollectionsMinimized } from 'store/options/selectors';
import { fetchOptions } from 'store/options/actions';
import { fetchUrlVariables } from 'store/urlVariables/actions';
import { THEMES, HIGHLIGHT_STYLES } from 'constants/constants';
import './GlobalStyles';
import { Wrapper, MainContent, LeftCol, RightCol } from './StyledComponents';
/*
* This must be a React.Component because DragDropContext
* attaches a ref to the component, which as we know will
* not work with a stateless functional component.
*/
class App extends React.Component {
static propTypes = {
fetchUrlVariables: PropTypes.func.isRequired,
fetchOptions: PropTypes.func.isRequired,
theme: PropTypes.oneOf(THEMES).isRequired,
highlightStyle: PropTypes.oneOf(HIGHLIGHT_STYLES.map(style => style.style)).isRequired,
collectionsMinimized: PropTypes.bool.isRequired,
};
constructor(props) {
super(props);
props.fetchOptions();
props.fetchUrlVariables();
updateTheme(props.theme);
updateHighlightStyle(props.highlightStyle);
}
// Need to do this on prop change to react to sync storage option change
componentWillReceiveProps({ theme, highlightStyle }) {
if (this.props.theme !== theme) {
updateTheme(theme);
}
if (this.props.highlightStyle !== highlightStyle) {
updateHighlightStyle(highlightStyle);
}
}
render() {
const { collectionsMinimized } = this.props;
return (
<Wrapper>
<Header />
<MainContent>
<LeftCol
xsHidden
sm={collectionsMinimized ? null : 4}
collapsed={collectionsMinimized}
>
<aside>
<LeftPanel />
</aside>
</LeftCol>
<RightCol
xs={12}
sm={collectionsMinimized ? 12 : 8}
>
<main>
<Request />
<Response />
</main>
</RightCol>
</MainContent>
<Footer />
<Modal />
</Wrapper>
);
}
}
const mapStateToProps = state => ({
theme: getTheme(state),
highlightStyle: getHighlightStyle(state),
collectionsMinimized: getCollectionsMinimized(state),
});
export default flow(
connect(mapStateToProps, { fetchOptions, fetchUrlVariables }),
DragDropContext(HTML5Backend),
)(App);