-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
* feat: use dashboard layout (#37) * chore: rename 'service' to 'lib' * feat: use dashboard layout * fix: fix login error
- Loading branch information
1 parent
1fa07d1
commit 74c74c4
Showing
28 changed files
with
989 additions
and
741 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,40 +1,44 @@ | ||
import { createTheme, ThemeProvider } from '@mui/material/styles'; | ||
import CssBaseline from '@mui/material/CssBaseline'; | ||
|
||
import React, { useState } from 'react'; | ||
import ReactDOM from 'react-dom'; | ||
import { useState } from 'react'; | ||
import { createRoot } from 'react-dom/client'; | ||
import { Provider } from 'react-redux'; | ||
import { BrowserRouter } from 'react-router-dom'; | ||
|
||
import { Drawer } from './components/drawer'; | ||
import { store } from './slices/store'; | ||
import { PrimaryLayout } from './layout'; | ||
import Navbar from './components/nav'; | ||
|
||
import { Flex } from './components'; | ||
import { AppBar } from './components/appBar'; | ||
import './styles.scss'; | ||
|
||
import { mainListItems } from './components/items'; | ||
import { PrimaryLayout } from './layout'; | ||
import React from 'react'; | ||
|
||
const App = () => { | ||
const Theme = createTheme(); | ||
const [open, setOpen] = useState(true); | ||
const [theme, setTheme] = useState(Theme); | ||
const toggleDrawer = () => { | ||
setOpen(!open); | ||
}; | ||
|
||
return ( | ||
<BrowserRouter> | ||
<Provider store={store}> | ||
<ThemeProvider theme={theme}> | ||
<Navbar brand="Jobs UI" toggleMode={(mode) => { | ||
const newTheme = createTheme({ | ||
palette: { | ||
mode | ||
} | ||
}); | ||
setTheme(newTheme); | ||
const bgColor = newTheme.palette.background.paper; | ||
document.body.style.backgroundColor = bgColor; | ||
}} /> | ||
<PrimaryLayout /> | ||
<PrimaryLayout/> | ||
</ThemeProvider> | ||
</Provider> | ||
</BrowserRouter> | ||
); | ||
} | ||
|
||
ReactDOM.render(<App />, document.getElementById('root')); | ||
}; | ||
const container = document.getElementById('root'); | ||
const root = createRoot(container!); | ||
root.render( | ||
<React.Fragment> | ||
<CssBaseline /> | ||
<App /> | ||
</React.Fragment> | ||
); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,27 @@ | ||
import { styled } from '@mui/material/styles'; | ||
import MuiAppBar, { AppBarProps as MuiAppBarProps } from '@mui/material/AppBar'; | ||
import * as React from 'react'; | ||
|
||
interface AppBarProps extends MuiAppBarProps { | ||
open?: boolean; | ||
} | ||
|
||
const drawerWidth: number = 240; | ||
|
||
export const AppBar = styled(MuiAppBar, { | ||
shouldForwardProp: (prop) => prop !== 'open', | ||
})<AppBarProps>(({ theme, open }) => ({ | ||
zIndex: theme.zIndex.drawer + 1, | ||
transition: theme.transitions.create(['width', 'margin'], { | ||
easing: theme.transitions.easing.sharp, | ||
duration: theme.transitions.duration.leavingScreen, | ||
}), | ||
...(open && { | ||
marginLeft: drawerWidth, | ||
width: `calc(100% - ${drawerWidth}px)`, | ||
transition: theme.transitions.create(['width', 'margin'], { | ||
easing: theme.transitions.easing.sharp, | ||
duration: theme.transitions.duration.enteringScreen, | ||
}), | ||
}), | ||
})); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,31 @@ | ||
import * as React from 'react'; | ||
import { styled } from '@mui/material/styles'; | ||
import MuiDrawer from '@mui/material/Drawer'; | ||
|
||
const drawerWidth: number = 240; | ||
|
||
export const Drawer = styled(MuiDrawer, { shouldForwardProp: (prop) => prop !== 'open' })( | ||
({ theme, open }) => ({ | ||
'& .MuiDrawer-paper': { | ||
position: 'relative', | ||
whiteSpace: 'nowrap', | ||
width: drawerWidth, | ||
transition: theme.transitions.create('width', { | ||
easing: theme.transitions.easing.sharp, | ||
duration: theme.transitions.duration.enteringScreen, | ||
}), | ||
boxSizing: 'border-box', | ||
...(!open && { | ||
overflowX: 'hidden', | ||
transition: theme.transitions.create('width', { | ||
easing: theme.transitions.easing.sharp, | ||
duration: theme.transitions.duration.leavingScreen, | ||
}), | ||
width: theme.spacing(7), | ||
[theme.breakpoints.up('sm')]: { | ||
width: theme.spacing(9), | ||
}, | ||
}), | ||
}, | ||
}), | ||
); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,12 @@ | ||
import * as React from 'react'; | ||
import Box from '@mui/material/Box'; | ||
|
||
type FlexProps = React.ComponentProps<typeof Box> & { children: React.ReactNode}; | ||
|
||
export const Flex: React.FC<FlexProps> = (props) => { | ||
const { children, ...rest } = props; | ||
|
||
return <Box sx={{ display: 'flex' }} {...rest}> | ||
{children} | ||
</Box>; | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1 +1,5 @@ | ||
export * from './nav' | ||
export * from './flex'; | ||
export * from './nav'; | ||
export * from './themeModePicker'; | ||
export * from './title'; | ||
export * from './userMenu'; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,25 @@ | ||
import * as React from 'react'; | ||
import ListItemButton from '@mui/material/ListItemButton'; | ||
import ListItemIcon from '@mui/material/ListItemIcon'; | ||
import ListItemText from '@mui/material/ListItemText'; | ||
import DashboardIcon from '@mui/icons-material/Dashboard'; | ||
import GithubIcon from '@mui/icons-material/GitHub'; | ||
|
||
import { Link as RouterLink } from 'react-router-dom'; | ||
|
||
export const mainListItems = ( | ||
<React.Fragment> | ||
<ListItemButton component={RouterLink} to="/" color="inherit"> | ||
<ListItemIcon> | ||
<DashboardIcon /> | ||
</ListItemIcon> | ||
<ListItemText primary="Home" /> | ||
</ListItemButton> | ||
<ListItemButton component={RouterLink} to="/repos" color="inherit"> | ||
<ListItemIcon> | ||
<GithubIcon /> | ||
</ListItemIcon> | ||
<ListItemText primary="Repos" /> | ||
</ListItemButton> | ||
</React.Fragment> | ||
); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,11 @@ | ||
import * as React from 'react'; | ||
import Typography, { TypographyProps } from '@mui/material/Typography'; | ||
|
||
type TitleProps = React.ComponentProps<TypographyProps<'h2', any>> & { children?: React.ReactNode } | ||
|
||
export const Title: React.FC<TitleProps> = (props) => { | ||
const { children, ...rest } = props; | ||
return <Typography component="h2" variant="h6" color="primary" gutterBottom {...rest}> | ||
{children} | ||
</Typography> | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,93 @@ | ||
import Box from '@mui/material/Box'; | ||
import Button from '@mui/material/Button'; | ||
import Menu from '@mui/material/Menu'; | ||
import MenuItem from '@mui/material/MenuItem'; | ||
import ListItemIcon from '@mui/material/ListItemIcon'; | ||
import Logout from '@mui/icons-material/Logout' | ||
import { useAppSelector } from '@/slices/hook'; | ||
import * as React from 'react'; | ||
import { Fragment, useState } from 'react'; | ||
import { Link as RouterLink, useNavigate } from 'react-router-dom'; | ||
import { useSelector, useDispatch } from 'react-redux'; | ||
import { setUsername } from '@/slices/login'; | ||
|
||
|
||
export const UserMenu: React.FC = () => { | ||
const { username } = useAppSelector(state => state.login); | ||
const [anchorEl, setAnchorEl] = useState<null | HTMLElement>(null); | ||
const dropdownOpen = Boolean(anchorEl); | ||
const dispatch = useDispatch(); | ||
const navigate = useNavigate(); | ||
const handleClick = (event: React.MouseEvent<HTMLButtonElement>) => { | ||
setAnchorEl(event.currentTarget); | ||
}; | ||
const handleClose = () => { | ||
setAnchorEl(null); | ||
}; | ||
|
||
return ( | ||
<Fragment> | ||
{username ? ( | ||
<Button | ||
color="inherit" | ||
onClick={e => { | ||
setAnchorEl(e.currentTarget); | ||
}} | ||
> | ||
{username} | ||
</Button> | ||
) : ( | ||
<Button component={RouterLink} to="/login" color="inherit"> | ||
Login | ||
</Button> | ||
)} | ||
<Menu | ||
anchorEl={anchorEl} | ||
open={dropdownOpen} | ||
PaperProps={{ | ||
elevation: 0, | ||
sx: { | ||
overflow: 'visible', | ||
filter: 'drop-shadow(0px 2px 8px rgba(0,0,0,0.32))', | ||
mt: 1.5, | ||
'& .MuiAvatar-root': { | ||
width: 32, | ||
height: 32, | ||
ml: -0.5, | ||
mr: 1 | ||
}, | ||
'&:before': { | ||
content: '""', | ||
display: 'block', | ||
position: 'absolute', | ||
top: 0, | ||
right: 14, | ||
width: 10, | ||
height: 10, | ||
bgcolor: 'background.paper', | ||
transform: 'translateY(-50%) rotate(45deg)', | ||
zIndex: 0 | ||
} | ||
} | ||
}} | ||
transformOrigin={{ horizontal: 'right', vertical: 'top' }} | ||
anchorOrigin={{ horizontal: 'right', vertical: 'bottom' }} | ||
> | ||
<MenuItem | ||
onClick={() => { | ||
localStorage.removeItem('login'); | ||
dispatch(setUsername(null)); | ||
setAnchorEl(null); | ||
navigate('/login'); | ||
}} | ||
> | ||
<ListItemIcon> | ||
<Logout fontSize="small" /> | ||
</ListItemIcon> | ||
Logout | ||
</MenuItem> | ||
</Menu> | ||
</Fragment> | ||
|
||
); | ||
} |
Oops, something went wrong.