Newer
Older
import React from 'react';
import PropTypes from 'prop-types';
import classNames from 'classnames';
import { connect } from 'react-redux';
import { withStyles } from '@material-ui/core/styles';
import Drawer from '@material-ui/core/Drawer';
import AppBar from '@material-ui/core/AppBar';
import Toolbar from '@material-ui/core/Toolbar';
import Typography from '@material-ui/core/Typography';
import IconButton from '@material-ui/core/IconButton';
import MenuIcon from '@material-ui/icons/Menu';
import ChevronLeftIcon from '@material-ui/icons/ChevronLeft';
import ChevronRightIcon from '@material-ui/icons/ChevronRight';
import Tabs from '@material-ui/core/Tabs';
import Tab from '@material-ui/core/Tab';
import IntegrationAutosuggest from '../components/IntegrationAutosuggest';
import LeafletMap from '../components/map/LeafletMap';
import Message from '../components/Message';
import VirtualizedTable from '../components/VirtualizedTable';
import DatasetSelector from '../components/DatasetSelector';
import Pie from '../components/Pie.js';
import {
updateQuery,
fetchSuggestions,
clearSuggestions,
fetchResults,
closeDrawer,
} from '../actions';
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
const styles = theme => ({
root: {
flexGrow: 1,
},
appFrame: {
height: '100%',
zIndex: 1,
overflow: 'hidden',
position: 'relative',
display: 'flex',
width: '100%',
},
appBar: {
position: 'absolute',
transition: theme.transitions.create(['margin', 'width'], {
easing: theme.transitions.easing.sharp,
duration: theme.transitions.duration.leavingScreen,
}),
},
appBarShift: {
width: `calc(100% - ${drawerWidth}px)`,
transition: theme.transitions.create(['margin', 'width'], {
easing: theme.transitions.easing.easeOut,
duration: theme.transitions.duration.enteringScreen,
}),
},
'appBarShift-left': {
marginLeft: drawerWidth,
},
'appBarShift-right': {
marginRight: drawerWidth,
},
menuButton: {
marginLeft: 12,
marginRight: 20,
},
hide: {
display: 'none',
},
drawerPaper: {
position: 'relative',
width: drawerWidth,
},
drawerHeader: {
display: 'flex',
alignItems: 'center',
padding: '0 8px',
...theme.mixins.toolbar,
},
drawerSearch: {
display: 'flex',
justifyContent: 'center',
},
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
content: {
flexGrow: 1,
backgroundColor: theme.palette.background.default,
//padding: theme.spacing.unit * 3,
transition: theme.transitions.create('margin', {
easing: theme.transitions.easing.sharp,
duration: theme.transitions.duration.leavingScreen,
}),
},
'content-left': {
marginLeft: -drawerWidth,
},
'content-right': {
marginRight: -drawerWidth,
},
contentShift: {
transition: theme.transitions.create('margin', {
easing: theme.transitions.easing.easeOut,
duration: theme.transitions.duration.enteringScreen,
}),
},
'contentShift-left': {
marginLeft: 0,
},
'contentShift-right': {
marginRight: 0,
},
});
let MapApp = (props) => {
const { classes, error, theme, drawerIsOpen, mapReady } = props;
const anchor = 'left';
if (props.search.results.length > 0) {
switch(props.resultFormat) {
case 'list':
resultsView = <VirtualizedTable list={Immutable.List(props.search.results)} />;
break;
case 'stats':
resultsView = <Pie data={props.search.results} />;
break;
default:
resultsView = <VirtualizedTable list={Immutable.List(props.search.results)} />;
}
const drawer = (
<Drawer
variant="persistent"
anchor={anchor}
open={drawerIsOpen}
classes={{
paper: classes.drawerPaper,
}}
>
<div className={classes.drawerHeader}>
<Tabs
value={0}
onChange={null}
fullWidth
indicatorColor="secondary"
textColor="secondary"
>
<Tab label="Places" />
<IconButton onClick={props.closeDrawer}>
{theme.direction === 'rtl' ? <ChevronRightIcon /> : <ChevronLeftIcon />}
</IconButton>
</div>
<DatasetSelector
datasets={props.search.datasets}
<div className={classes.drawerSearch}>
<IntegrationAutosuggest
search={props.search}
updateQuery={props.updateQuery}
fetchSuggestions={props.fetchSuggestions}
clearSuggestions={props.clearSuggestions}
fetchResults={props.fetchResults}
clearResults={props.clearResults}
updateResultFormat={props.updateResultFormat}
</Drawer>
);
let before = null;
let after = null;
if (anchor === 'left') {
before = drawer;
} else {
after = drawer;
}
if (!mapReady) {
props.setMapReady();
setTimeout(() => {
props.openDrawer();
}, 300);
}
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
return (
<div className={classes.root}>
<div className={classes.appFrame}>
<AppBar
className={classNames(classes.appBar, {
[classes.appBarShift]: drawerIsOpen,
[classes[`appBarShift-${anchor}`]]: drawerIsOpen,
})}
>
<Toolbar disableGutters={!drawerIsOpen}>
<IconButton
color="inherit"
aria-label="open drawer"
onClick={props.openDrawer}
className={classNames(classes.menuButton, drawerIsOpen && classes.hide)}
>
<MenuIcon />
</IconButton>
<Typography variant="title" color="inherit" noWrap>
Hipla.fi
</Typography>
</Toolbar>
</AppBar>
{before}
<main
className={classNames(classes.content, classes[`content-${anchor}`], {
[classes.contentShift]: drawerIsOpen,
[classes[`contentShift-${anchor}`]]: drawerIsOpen,
})}
>
<div className={classes.drawerHeader} />
<Message error={error} />
<LeafletMap
sliderValue={100}
results={props.search.results}
geoJSON={props.geoJSON}
</main>
{after}
</div>
</div>
);
};
const mapStateToProps = (state) => ({
search: state.search,
drawerIsOpen: state.options.drawerIsOpen,
mapReady: state.options.mapReady,
error: state.error,
geoJSONKey: state.map.geoJSONKey,
resultFormat: state.options.resultFormat
});
const mapDispatchToProps = ({
openDrawer,
closeDrawer,
updateQuery,
fetchSuggestions,
clearSuggestions,
fetchResults,
});
MapApp.propTypes = {
classes: PropTypes.object.isRequired,
theme: PropTypes.object.isRequired,
search: PropTypes.object.isRequired,
error: PropTypes.object.isRequired,
drawerIsOpen: PropTypes.bool.isRequired,
mapReady: PropTypes.bool.isRequired,
openDrawer: PropTypes.func.isRequired,
closeDrawer: PropTypes.func.isRequired,
updateQuery: PropTypes.func.isRequired,
fetchSuggestions: PropTypes.func.isRequired,
clearSuggestions: PropTypes.func.isRequired,
fetchResults: PropTypes.func.isRequired,
clearResults: PropTypes.func.isRequired,
setMapReady: PropTypes.func.isRequired,
updateResultFormat: PropTypes.func.isRequired,
resultFormat: PropTypes.string.isRequired
};
MapApp = connect(
mapStateToProps,
mapDispatchToProps
)(withStyles(styles, {withTheme: true})(MapApp));
export default MapApp;