|
| 1 | +import React, { useState, useContext } from 'react'; |
| 2 | +import { |
| 3 | + withStyles, |
| 4 | + createStyles, |
| 5 | + makeStyles, |
| 6 | + Theme, |
| 7 | +} from '@material-ui/core/styles'; |
| 8 | +import Button from '@material-ui/core/Button'; |
| 9 | +import AppBar from '@material-ui/core/AppBar'; |
| 10 | +import Avatar from '@material-ui/core/Avatar'; |
| 11 | +import Toolbar from '@material-ui/core/Toolbar'; |
| 12 | +import Typography from '@material-ui/core/Typography'; |
| 13 | +import IconButton from '@material-ui/core/IconButton'; |
| 14 | +import MenuIcon from '@material-ui/icons/Menu'; |
| 15 | +import Menu from '@material-ui/core/Menu'; |
| 16 | +import MenuItem from '@material-ui/core/MenuItem'; |
| 17 | +import List from '@material-ui/core/List'; |
| 18 | +import ListItem from '@material-ui/core/ListItem'; |
| 19 | +import ListItemText from '@material-ui/core/ListItemText'; |
| 20 | +import ListItemIcon from '@material-ui/core/ListItemIcon'; |
| 21 | +// ROUTING TO DASHBOARD |
| 22 | +import { Link } from 'react-router-dom'; |
| 23 | +import { styleContext } from '../containers/AppContainer'; |
| 24 | +import StateContext from '../../context/context'; |
| 25 | +import logo from '../../../resources/icon.png'; |
| 26 | + |
| 27 | + |
| 28 | +// NavBar text and button styling |
| 29 | +const useStyles = makeStyles((theme: Theme) => createStyles({ |
| 30 | + root: { |
| 31 | + flexGrow: 1, |
| 32 | + width: '100%', |
| 33 | + }, |
| 34 | + menuButton: { |
| 35 | + marginRight: theme.spacing(2), |
| 36 | + color: 'white', |
| 37 | + }, |
| 38 | + title: { |
| 39 | + flexGrow: 1, |
| 40 | + color: 'white', |
| 41 | + }, |
| 42 | + manageProject: { |
| 43 | + display: 'flex', |
| 44 | + justifyContent: 'center', |
| 45 | + }, |
| 46 | +})); |
| 47 | + |
| 48 | +// --------------------------Sorting Buttons------------------------------------// |
| 49 | +const sortByRating = (props) => { |
| 50 | + console.log('rating'); |
| 51 | + console.log("props", props); |
| 52 | + |
| 53 | + // should change state to true: then in the return for project container, a conditional rendering will occur |
| 54 | + |
| 55 | + // generate a sorted array of public projects based on likes |
| 56 | + // const sortedProjects = projects.sort((a, b) => ((a.likes > b.likes) ? 1 : -1)); |
| 57 | +}; |
| 58 | + |
| 59 | +const sortByDate = (props) => { |
| 60 | + console.log('date'); |
| 61 | +}; |
| 62 | + |
| 63 | +const sortByUser = (props) => { |
| 64 | + console.log('user'); |
| 65 | +}; |
| 66 | + |
| 67 | +const sortMethods = ['rating', 'date', 'user']; |
| 68 | + |
| 69 | +export default function NavBar(props) { |
| 70 | + |
| 71 | + const classes = useStyles(); |
| 72 | + const { style, setStyle } = useContext(styleContext); |
| 73 | + |
| 74 | + |
| 75 | + // toggle dropdown sorting menu |
| 76 | + const [isOpen, setIsOpen] = useState(false); |
| 77 | + const [selectedOption, setSelectedOption] = useState('rating'); |
| 78 | + |
| 79 | + const toggling = () => setIsOpen(!isOpen); |
| 80 | +// function not working properly, you have to go through the process and click twice |
| 81 | + const optionClicked = value => () => { |
| 82 | + setSelectedOption(value); |
| 83 | + setIsOpen(false); |
| 84 | + console.log('selectedOption', selectedOption); |
| 85 | + }; |
| 86 | + |
| 87 | + return ( |
| 88 | + <div className={classes.root} style={style}> |
| 89 | + <AppBar position="static"> |
| 90 | + <Toolbar> |
| 91 | + <Avatar src={logo}></Avatar> |
| 92 | + <Typography variant="h6" style={{ marginLeft: '1rem' }} className={classes.title}> |
| 93 | + ReacType |
| 94 | + </Typography> |
| 95 | + |
| 96 | + {/* ==================================Sort by Button================================================== */} |
| 97 | + |
| 98 | + <div style ={ { textDecoration: 'none' } }> |
| 99 | + <Button onClick={toggling} |
| 100 | + variant="contained" |
| 101 | + color="primary" |
| 102 | + style={{ minWidth: '137.69px' }} |
| 103 | + className="navbarButton" |
| 104 | + id="navbarButtonDash" |
| 105 | + > |
| 106 | + Sort documents |
| 107 | + </Button> |
| 108 | + |
| 109 | + { |
| 110 | + isOpen && ( |
| 111 | + <div className="sortDoc"> |
| 112 | + {sortMethods.map((option, index) => ( |
| 113 | + <Button onClick={optionClicked(option)} |
| 114 | + variant="contained" |
| 115 | + color="primary" |
| 116 | + style={{ minWidth: '137.69px' }} |
| 117 | + className="navbarButton" |
| 118 | + key={index} |
| 119 | + > {option} |
| 120 | + </Button> |
| 121 | + ))}; |
| 122 | + </div> |
| 123 | + ) |
| 124 | + } |
| 125 | + </div> |
| 126 | + |
| 127 | + {/* ====================================Home Button============================================== */} |
| 128 | + <div style ={ { textDecoration: 'none' } }> |
| 129 | + <Link to="/"> |
| 130 | + <Button |
| 131 | + variant="contained" |
| 132 | + color="primary" |
| 133 | + style={{ minWidth: '137.69px' }} |
| 134 | + className="navbarButton" |
| 135 | + id="ratingButton" |
| 136 | + > Home |
| 137 | + </Button> |
| 138 | + </Link> |
| 139 | + </div> |
| 140 | + </Toolbar> |
| 141 | + </AppBar> |
| 142 | + </div> |
| 143 | + ); |
| 144 | +} |
0 commit comments