Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

836 map setting menu left drawer #875

Merged
merged 11 commits into from
Jan 7, 2021
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
31 changes: 31 additions & 0 deletions client/App.jsx
Original file line number Diff line number Diff line change
Expand Up @@ -7,31 +7,62 @@ import { getMetadataRequest } from '@reducers/metadata';
import Header from '@components/Header';
import Footer from '@components/Footer';
import MapContainer from '@components/Map';
import PersistentDrawerLeft from '@components/LeftDrawer';
import GearButton from '@components/GearButton';
import { toggleMenu as reduxToggleMenu } from '@reducers/ui';
import { useSwipeable } from 'react-swipeable';
import theme from './theme/theme';

const menuStyles = {
swipeAreaOpen: {
float: 'left',
position: 'fixed',
width: '30%',
height: '100%',
},
gear: {
marginLeft: '85vw',
marginTop: '70vh',
},
};

const App = ({
getMetadata,
toggleMenu,
}) => {
useEffect(() => {
getMetadata();
});

const handleSwipeMenu = useSwipeable({
trackMouse: true,
onSwipedRight: () => toggleMenu(),
onSwipedLeft: () => toggleMenu(),
});

return (
<ThemeProvider theme={theme}>
<CssBaseline />
<Header />
<PersistentDrawerLeft />
<MapContainer />
{/* area where you can swipe the menu sidebar */}
{/* eslint-disable-next-line react/jsx-props-no-spreading */}
<div {...handleSwipeMenu} style={menuStyles.swipeAreaOpen} />
<GearButton onClick={toggleMenu} style={menuStyles.gear} />
<Footer />
</ThemeProvider>
);
};

const mapDispatchToProps = dispatch => ({
getMetadata: () => dispatch(getMetadataRequest()),
toggleMenu: () => dispatch(reduxToggleMenu()),
});

export default connect(null, mapDispatchToProps)(App);

App.propTypes = {
getMetadata: PropTypes.func.isRequired,
toggleMenu: PropTypes.func.isRequired,
};
7 changes: 5 additions & 2 deletions client/components/GearButton/index.jsx
Original file line number Diff line number Diff line change
Expand Up @@ -18,10 +18,10 @@ const useStyles = makeStyles({
},
});

