|
1 |
| -import React, { useState } from 'react'; |
2 |
| -import { Theme } from '@mui/material/styles'; |
3 |
| -import withStyles from '@mui/styles/withStyles'; |
4 |
| -import createStyles from '@mui/styles/createStyles'; |
5 |
| -import makeStyles from '@mui/styles/makeStyles'; |
6 |
| -import AppBar from '@mui/material/AppBar'; |
| 1 | +import React from 'react'; |
7 | 2 | import Avatar from '@mui/material/Avatar';
|
8 |
| -import Brightness3Icon from '@mui/icons-material/Brightness3'; |
9 |
| -import Brightness5Icon from '@mui/icons-material/Brightness5'; |
10 |
| -import DashboardIcon from '@mui/icons-material/Dashboard'; |
11 |
| -import Toolbar from '@mui/material/Toolbar'; |
12 |
| -import Typography from '@mui/material/Typography'; |
13 |
| -import Button from '@mui/material/Button'; |
14 |
| -import DeleteIcon from '@mui/icons-material/Delete'; |
15 |
| -import FilterListIcon from '@mui/icons-material/FilterList'; |
16 |
| -import Menu from '@mui/material/Menu'; |
17 |
| -import MenuItem from '@mui/material/MenuItem'; |
18 |
| -import List from '@mui/material/List'; |
19 |
| -import ListItem from '@mui/material/ListItem'; |
20 |
| -import ListItemText from '@mui/material/ListItemText'; |
21 |
| -import { Link } from 'react-router-dom'; |
22 |
| -import LoginButton from '../right/LoginButton'; |
23 |
| -import ExportButton from '../right/ExportButton'; |
24 |
| -import SaveProjectButton from '../right/SaveProjectButton'; |
25 |
| -import DeleteProjects from '../right/DeleteProjects'; |
26 |
| -import ProjectsFolder from '../right/OpenProjects'; |
27 |
| -import createModal from '../right/createModal'; |
28 | 3 | import logo from '../../public/icons/win/logo.png';
|
29 |
| -// Imports for redux toolkit usage |
30 |
| -import { toggleDarkMode } from '../../redux/reducers/slice/darkModeSlice'; |
31 |
| -import { resetAllState } from '../../redux/reducers/slice/appStateSlice'; |
32 |
| -import { useSelector, useDispatch } from 'react-redux'; |
33 |
| -import { setStyle } from '../../redux/reducers/slice/styleSlice' |
34 |
| -// NavBar text and button styling |
35 |
| -const useStyles = makeStyles((theme: Theme) => |
36 |
| - createStyles({ |
37 |
| - root: { |
38 |
| - flexGrow: 1, |
39 |
| - width: '100%' |
40 |
| - }, |
41 |
| - menuButton: { |
42 |
| - marginRight: theme.spacing(1), |
43 |
| - color: 'white' |
44 |
| - }, |
45 |
| - title: { |
46 |
| - flexGrow: 1, |
47 |
| - color: 'white' |
48 |
| - }, |
49 |
| - manageProject: { |
50 |
| - display: 'flex', |
51 |
| - justifyContent: 'center' |
52 |
| - } |
53 |
| - }) |
54 |
| -); |
| 4 | +import NavbarDropDown from './NavBarButtons'; |
| 5 | +import { useSelector } from 'react-redux' |
55 | 6 |
|
56 |
| -// Drop down menu button for export |
57 |
| -const StyledMenu = withStyles({ |
58 |
| - paper: { |
59 |
| - border: '1px solid #d3d4d5' |
60 |
| - } |
61 |
| -})(props => ( |
62 |
| - <Menu |
63 |
| - elevation={0} |
64 |
| - // getContentAnchorEl={null} |
65 |
| - anchorOrigin={{ |
66 |
| - vertical: 'bottom', |
67 |
| - horizontal: 'center' |
68 |
| - }} |
69 |
| - transformOrigin={{ |
70 |
| - vertical: 'top', |
71 |
| - horizontal: 'center' |
72 |
| - }} |
73 |
| - {...props} |
74 |
| - /> |
75 |
| -)); |
76 |
| - |
77 |
| -const StyledMenuItem = withStyles(theme => ({ |
78 |
| - root: { |
79 |
| - '&:focus': { |
80 |
| - '& .MuiListItemIcon-root, & .MuiListItemText-primary': { |
81 |
| - color: theme.palette.common.white |
82 |
| - } |
83 |
| - } |
84 |
| - } |
85 |
| -}))(MenuItem); |
86 |
| - |
87 |
| -//export default function NavBar(props) |
88 | 7 | const NavBar = (props) => {
|
89 |
| - const classes = useStyles(); |
90 |
| - // State for export menu button |
91 |
| - const [anchorEl, setAnchorEl] = React.useState(null); |
92 |
| - // State for clear canvas button |
93 |
| - const [modal, setModal] = useState(null); |
94 |
| - const dispatch = useDispatch(); |
95 |
| - const { state, style, isDarkMode } = useSelector(store => ({ |
96 |
| - state: store.appState, |
97 |
| - style: store.style, |
98 |
| - isDarkMode: store.darkMode.isDarkMode |
99 |
| - |
100 |
| - })); |
| 8 | + |
| 9 | + // for dropdown navbar |
| 10 | + const [dropMenu, setDropMenu] = React.useState(false); |
| 11 | + const isDarkMode = useSelector(state=>state.darkMode.isDarkMode) |
101 | 12 |
|
102 |
| - //NEW DARK MODE |
103 |
| - const handleDarkModeToggle = () => { |
104 |
| - dispatch(toggleDarkMode()); |
105 |
| - // Add your logic to update the style and theme based on darkMode |
106 |
| - isDarkMode ? dispatch(setStyle(null)) : dispatch(setStyle({ backgroundColor: '#21262c' })); |
107 |
| - props.setTheme(isDarkMode); |
108 |
| - }; |
109 |
| - |
110 |
| - const handleClick = event => { |
111 |
| - setAnchorEl(event.currentTarget); |
112 |
| - }; |
113 |
| - const handleClose = () => { |
114 |
| - setAnchorEl(null); |
115 |
| - }; |
116 |
| - // ---Clear canvas functionality--- |
117 |
| - // Closes out the open modal |
118 |
| - const closeModal = () => setModal(''); |
119 |
| - // Creates modal that asks if user wants to clear workspace |
120 |
| - // If user clears their workspace, then their components are removed from state and the modal is closed |
121 |
| - const clearWorkspace = () => { |
122 |
| - // Reset state for project to initial state |
123 |
| - const resetState = () => { |
124 |
| - dispatch(resetAllState()); |
125 |
| - }; |
126 |
| - // Set modal options |
127 |
| - const children = ( |
128 |
| - <List className="export-preference"> |
129 |
| - <ListItem |
130 |
| - key={'clear'} |
131 |
| - button |
132 |
| - onClick={resetState} |
133 |
| - style={{ |
134 |
| - border: '1px solid #3f51b5', |
135 |
| - marginBottom: '2%', |
136 |
| - marginTop: '5%' |
137 |
| - }} |
138 |
| - > |
139 |
| - <ListItemText |
140 |
| - primary={'Yes, delete all project data'} |
141 |
| - style={{ textAlign: 'center' }} |
142 |
| - onClick={closeModal} |
143 |
| - /> |
144 |
| - </ListItem> |
145 |
| - </List> |
146 |
| - ); |
147 |
| - // Create modal |
148 |
| - setModal( |
149 |
| - createModal({ |
150 |
| - closeModal, |
151 |
| - children, |
152 |
| - message: 'Are you sure want to delete all data?', |
153 |
| - primBtnLabel: null, |
154 |
| - primBtnAction: null, |
155 |
| - secBtnAction: null, |
156 |
| - secBtnLabel: null, |
157 |
| - open: true |
158 |
| - }) |
159 |
| - ); |
160 |
| - }; |
161 | 13 | return (
|
162 |
| - <div className={classes.root} style={style}> |
163 |
| - <AppBar position="static"> |
164 |
| - <Toolbar> |
165 |
| - <Avatar src={logo}></Avatar> |
166 |
| - <Typography |
167 |
| - variant="h6" |
168 |
| - style={{ |
169 |
| - marginLeft: '1rem', |
170 |
| - color: isDarkMode ? '#fff' : '#0d47a1' |
171 |
| - }} |
172 |
| - className={classes.title} |
173 |
| - > |
174 |
| - ReacType |
175 |
| - </Typography> |
176 |
| - <Link to="/tutorial" style={{ textDecoration: 'none' }} target='_blank'> |
177 |
| - <Button |
178 |
| - variant="contained" |
179 |
| - color="secondary" |
180 |
| - style={{ minWidth: '137.69px' }} |
181 |
| - className="navbarButton" |
182 |
| - id="navbarButton" |
183 |
| - > |
184 |
| - Tutorial |
185 |
| - </Button> |
186 |
| - </Link> |
187 |
| - {/* ==================================Dashboard Button================================================== */} |
188 |
| - {state.isLoggedIn ? ( |
189 |
| - <Link to="/dashboard" style={{ textDecoration: 'none' }}> |
190 |
| - <Button |
191 |
| - variant="contained" |
192 |
| - color="secondary" |
193 |
| - style={{ minWidth: '137.69px' }} |
194 |
| - className="navbarButton" |
195 |
| - endIcon={<DashboardIcon />} |
196 |
| - id="navbarButton" |
197 |
| - > |
198 |
| - Dashboard |
199 |
| - </Button> |
200 |
| - </Link> |
201 |
| - ) : ( |
202 |
| - <span></span> |
203 |
| - )} |
204 |
| - {/* ==================================Clear Canvas Button================================================== */} |
205 |
| - <Button |
206 |
| - variant="contained" |
207 |
| - color="secondary" |
208 |
| - style={{ minWidth: '137.69px' }} |
209 |
| - onClick={clearWorkspace} |
210 |
| - className="navbarButton" |
211 |
| - id="navbarButton" |
212 |
| - endIcon={<DeleteIcon />} |
213 |
| - > |
214 |
| - Clear Canvas |
215 |
| - </Button> |
216 |
| - <ExportButton /> |
217 |
| - <Button |
218 |
| - className="navbarButton" |
219 |
| - id="navbarButton" |
220 |
| - color="secondary" |
221 |
| - variant="contained" |
222 |
| - style={{ minWidth: '113.97px' }} |
223 |
| - endIcon={ |
224 |
| - props.isThemeLight ? <Brightness3Icon /> : <Brightness5Icon /> |
225 |
| - } |
226 |
| - onClick={handleDarkModeToggle} |
227 |
| - > |
228 |
| - {isDarkMode ? 'Light Mode' : 'Dark Mode'} |
229 |
| - </Button> |
230 |
| - {state.isLoggedIn ? ( // render Manage Project button/dropdown only if user is logged in |
231 |
| - <Button |
232 |
| - variant="contained" |
233 |
| - color="secondary" |
234 |
| - onClick={handleClick} |
235 |
| - className="navbarButton" |
236 |
| - id="navbarButton" |
237 |
| - endIcon={<FilterListIcon />} |
238 |
| - > |
239 |
| - MANAGE PROJECT |
240 |
| - </Button> |
241 |
| - ) : ( |
242 |
| - <span></span> |
243 |
| - )} |
244 |
| - <LoginButton /> |
245 |
| - <StyledMenu // Dropdown menu connected to Manage Project Button |
246 |
| - id="customized-menu" |
247 |
| - anchorEl={anchorEl} |
248 |
| - keepMounted |
249 |
| - open={Boolean(anchorEl)} |
250 |
| - onClose={handleClose} |
251 |
| - > |
252 |
| - <StyledMenuItem |
253 |
| - id="navbarButton" |
254 |
| - className={classes.manageProject} |
255 |
| - onClick={handleClose} |
256 |
| - > |
257 |
| - <SaveProjectButton /> |
258 |
| - </StyledMenuItem> |
259 |
| - <StyledMenuItem |
260 |
| - className={classes.manageProject} |
261 |
| - onClick={handleClose} |
262 |
| - > |
263 |
| - <ProjectsFolder /> |
264 |
| - </StyledMenuItem> |
265 |
| - <StyledMenuItem |
266 |
| - className={classes.manageProject} |
267 |
| - onClick={handleClose} |
268 |
| - > |
269 |
| - <DeleteProjects /> |
270 |
| - </StyledMenuItem> |
271 |
| - </StyledMenu> |
272 |
| - </Toolbar> |
273 |
| - </AppBar> |
274 |
| - {modal} |
| 14 | + <nav className="main-navbar" style={isDarkMode ? {backgroundColor: '#013365'} : {backgroundColor: 'white'}}> |
| 15 | + <div className="main-logo"> |
| 16 | + <Avatar src={logo}></Avatar> |
| 17 | + <h1 style={isDarkMode ? {color: 'white'} : {color: '#013365'}}>ReacType</h1> |
| 18 | + </div> |
| 19 | + <div onMouseLeave={()=>setDropMenu(false)}> |
| 20 | + <svg xmlns="http://www.w3.org/2000/svg" width="16" height="16" fill="currentColor" className="bi bi-gear-wide-connected navbar-icon" viewBox="0 0 16 16" |
| 21 | + onMouseOver={()=>setDropMenu(true)}> |
| 22 | + <path d="M7.068.727c.243-.97 1.62-.97 1.864 0l.071.286a.96.96 0 0 0 1.622.434l.205-.211c.695-.719 1.888-.03 1.613.931l-.08.284a.96.96 0 0 0 1.187 1.187l.283-.081c.96-.275 1.65.918.931 1.613l-.211.205a.96.96 0 0 0 .434 1.622l.286.071c.97.243.97 1.62 0 1.864l-.286.071a.96.96 0 0 0-.434 1.622l.211.205c.719.695.03 1.888-.931 1.613l-.284-.08a.96.96 0 0 0-1.187 1.187l.081.283c.275.96-.918 1.65-1.613.931l-.205-.211a.96.96 0 0 0-1.622.434l-.071.286c-.243.97-1.62.97-1.864 0l-.071-.286a.96.96 0 0 0-1.622-.434l-.205.211c-.695.719-1.888.03-1.613-.931l.08-.284a.96.96 0 0 0-1.186-1.187l-.284.081c-.96.275-1.65-.918-.931-1.613l.211-.205a.96.96 0 0 0-.434-1.622l-.286-.071c-.97-.243-.97-1.62 0-1.864l.286-.071a.96.96 0 0 0 .434-1.622l-.211-.205c-.719-.695-.03-1.888.931-1.613l.284.08a.96.96 0 0 0 1.187-1.186l-.081-.284c-.275-.96.918-1.65 1.613-.931l.205.211a.96.96 0 0 0 1.622-.434l.071-.286zM12.973 8.5H8.25l-2.834 3.779A4.998 4.998 0 0 0 12.973 8.5zm0-1a4.998 4.998 0 0 0-7.557-3.779l2.834 3.78h4.723zM5.048 3.967c-.03.021-.058.043-.087.065l.087-.065zm-.431.355A4.984 4.984 0 0 0 3.002 8c0 1.455.622 2.765 1.615 3.678L7.375 8 4.617 4.322zm.344 7.646.087.065-.087-.065z"/> |
| 23 | + </svg> |
| 24 | + {dropMenu && <NavbarDropDown></NavbarDropDown>} |
275 | 25 | </div>
|
276 |
| - ); |
| 26 | + </nav> |
| 27 | + ) |
277 | 28 | }
|
278 | 29 |
|
279 | 30 | export default NavBar;
|
0 commit comments