|
| 1 | +import React, { useState, useContext } from 'react'; |
| 2 | +import { |
| 3 | + createStyles, |
| 4 | + makeStyles, |
| 5 | + Theme, |
| 6 | +} from '@material-ui/core/styles'; |
| 7 | +import Button from '@material-ui/core/Button'; |
| 8 | +import AppBar from '@material-ui/core/AppBar'; |
| 9 | +import Avatar from '@material-ui/core/Avatar'; |
| 10 | +import Toolbar from '@material-ui/core/Toolbar'; |
| 11 | +import Typography from '@material-ui/core/Typography'; |
| 12 | +import { Link } from 'react-router-dom'; |
| 13 | +import { styleContext } from '../containers/AppContainer'; |
| 14 | +import logo from '../../../resources/icon.png'; |
| 15 | + |
| 16 | + |
| 17 | +// NavBar text and button styling |
| 18 | +const useStyles = makeStyles((theme: Theme) => createStyles({ |
| 19 | + root: { |
| 20 | + flexGrow: 1, |
| 21 | + width: '100%', |
| 22 | + }, |
| 23 | + menuButton: { |
| 24 | + marginRight: theme.spacing(2), |
| 25 | + color: 'white', |
| 26 | + }, |
| 27 | + title: { |
| 28 | + flexGrow: 1, |
| 29 | + color: 'white', |
| 30 | + }, |
| 31 | + manageProject: { |
| 32 | + display: 'flex', |
| 33 | + justifyContent: 'center', |
| 34 | + }, |
| 35 | +})); |
| 36 | + |
| 37 | +// sorting options |
| 38 | +const sortMethods = ['rating', 'date', 'user']; |
| 39 | + |
| 40 | +// TO DO: set types of props validation |
| 41 | + |
| 42 | +export default function NavBar(props) { |
| 43 | + // TO DO: import setStyle |
| 44 | + const classes = useStyles(); |
| 45 | + const { style, setStyle } = useContext(styleContext); |
| 46 | + |
| 47 | + |
| 48 | + // toggle to open and close dropdown sorting menu |
| 49 | + const [isOpen, setIsOpen] = useState(false); |
| 50 | + |
| 51 | + const toggling = () => setIsOpen(!isOpen); |
| 52 | + |
| 53 | + return ( |
| 54 | + <div className={classes.root} style={style}> |
| 55 | + <AppBar position="static"> |
| 56 | + <Toolbar> |
| 57 | + <Avatar src={logo}></Avatar> |
| 58 | + <Typography variant="h6" style={{ marginLeft: '1rem' }} className={classes.title}> |
| 59 | + ReacType |
| 60 | + </Typography> |
| 61 | + |
| 62 | + {/* ==========================================Sort by Button================================================== */} |
| 63 | + |
| 64 | + <div style ={ { textDecoration: 'none' } }> |
| 65 | + <Button onClick={toggling} |
| 66 | + variant="contained" |
| 67 | + color="primary" |
| 68 | + style={{ minWidth: '137.69px' }} |
| 69 | + className="navbarButton" |
| 70 | + id="navbarButtonDash" |
| 71 | + > |
| 72 | + Sort documents |
| 73 | + </Button> |
| 74 | + |
| 75 | + { |
| 76 | + isOpen && ( |
| 77 | + <div className="sortDoc"> |
| 78 | + {sortMethods.map((option, index) => ( |
| 79 | + <Button onClick={() => { |
| 80 | + props.optionClicked(option); |
| 81 | + toggling(); |
| 82 | + }} |
| 83 | + variant="contained" |
| 84 | + color="primary" |
| 85 | + style={{ minWidth: '137.69px' }} |
| 86 | + className="navbarButton" |
| 87 | + key={index} |
| 88 | + > {option} |
| 89 | + </Button> |
| 90 | + ))}; |
| 91 | + </div> |
| 92 | + ) |
| 93 | + } |
| 94 | + </div> |
| 95 | + |
| 96 | + {/* ====================================Home Button============================================== */} |
| 97 | + |
| 98 | + <div style ={ { textDecoration: 'none' } }> |
| 99 | + <Link to="/"> |
| 100 | + <Button |
| 101 | + variant="contained" |
| 102 | + color="primary" |
| 103 | + style={{ minWidth: '137.69px' }} |
| 104 | + className="navbarButton" |
| 105 | + id="ratingButton" |
| 106 | + > Home |
| 107 | + </Button> |
| 108 | + </Link> |
| 109 | + </div> |
| 110 | + </Toolbar> |
| 111 | + </AppBar> |
| 112 | + </div> |
| 113 | + ); |
| 114 | +} |
0 commit comments