Fix bug when open screen from /

This commit is contained in:
Leonardo Murça 2022-06-29 10:39:36 -03:00
parent d06352c719
commit 0ed97c74b0
9 changed files with 542 additions and 555 deletions

View file

@ -94,7 +94,8 @@ const menuOptions = activePath => [
selectedIcon: <HomeIcon />, selectedIcon: <HomeIcon />,
unselectedIcon: <HomeOutlined />, unselectedIcon: <HomeOutlined />,
pathname: '/home', pathname: '/home',
isActive: activePath === '/home' || activePath === '/login', isActive:
activePath === '/home' || activePath === '/login' || activePath === '/',
}, },
{ {
id: 1, id: 1,

View file

@ -12,8 +12,7 @@ import dayjs from 'dayjs';
import { capitalizeFirstLetter } from '../utils/capitalizeFirstLetter'; import { capitalizeFirstLetter } from '../utils/capitalizeFirstLetter';
function AssignmentCard({ title, classrooms, dueDate, scores, layoutType }) { function AssignmentCard({ title, classrooms, dueDate, scores, layoutType }) {
switch (layoutType) { if (layoutType === 'desktop') {
case 'desktop':
return ( return (
<Card <Card
sx={{ sx={{
@ -89,8 +88,7 @@ function AssignmentCard({ title, classrooms, dueDate, scores, layoutType }) {
</CardActionArea> </CardActionArea>
</Card> </Card>
); );
} else if (layoutType === 'mobile') {
case 'mobile':
return ( return (
<Card <Card
sx={{ sx={{
@ -165,9 +163,6 @@ function AssignmentCard({ title, classrooms, dueDate, scores, layoutType }) {
</CardActionArea> </CardActionArea>
</Card> </Card>
); );
default:
return null;
} }
} }

View file

@ -18,8 +18,7 @@ function ClassCard({
layoutType, layoutType,
onClick, onClick,
}) { }) {
switch (layoutType) { if (layoutType === 'desktop') {
case 'desktop':
return ( return (
<Card sx={{ width: 390, height: 135 }}> <Card sx={{ width: 390, height: 135 }}>
<CardActionArea <CardActionArea
@ -86,8 +85,7 @@ function ClassCard({
</CardActionArea> </CardActionArea>
</Card> </Card>
); );
} else if (layoutType === 'mobile') {
case 'mobile':
return ( return (
<Card sx={{ width: '100%' }}> <Card sx={{ width: '100%' }}>
<CardActionArea <CardActionArea
@ -140,9 +138,6 @@ function ClassCard({
</CardActionArea> </CardActionArea>
</Card> </Card>
); );
default:
return null;
} }
} }

View file

@ -20,8 +20,7 @@ function MainMenu({ options, layoutType }) {
options.find(option => option.isActive) options.find(option => option.isActive)
); );
switch (layoutType) { if (layoutType === 'desktop') {
case 'desktop':
return ( return (
<Drawer sx={drawer} variant="permanent" anchor="left"> <Drawer sx={drawer} variant="permanent" anchor="left">
<Toolbar disableGutters sx={toolbar}> <Toolbar disableGutters sx={toolbar}>
@ -43,8 +42,7 @@ function MainMenu({ options, layoutType }) {
</List> </List>
</Drawer> </Drawer>
); );
} else if (layoutType === 'mobile') {
case 'mobile':
return ( return (
<Box sx={{ width: '100%', position: 'fixed', bottom: 0, zIndex: 2 }}> <Box sx={{ width: '100%', position: 'fixed', bottom: 0, zIndex: 2 }}>
<BottomNavigation <BottomNavigation
@ -70,9 +68,6 @@ function MainMenu({ options, layoutType }) {
</BottomNavigation> </BottomNavigation>
</Box> </Box>
); );
default:
return null;
} }
} }

View file

@ -15,8 +15,7 @@ function Toolbar({ title, layoutType, avatarMenuOptions }) {
const [anchorElUser, setAnchorElUser] = useState(null); const [anchorElUser, setAnchorElUser] = useState(null);
const [anchorElNotifications, setAnchorElNotifications] = useState(null); const [anchorElNotifications, setAnchorElNotifications] = useState(null);
switch (layoutType) { if (layoutType === 'desktop') {
case 'desktop':
return ( return (
<Box sx={box}> <Box sx={box}>
{title} {title}
@ -95,8 +94,7 @@ function Toolbar({ title, layoutType, avatarMenuOptions }) {
</Box> </Box>
</Box> </Box>
); );
} else if (layoutType === 'mobile') {
case 'mobile':
return ( return (
<Box sx={mobileBox}> <Box sx={mobileBox}>
{title} {title}
@ -175,9 +173,6 @@ function Toolbar({ title, layoutType, avatarMenuOptions }) {
</Box> </Box>
</Box> </Box>
); );
default:
return null;
} }
} }

View file

@ -2,7 +2,7 @@ import { useMediaQuery } from '@mui/material';
import { useEffect, useState } from 'react'; import { useEffect, useState } from 'react';
export default function useLayoutType() { export default function useLayoutType() {
const [layoutType, setLayoutType] = useState('desktop'); const [layoutType, setLayoutType] = useState('unset');
const isMediaQueryRuleActive = useMediaQuery('(max-width:800px)'); const isMediaQueryRuleActive = useMediaQuery('(max-width:800px)');
useEffect(() => { useEffect(() => {

View file

@ -9,18 +9,12 @@ import { createArrayFrom1ToN } from '../../utils/createArrayFrom1ToN';
function View({ layoutType, classrooms, assignments, onClickClassCard }) { function View({ layoutType, classrooms, assignments, onClickClassCard }) {
const { container, divider, assignmentsStack } = styles[layoutType]; const { container, divider, assignmentsStack } = styles[layoutType];
switch (layoutType) { if (layoutType === 'desktop') {
case 'desktop':
return ( return (
<Grid sx={container} container spacing={2}> <Grid sx={container} container spacing={2}>
<Grid item xs={8}> <Grid item xs={8}>
<h1>Turmas</h1> <h1>Turmas</h1>
<Stack <Stack alignItems="center" flexWrap="wrap" direction="row" gap="30px">
alignItems="center"
flexWrap="wrap"
direction="row"
gap="30px"
>
{classrooms === null ? ( {classrooms === null ? (
createArrayFrom1ToN(6).map(i => ( createArrayFrom1ToN(6).map(i => (
<Skeleton <Skeleton
@ -84,7 +78,7 @@ function View({ layoutType, classrooms, assignments, onClickClassCard }) {
</Grid> </Grid>
</Grid> </Grid>
); );
case 'mobile': } else if (layoutType === 'mobile') {
return ( return (
<Stack sx={container}> <Stack sx={container}>
<h1>Turmas</h1> <h1>Turmas</h1>
@ -156,9 +150,6 @@ function View({ layoutType, classrooms, assignments, onClickClassCard }) {
</Stack> </Stack>
</Stack> </Stack>
); );
default:
return null;
} }
} }

View file

@ -41,5 +41,12 @@ const mobile = {
assignmentsStack: mobileAssignmentsStack, assignmentsStack: mobileAssignmentsStack,
}; };
const styles = { desktop, mobile }; // ========== Unset ==========
const unset = {
container: null,
divider: null,
assignmentsStack: null,
};
const styles = { desktop, mobile, unset };
export default styles; export default styles;

View file

@ -77,5 +77,13 @@ const mobile = {
logoContainer: logoContainerMobile, logoContainer: logoContainerMobile,
}; };
const styles = { desktop, mobile }; // ========== Unset ==========
const unset = {
paper: null,
boxLogo: null,
boxForm: null,
logoContainer: null,
};
const styles = { desktop, mobile, unset };
export default styles; export default styles;