Skip to content
Snippets Groups Projects
Commit 2a428082 authored by esikkala's avatar esikkala
Browse files

Improve app bar

parent 64dd128d
No related branches found
No related tags found
No related merge requests found
import React from 'react';
import PropTypes from 'prop-types';
import { withStyles } from '@material-ui/core/styles';
import IconButton from '@material-ui/core/IconButton';
import SearchIcon from '@material-ui/icons/Search';
import Input from '@material-ui/core/Input';
import InputLabel from '@material-ui/core/InputLabel';
import InputAdornment from '@material-ui/core/InputAdornment';
import FormControl from '@material-ui/core/FormControl';
import CircularProgress from '@material-ui/core/CircularProgress';
const styles = theme => ({
textSearch: {
margin: theme.spacing.unit,
},
});
class SearchField extends React.Component {
state = {
value: '',
};
componentDidUpdate = prevProps => {
if (prevProps.search.query != this.props.search.query) {
this.setState({
value: this.props.search.query
});
}
}
handleChange = (event) => {
this.setState({ value: event.target.value });
};
handleMouseDown = (event) => {
event.preventDefault();
};
handleOnKeyDown = (event) => {
if (event.key === 'Enter' && this.hasDatasets() && this.hasValidQuery()) {
this.props.clearResults();
this.props.updateQuery(this.state.value);
this.props.fetchResults('text', this.state.value);
}
};
handleClick = () => {
if (this.hasDatasets() && this.hasValidQuery()) {
this.props.clearResults();
this.props.updateQuery(this.state.value);
this.props.fetchResults('text', this.state.value);
}
};
hasDatasets = () => {
let hasDs = false;
Object.values(this.props.datasets).forEach(value => {
if (value.selected) {
hasDs = true;
}
});
return hasDs;
}
hasValidQuery = () => {
return this.state.value.length > 2;
}
render() {
const { classes, strings } = this.props;
let searchButton = null;
if (this.props.search.textResultsFetching) {
searchButton = (
<IconButton
aria-label="Search places"
>
<CircularProgress size={24} />
</IconButton>
);
} else {
searchButton = (
<IconButton
aria-label="Search"
onClick={this.handleClick}
onMouseDown={this.handleMouseDown}
>
<SearchIcon />
</IconButton>
);
}
return (
<div className={classes.root}>
<FormControl className={classes.textSearch}>
<InputLabel htmlFor="adornment-search">{strings.searchPlaceNames}</InputLabel>
<Input
id="adornment-search"
type='text'
value={this.state.value}
onChange={this.handleChange}
onKeyDown={this.handleOnKeyDown}
endAdornment={
<InputAdornment position="end">
{searchButton}
</InputAdornment>
}
/>
</FormControl>
</div>
);
}
}
SearchField.propTypes = {
classes: PropTypes.object.isRequired,
search: PropTypes.object.isRequired,
fetchResults: PropTypes.func.isRequired,
clearResults: PropTypes.func.isRequired,
updateQuery: PropTypes.func.isRequired,
datasets: PropTypes.object.isRequired,
strings: PropTypes.object.isRequired
};
export default withStyles(styles)(SearchField);
...@@ -5,16 +5,11 @@ import Toolbar from '@material-ui/core/Toolbar'; ...@@ -5,16 +5,11 @@ import Toolbar from '@material-ui/core/Toolbar';
import IconButton from '@material-ui/core/IconButton'; import IconButton from '@material-ui/core/IconButton';
import Typography from '@material-ui/core/Typography'; import Typography from '@material-ui/core/Typography';
import InputBase from '@material-ui/core/InputBase'; import InputBase from '@material-ui/core/InputBase';
import Badge from '@material-ui/core/Badge';
import MenuItem from '@material-ui/core/MenuItem'; import MenuItem from '@material-ui/core/MenuItem';
import Menu from '@material-ui/core/Menu'; import Menu from '@material-ui/core/Menu';
import { fade } from '@material-ui/core/styles/colorManipulator'; import { fade } from '@material-ui/core/styles/colorManipulator';
import { withStyles } from '@material-ui/core/styles'; import { withStyles } from '@material-ui/core/styles';
//§import MenuIcon from '@material-ui/icons/Menu';
import SearchIcon from '@material-ui/icons/Search'; import SearchIcon from '@material-ui/icons/Search';
import AccountCircle from '@material-ui/icons/AccountCircle';
import MailIcon from '@material-ui/icons/Mail';
import NotificationsIcon from '@material-ui/icons/Notifications';
import MoreIcon from '@material-ui/icons/MoreVert'; import MoreIcon from '@material-ui/icons/MoreVert';
import Button from '@material-ui/core/Button'; import Button from '@material-ui/core/Button';
import { Link, NavLink } from 'react-router-dom'; import { Link, NavLink } from 'react-router-dom';
...@@ -119,23 +114,12 @@ class TopBar extends React.Component { ...@@ -119,23 +114,12 @@ class TopBar extends React.Component {
}; };
render() { render() {
const { anchorEl, mobileMoreAnchorEl } = this.state; const { mobileMoreAnchorEl } = this.state;
const { classes } = this.props; const { classes } = this.props;
const isMenuOpen = Boolean(anchorEl);
const isMobileMenuOpen = Boolean(mobileMoreAnchorEl); const isMobileMenuOpen = Boolean(mobileMoreAnchorEl);
const renderMenu = ( const perspectives = [ 'manuscripts', 'works', 'events', 'people',
<Menu 'organizations', 'places' ];
anchorEl={anchorEl}
anchorOrigin={{ vertical: 'top', horizontal: 'right' }}
transformOrigin={{ vertical: 'top', horizontal: 'right' }}
open={isMenuOpen}
onClose={this.handleMenuClose}
>
<MenuItem onClick={this.handleMenuClose}>Profile</MenuItem>
<MenuItem onClick={this.handleMenuClose}>My account</MenuItem>
</Menu>
);
const renderMobileMenu = ( const renderMobileMenu = (
<Menu <Menu
...@@ -145,76 +129,18 @@ class TopBar extends React.Component { ...@@ -145,76 +129,18 @@ class TopBar extends React.Component {
open={isMobileMenuOpen} open={isMobileMenuOpen}
onClose={this.handleMobileMenuClose} onClose={this.handleMobileMenuClose}
> >
<MenuItem> {perspectives.map(perspective =>
<IconButton color="inherit"> <MenuItem
<Badge badgeContent={4} color="secondary"> key={perspective}
<MailIcon /> component={Link}
</Badge> to={`/${perspective}`}
</IconButton> >
<p>Messages</p> {perspective.toUpperCase()}
</MenuItem> </MenuItem>
<MenuItem> )}
<IconButton color="inherit">
<Badge badgeContent={11} color="secondary">
<NotificationsIcon />
</Badge>
</IconButton>
<p>Notifications</p>
</MenuItem>
<MenuItem onClick={this.handleProfileMenuOpen}>
<IconButton color="inherit">
<AccountCircle />
</IconButton>
<p>Profile</p>
</MenuItem>
</Menu> </Menu>
); );
const ManuscriptsLink = props => (
<NavLink
to="/manuscripts"
className={classes.appBarButton}
isActive={(match, location) => location.pathname.startsWith('/manuscripts')}
activeClassName={classes.appBarButtonActive}
{...props}
/>);
const WorksLink = props => (
<NavLink
to="/works"
className={classes.appBarButton}
isActive={(match, location) => location.pathname.startsWith('/works')}
activeClassName={classes.appBarButtonActive}
{...props}
/>);
const PeopleLink = props => (
<NavLink
to="/people"
className={classes.appBarButton}
isActive={(match, location) => location.pathname.startsWith('/people')}
activeClassName={classes.appBarButtonActive}
{...props}
/>);
const OrganizationsLink = props => (
<NavLink
to="/organizations"
className={classes.appBarButton}
isActive={(match, location) => location.pathname.startsWith('/organizations')}
activeClassName={classes.appBarButtonActive}
{...props}
/>);
const PlacesLink = props => (
<NavLink
to="/places"
className={classes.appBarButton}
isActive={(match, location) => location.pathname.startsWith('/places')}
activeClassName={classes.appBarButtonActive}
{...props}
/>);
return ( return (
<div className={classes.root}> <div className={classes.root}>
<AppBar position="absolute"> <AppBar position="absolute">
...@@ -243,32 +169,18 @@ class TopBar extends React.Component { ...@@ -243,32 +169,18 @@ class TopBar extends React.Component {
</div> </div>
<div className={classes.grow} /> <div className={classes.grow} />
<div className={classes.sectionDesktop}> <div className={classes.sectionDesktop}>
<Button {perspectives.map(perspective =>
className={classes.appBarButton} <Button
component={ManuscriptsLink}> key={perspective}
manuscripts className={classes.appBarButton}
</Button> component={NavLink}
<Button to={`/${perspective}`}
className={classes.appBarButton} isActive={(match, location) => location.pathname.startsWith(`/${perspective}`)}
component={WorksLink}> activeClassName={classes.appBarButtonActive}
works >
</Button> {perspective}
<Button disabled className={classes.appBarButton}>Events</Button> </Button>
<Button )}
className={classes.appBarButton}
component={PeopleLink}>
people
</Button>
<Button
className={classes.appBarButton}
component={OrganizationsLink}>
organizations
</Button>
<Button
className={classes.appBarButton}
component={PlacesLink}>
places
</Button>
</div> </div>
<div className={classes.sectionMobile}> <div className={classes.sectionMobile}>
<IconButton aria-haspopup="true" onClick={this.handleMobileMenuOpen} color="inherit"> <IconButton aria-haspopup="true" onClick={this.handleMobileMenuOpen} color="inherit">
...@@ -277,7 +189,6 @@ class TopBar extends React.Component { ...@@ -277,7 +189,6 @@ class TopBar extends React.Component {
</div> </div>
</Toolbar> </Toolbar>
</AppBar> </AppBar>
{renderMenu}
{renderMobileMenu} {renderMobileMenu}
</div> </div>
); );
...@@ -289,42 +200,3 @@ TopBar.propTypes = { ...@@ -289,42 +200,3 @@ TopBar.propTypes = {
}; };
export default withStyles(styles)(TopBar); export default withStyles(styles)(TopBar);
// <IconButton
// className={classes.menuButton}
// color="inherit"
// aria-label="Menu"
// onClick={this.handleClick}
// >
// <MenuIcon />
// </IconButton>
//
// <Menu
// id="simple-menu"
// anchorEl={anchorEl}
// open={Boolean(anchorEl)}
// onClose={this.handleClose}
// >
// <div className={classes.menuContent}>
//
//
// <FormControl component="fieldset" className={classes.formControl}>
// <FormLabel component="legend">Map mode</FormLabel>
// <RadioGroup
// className={classes.formGroup}
// aria-label="Map mode"
// name="map"
// value={this.props.mapMode}
// onChange={this.handleChange}
// >
// <FormControlLabel value="cluster" control={<Radio />} label="Clustered markers" />
// <FormControlLabel value="noCluster" control={<Radio />} label="Markers" />
//
// </RadioGroup>
// </FormControl>
//
//
//
// </div>
//
// </Menu>
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment