Add fetch to upcoming assignments for professor

This commit is contained in:
Leonardo Murça 2022-12-14 18:52:24 -03:00
parent 30524bc1e0
commit 8e0922b047
4 changed files with 50 additions and 11 deletions

View file

@ -1,8 +1,10 @@
import { useState } from 'react';
import { import {
Button, Button,
Card, Card,
Container, Container,
Grid, Grid,
Link,
Skeleton, Skeleton,
Stack, Stack,
Typography, Typography,
@ -13,7 +15,6 @@ import styles from './styles';
import jitsiLogo from '../../../../assets/jitsi.svg'; import jitsiLogo from '../../../../assets/jitsi.svg';
import { createArrayFrom1ToN } from '../../../../utils/createArrayFrom1ToN'; import { createArrayFrom1ToN } from '../../../../utils/createArrayFrom1ToN';
import PublishAnnouncementCard from '../../../../components/PublishAnnouncementCard'; import PublishAnnouncementCard from '../../../../components/PublishAnnouncementCard';
import { useState } from 'react';
function AnnouncementsTab({ function AnnouncementsTab({
layoutType, layoutType,
@ -90,6 +91,21 @@ function AnnouncementsTab({
> >
<Stack justifyContent="flex-start" spacing={1}> <Stack justifyContent="flex-start" spacing={1}>
<h3 style={{ fontWeight: 500 }}>Próximas Atividades</h3> <h3 style={{ fontWeight: 500 }}>Próximas Atividades</h3>
{announcementsTabData.upcomingAssignments.length !== 0 ? (
announcementsTabData.upcomingAssignments.map(ua => (
<Link
href={`/assignment/${ua.id}`}
sx={{ fontSize: '15px' }}
key={ua.id}
>
{ua.title}
</Link>
))
) : (
<Container disableGutters>
<p>Nenhuma atividade encontrada!</p>
</Container>
)}
</Stack> </Stack>
</Card> </Card>
<Card <Card
@ -222,6 +238,22 @@ function AnnouncementsTab({
> >
<Stack justifyContent="flex-start" spacing={1}> <Stack justifyContent="flex-start" spacing={1}>
<h3 style={{ fontWeight: 500 }}>Próximas Atividades</h3> <h3 style={{ fontWeight: 500 }}>Próximas Atividades</h3>
{announcementsTabData.upcomingAssignments.length !== 0 ? (
announcementsTabData.upcomingAssignments.map(ua => (
<Link
href={`/assignment/${ua.id}`}
sx={{ fontSize: '15px' }}
key={ua.id}
>
{ua.title}
</Link>
))
) : (
<Container disableGutters>
<p>Nenhuma atividade encontrada!</p>
</Container>
)}
</Stack> </Stack>
</Card> </Card>
<Card <Card

View file

@ -22,10 +22,14 @@ function Classroom() {
params.id params.id
); );
const upcomingAssignments =
await userService.fetchUpcomingAssignmentsByClassId(params.id);
setTabData({ setTabData({
tab: 'announcements', tab: 'announcements',
state: 'idle', state: 'idle',
announcements: [...announcements.data], announcements: [...announcements.data],
upcomingAssignments: [...upcomingAssignments.data],
}); });
}, [userService, params.id]); }, [userService, params.id]);

View file

@ -21,4 +21,7 @@ export default class ProfessorService {
fetchPeopleByClassId = classId => ProfessorApi.getPeopleByClassId(classId); fetchPeopleByClassId = classId => ProfessorApi.getPeopleByClassId(classId);
fetchGradesByClassId = classId => ProfessorApi.getGradesByClassId(classId); fetchGradesByClassId = classId => ProfessorApi.getGradesByClassId(classId);
fetchUpcomingAssignmentsByClassId = classId =>
ProfessorApi.getUpcomingAssignmentsByClassId(classId);
} }

View file

@ -72,6 +72,16 @@ const CommonApi = {
data: allPeople.filter(p => p.classes[0].id === classId), data: allPeople.filter(p => p.classes[0].id === classId),
}; };
}), }),
getUpcomingAssignmentsByClassId: classId =>
sleep(300).then(() => {
console.log('Getting upcoming assignments by class id ' + classId);
return {
data: allUpcomingAssignments.filter(
a => a.classrooms.filter(c => c.id === classId)[0]
),
};
}),
}; };
const StudentApi = { const StudentApi = {
@ -84,16 +94,6 @@ const StudentApi = {
}; };
}), }),
getUpcomingAssignmentsByClassId: classId =>
sleep(300).then(() => {
console.log('Getting upcoming assignments by class id ' + classId);
return {
data: allUpcomingAssignments.filter(
a => a.classrooms.filter(c => c.id === classId)[0]
),
};
}),
getAllAssignments: userId => getAllAssignments: userId =>
sleep(400).then(() => { sleep(400).then(() => {
console.log('Getting all assignments ' + userId); console.log('Getting all assignments ' + userId);