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/LeafletMap';
import Message from '../components/Message';
import SimpleTable from '../components/SimpleTable';
// import DataTable from '../components/DataTable';
// import DataGrid from '../components/DataGrid';
import {
updateQuery,
updateDatasets,
fetchSuggestions,
clearSuggestions,
fetchResults,
openDrawer,
closeDrawer,
} from '../actions';
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
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',
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
padding: '0 8px',
...theme.mixins.toolbar,
},
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';
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" />
<Tab label="Maps" />
<IconButton onClick={props.closeDrawer}>
{theme.direction === 'rtl' ? <ChevronRightIcon /> : <ChevronLeftIcon />}
</IconButton>
</div>
<IntegrationAutosuggest
search={props.search}
updateQuery={props.updateQuery}
fetchSuggestions={props.fetchSuggestions}
clearSuggestions={props.clearSuggestions}
fetchResults={props.fetchResults}
/>
{props.search.results.length > 0 &&
</Drawer>
);
let before = null;
let after = null;
if (anchor === 'left') {
before = drawer;
} else {
after = drawer;
}
if (!mapReady) {
props.setMapReady();
setTimeout(() => {
props.openDrawer();
}, 300);
}
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
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,
});
const mapDispatchToProps = ({
openDrawer,
closeDrawer,
updateQuery,
updateDatasets,
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,
setMapReady: PropTypes.func.isRequired,
};
MapApp = connect(
mapStateToProps,
mapDispatchToProps
)(withStyles(styles, {withTheme: true})(MapApp));
export default MapApp;