Add assignment navigation in home screen

This commit is contained in:
Leonardo Murça 2022-08-15 21:44:54 -03:00
parent df4df6314a
commit 3b48463620
5 changed files with 27 additions and 6 deletions

View file

@ -49,7 +49,7 @@ function AuthenticatedApp() {
<Route path=":id" element={<Classroom />} /> <Route path=":id" element={<Classroom />} />
</Route> </Route>
<Route path="/assignment"> <Route path="/assignment">
<Route path=":id/" element={<Assignment />} /> <Route path=":id" element={<Assignment />} />
</Route> </Route>
<Route path="/login" element={<Navigate to="/home" />} /> <Route path="/login" element={<Navigate to="/home" />} />
<Route path="/" element={<Navigate to="/home" />} /> <Route path="/" element={<Navigate to="/home" />} />

View file

@ -29,7 +29,8 @@ const menuOptions = activePath => [
activePath === '/home' || activePath === '/home' ||
activePath === '/login' || activePath === '/login' ||
activePath === '/' || activePath === '/' ||
activePath.indexOf('class') !== -1, activePath.indexOf('class') !== -1 ||
activePath.indexOf('assignment') !== -1,
}, },
{ {
id: 1, id: 1,

View file

@ -13,7 +13,14 @@ import { capitalizeFirstLetter } from '../../utils/capitalizeFirstLetter';
import styles from './styles'; import styles from './styles';
function AssignmentCard({ title, classrooms, dueDate, scores, layoutType }) { function AssignmentCard({
title,
classrooms,
dueDate,
scores,
layoutType,
onClick,
}) {
const { const {
cardContainer, cardContainer,
classroomLinesIndicator, classroomLinesIndicator,
@ -33,7 +40,7 @@ function AssignmentCard({ title, classrooms, dueDate, scores, layoutType }) {
classrooms classrooms
.filter((_, i) => i > 0) .filter((_, i) => i > 0)
.map(c => <div key={c.id} style={classroomLinesIndicator(c)} />)} .map(c => <div key={c.id} style={classroomLinesIndicator(c)} />)}
<CardActionArea sx={cardActionArea}> <CardActionArea onClick={() => onClick()} sx={cardActionArea}>
<CardContent sx={cardContent}> <CardContent sx={cardContent}>
<Tooltip title={title}> <Tooltip title={title}>
<Typography <Typography
@ -72,7 +79,7 @@ function AssignmentCard({ title, classrooms, dueDate, scores, layoutType }) {
} else if (layoutType === 'mobile') { } else if (layoutType === 'mobile') {
return ( return (
<Card sx={cardContainer(classrooms)}> <Card sx={cardContainer(classrooms)}>
<CardActionArea sx={cardActionArea}> <CardActionArea onClick={() => onClick()} sx={cardActionArea}>
{classrooms.length > 1 && {classrooms.length > 1 &&
classrooms classrooms
.filter((_, i) => i > 0) .filter((_, i) => i > 0)

View file

@ -6,7 +6,13 @@ import AssignmentCard from '../../components/AssignmentCard';
import styles from './styles'; import styles from './styles';
import { createArrayFrom1ToN } from '../../utils/createArrayFrom1ToN'; import { createArrayFrom1ToN } from '../../utils/createArrayFrom1ToN';
function View({ layoutType, classrooms, assignments, onClickClassCard }) { function View({
layoutType,
classrooms,
assignments,
onClickClassCard,
onClickAssignmentCard,
}) {
const { container, divider, assignmentsStack } = styles[layoutType]; const { container, divider, assignmentsStack } = styles[layoutType];
if (layoutType === 'desktop') { if (layoutType === 'desktop') {
@ -69,6 +75,7 @@ function View({ layoutType, classrooms, assignments, onClickClassCard }) {
dueDate={assignment.dueDate} dueDate={assignment.dueDate}
scores={assignment.scores} scores={assignment.scores}
layoutType={layoutType} layoutType={layoutType}
onClick={() => onClickAssignmentCard(assignment.id)}
/> />
)) ))
) : ( ) : (
@ -142,6 +149,7 @@ function View({ layoutType, classrooms, assignments, onClickClassCard }) {
dueDate={assignment.dueDate} dueDate={assignment.dueDate}
scores={assignment.scores} scores={assignment.scores}
layoutType={layoutType} layoutType={layoutType}
onClick={() => onClickAssignmentCard(assignment.id)}
/> />
)) ))
) : ( ) : (

View file

@ -33,12 +33,17 @@ function Home() {
navigate(`/class/${id}`, { replace: true }); navigate(`/class/${id}`, { replace: true });
}; };
const onClickAssignmentCard = id => {
navigate(`/assignment/${id}`, { replace: true });
};
return ( return (
<View <View
layoutType={layoutType} layoutType={layoutType}
classrooms={classrooms} classrooms={classrooms}
assignments={assignments} assignments={assignments}
onClickClassCard={onClickClassCard} onClickClassCard={onClickClassCard}
onClickAssignmentCard={onClickAssignmentCard}
/> />
); );
} }