const GearButton = ({ onClick }) => {
const GearButton = props => {
const { gearIcon, button } = useStyles();
const [pressed, setPressed] = useState(false);

const { onClick, style } = props;
const onKeyDown = e => {
e.preventDefault();
if (e.key === ' '
Expand All @@ -44,6 +44,7 @@ const GearButton = ({ onClick }) => {
role="button"
aria-pressed={pressed}
aria-label="Toggle Sidebar"
style={style}
>
<SettingsSharpIcon className={gearIcon} />
</IconButton>
Expand All @@ -52,9 +53,11 @@ const GearButton = ({ onClick }) => {

GearButton.propTypes = {
onClick: PropTypes.func,
style: PropTypes.obj,
};
GearButton.defaultProps = {
onClick: undefined,
style: undefined,
};

export default GearButton;
252 changes: 252 additions & 0 deletions client/components/LeftDrawer/index.jsx
Original file line number Diff line number Diff line change
@@ -0,0 +1,252 @@
import React from 'react';
import PropTypes from 'proptypes';
import { makeStyles, useTheme } from '@material-ui/core/styles';
import Drawer from '@material-ui/core/Drawer';
import CssBaseline from '@material-ui/core/CssBaseline';
import List from '@material-ui/core/List';
import Divider from '@material-ui/core/Divider';
import IconButton from '@material-ui/core/IconButton';
import ChevronLeftIcon from '@material-ui/icons/ChevronLeft';
import ChevronRightIcon from '@material-ui/icons/ChevronRight';
import ListItem from '@material-ui/core/ListItem';
import ListItemIcon from '@material-ui/core/ListItemIcon';
import ListItemText from '@material-ui/core/ListItemText';
import LinkIcon from '@material-ui/icons/Link';
import { connect } from 'react-redux';
import { toggleMenu as reduxToggleMenu } from '@reducers/ui';
import Radio from '@material-ui/core/Radio';

const drawerWidth = 275;

const useStyles = makeStyles(theme => ({
root: {
display: 'flex',
},
menuButton: {
marginRight: theme.spacing(2),
},
hide: {
display: 'none',
},
drawer: {
width: drawerWidth,
flexShrink: 0,
},
drawerPaper: {
width: drawerWidth,
backgroundColor: '#2A404E',
},
content: {
flexGrow: 1,
padding: theme.spacing(3),
transition: theme.transitions.create('margin', {
easing: theme.transitions.easing.sharp,
duration: theme.transitions.duration.leavingScreen,
}),
marginLeft: -drawerWidth,
},
share: {
marginBottom: '100px',
paddingLeft: '25px',
},
listItem: {
paddingTop: '15px',
paddingBottom: '15px',
height: '24px',
},
listItemTitle: {
paddingLeft: '28px',
},
}));

const PersistentDrawerLeft = ({ menuIsOpen, toggleMenu }) => {
// TODO ADD FUNCTIONALITY
const [selectedMapStyleValue, setMapStyleValue] = React.useState('Point Map');
const [selectedMapModeValue, setMapModeValue] = React.useState('Dark');
const [selectedDataColorScheme, setDataColorScheme] = React.useState('Original');
const [selectedBoundariesValue, setBoundariesValue] = React.useState('None');

const handleChangeMapStyle = event => {
setMapStyleValue(event.target.value);
};

const handleChangeMapMode = event => {
setMapModeValue(event.target.value);
};

const handleChangeDataColorScheme = event => {
setDataColorScheme(event.target.value);
};

const handleChangeBoundaries = event => {
setBoundariesValue(event.target.value);
};

const classes = useStyles();
const theme = useTheme();

const onClickShare = () => {
// TODO ADD FUNCTIONALITY
};

const escFunction = e => {
e.preventDefault();
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

it looks like this is preventing the chrome devtools keyboard shortcut from working. a couple options that fixed it, hopefully without causing any side effects:

  1. move e.preventDefault inside the if block
  2. change the eventListener to 'keypress' instead of 'keydown'

keypress fires after keydown, so maybe that's somehow messing up the shortcut?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Will look into it

if (e.key === 'Escape'
) {
toggleMenu();
}
};

React.useEffect(() => {
document.addEventListener('keypress', escFunction, false);
return () => {
document.removeEventListener('keypress', escFunction, false);
};
}, [escFunction]);

return (
<div className={classes.root}>
<CssBaseline />
<Drawer
className={classes.drawer}
variant="persistent"
anchor="left"
open={menuIsOpen}
classes={{
paper: classes.drawerPaper,
}}
>
<div className={classes.drawerHeader}>
<IconButton onClick={toggleMenu}>
{theme.direction === 'ltr' ? <ChevronLeftIcon /> : <ChevronRightIcon />}
</IconButton>
</div>
<Divider />
<List>
<ListItem key="Map Style" className={classes.listItemTitle}>
<ListItemText primary="Map Style" />
</ListItem>
{['Point Map', 'Heat Map'].map(text => (
<ListItem className={classes.listItem} style={{ color: selectedMapStyleValue === text && '#87C8BC' }} button key={text}>
<ListItemIcon>
<Radio
checked={selectedMapStyleValue === text}
onChange={handleChangeMapStyle}
value={text}
style={{ color: selectedMapStyleValue === text && '#87C8BC' }}
name="radio-button"
inputProps={{ 'aria-label': text }}
/>
</ListItemIcon>
<ListItemText primary={text} />
</ListItem>
))}
</List>
<Divider />
{
/**
* TODO ADD DYNAMIC LIST OF ITEMS
* ADD COLOR TO RADIO BUTTONS
*/
}
<List>
<ListItem key="Map Mode" className={classes.listItemTitle}>
<ListItemText primary="Map Mode" />
</ListItem>
{['Dark', 'Light', 'Street'].map(text => (
<ListItem style={{ color: selectedMapModeValue === text && '#87C8BC' }} button key={text} className={classes.listItem}>
<ListItemIcon>
<Radio
checked={selectedMapModeValue === text}
onChange={handleChangeMapMode}
value={text}
style={{ color: selectedMapModeValue === text && '#87C8BC' }}
name="radio-button"
inputProps={{ 'aria-label': text }}
/>
</ListItemIcon>
<ListItemText primary={text} />
</ListItem>
))}
</List>
<Divider />
<List>
<ListItem key="Data Color Scheme" className={classes.listItemTitle}>
<ListItemText primary="Data Color Scheme" />
</ListItem>
{['Original', 'Prism', 'Bold'].map(text => (
<ListItem
style={{ color: selectedDataColorScheme === text && '#87C8BC' }}
button
key={text}
className={classes.listItem}
>
<ListItemIcon>
<Radio
checked={selectedDataColorScheme === text}
onChange={handleChangeDataColorScheme}
value={text}
style={{ color: selectedDataColorScheme === text && '#87C8BC' }}
name="radio-button"
inputProps={{ 'aria-label': text }}
/>
</ListItemIcon>
<ListItemText primary={text} />
</ListItem>
))}
</List>
<Divider />
<List>
<ListItem key="Boundaries" className={classes.listItemTitle}>
<ListItemText primary="Boundaries" />
</ListItem>
{['None', 'Neighborhood Councils', 'City Councils'].map(text => (
<ListItem
style={{ color: selectedDataColorScheme === text && '#87C8BC' }}
button
key={text}
className={classes.listItem}
selected={selectedBoundariesValue === text}
>
<ListItemIcon>
<Radio
checked={selectedBoundariesValue === text}
onChange={handleChangeBoundaries}
value={text}
style={{ color: selectedBoundariesValue === text && '#87C8BC' }}
name="radio-button"
inputProps={{ 'aria-label': text }}
/>
</ListItemIcon>
<ListItemText primary={text} />
</ListItem>
))}
</List>
<Divider />
<List>
<ListItem key="Share" className={classes.share}>
<ListItemIcon onClick={onClickShare}>
<LinkIcon />
</ListItemIcon>
<ListItemText primary="Share" />
</ListItem>
</List>
</Drawer>
</div>
);
};

PersistentDrawerLeft.propTypes = {
menuIsOpen: PropTypes.bool.isRequired,
toggleMenu: PropTypes.func.isRequired,
};

const mapStateToProps = state => ({
menuIsOpen: state.ui.menu.isOpen,
});

const mapDispatchToProps = dispatch => ({
toggleMenu: () => dispatch(reduxToggleMenu()),
});

export default connect(mapStateToProps, mapDispatchToProps)(PersistentDrawerLeft);
5 changes: 5 additions & 0 deletions client/package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

1 change: 1 addition & 0 deletions client/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -35,6 +35,7 @@
"react-redux": "^7.1.3",
"react-router": "^5.1.2",
"react-router-dom": "^5.1.2",
"react-swipeable": "^6.0.1",
"react-test-renderer": "^16.12.0",
"react-vis": "^1.11.7",
"redux": "^4.0.4",
Expand Down
2 changes: 1 addition & 1 deletion client/redux/reducers/ui.js
Original file line number Diff line number Diff line change
Expand Up @@ -57,7 +57,7 @@ export const setMapMode = mode => ({

const initialState = {
menu: {
isOpen: true,
isOpen: false,
// activeTab: MENU_TABS.MAP,
},
map: {
Expand Down