Add upcoming assignments card and fetch

This commit is contained in:
Leonardo Murça 2022-08-03 19:49:02 -03:00
parent 2a0c5d49a0
commit 62def4510d
5 changed files with 116 additions and 31 deletions

View file

@ -7,6 +7,7 @@ import {
getClassroomById, getClassroomById,
getClassrooms, getClassrooms,
getFaq, getFaq,
getUpcomingAssignmentsById,
} from '../services/user-service'; } from '../services/user-service';
const UserContext = createContext(); const UserContext = createContext();
@ -35,6 +36,9 @@ function UserProvider(props) {
const fetchClassroomAnnouncements = classId => const fetchClassroomAnnouncements = classId =>
getClassroomAnnouncementsById(classId); getClassroomAnnouncementsById(classId);
const fetchUpcomingAssignments = classId =>
getUpcomingAssignmentsById(classId);
return ( return (
<UserContext.Provider <UserContext.Provider
value={{ value={{
@ -44,6 +48,7 @@ function UserProvider(props) {
fetchClassroomById, fetchClassroomById,
fetchFAQ, fetchFAQ,
fetchClassroomAnnouncements, fetchClassroomAnnouncements,
fetchUpcomingAssignments,
}} }}
{...props} {...props}
/> />
@ -58,6 +63,7 @@ function useUser() {
fetchClassroomById, fetchClassroomById,
fetchFAQ, fetchFAQ,
fetchClassroomAnnouncements, fetchClassroomAnnouncements,
fetchUpcomingAssignments,
} = useContext(UserContext); } = useContext(UserContext);
return { return {
@ -67,6 +73,7 @@ function useUser() {
fetchClassroomById, fetchClassroomById,
fetchFAQ, fetchFAQ,
fetchClassroomAnnouncements, fetchClassroomAnnouncements,
fetchUpcomingAssignments,
}; };
} }

View file

@ -1,8 +1,10 @@
import { import {
Avatar, Avatar,
AvatarGroup, AvatarGroup,
Card,
Container, Container,
Grid, Grid,
Link,
Paper, Paper,
Stack, Stack,
Tab, Tab,
@ -19,10 +21,9 @@ function View({
classroom, classroom,
selectedTabOption, selectedTabOption,
onSelectTabOption, onSelectTabOption,
announcements, announcementsTabData,
}) { }) {
const { title, container, paper, tabs, avatar, tooltip } = styles[layoutType]; const { title, container, paper, tabs, avatar, tooltip } = styles[layoutType];
if (layoutType === 'desktop') { if (layoutType === 'desktop') {
return ( return (
<Container disableGutters sx={container}> <Container disableGutters sx={container}>
@ -71,20 +72,26 @@ function View({
</Paper> </Paper>
</Container> </Container>
)} )}
{announcements === null ? ( {announcementsTabData === null ? (
<h1>Loading...</h1> <h1>Loading...</h1>
) : ( ) : (
<Grid sx={container} container spacing={2}> <Grid sx={container} container spacing={2}>
<Grid item xs={4}> <Grid item xs={4}>
<Container <Container disableGutters>
disableGutters <Card
sx={{ sx={{ width: '100%', padding: '20px' }}
backgroundColor: 'tomato', elevation={4}
height: '100vh', variant="elevation"
textAlign: 'center', >
}} <Stack justifyContent="flex-start" spacing={1}>
> <h3>Próximas Atividades</h3>
Left {announcementsTabData.upcomingAssignments.map(ua => (
<Link sx={{ fontSize: '15px' }} key={ua.id}>
{ua.title}
</Link>
))}
</Stack>
</Card>
</Container> </Container>
</Grid> </Grid>
<Grid item xs={8}> <Grid item xs={8}>
@ -96,7 +103,7 @@ function View({
direction="row" direction="row"
gap="30px" gap="30px"
> >
{announcements.data.map(announcement => ( {announcementsTabData.announcements.map(announcement => (
<AnnouncementCard <AnnouncementCard
key={announcement.id} key={announcement.id}
announcement={announcement} announcement={announcement}
@ -156,7 +163,7 @@ function View({
</Paper> </Paper>
</Container> </Container>
)} )}
{announcements === null ? ( {announcementsTabData === null ? (
<h1>Loading...</h1> <h1>Loading...</h1>
) : ( ) : (
<Stack <Stack
@ -167,15 +174,21 @@ function View({
gap="30px" gap="30px"
sx={{ marginTop: '30px' }} sx={{ marginTop: '30px' }}
> >
<Container <Container disableGutters>
disableGutters <Card
sx={{ sx={{ width: '100%', padding: '20px' }}
backgroundColor: 'tomato', elevation={4}
height: '400px', variant="elevation"
textAlign: 'center', >
}} <Stack justifyContent="flex-start" spacing={1}>
> <h3>Próximas Atividades</h3>
Left {announcementsTabData.upcomingAssignments.map(ua => (
<Link sx={{ fontSize: '15px' }} key={ua.id}>
{ua.title}
</Link>
))}
</Stack>
</Card>
</Container> </Container>
<Stack <Stack
sx={{ width: '100%' }} sx={{ width: '100%' }}
@ -185,7 +198,7 @@ function View({
direction="row" direction="row"
gap="30px" gap="30px"
> >
{announcements.data.map(announcement => ( {announcementsTabData.announcements.map(announcement => (
<AnnouncementCard <AnnouncementCard
key={announcement.id} key={announcement.id}
announcement={announcement} announcement={announcement}

View file

@ -8,7 +8,11 @@ import View from './View';
function Classroom() { function Classroom() {
const params = useParams(); const params = useParams();
const layoutType = useLayoutType(); const layoutType = useLayoutType();
const { fetchClassroomById, fetchClassroomAnnouncements } = useUser(); const {
fetchClassroomById,
fetchClassroomAnnouncements,
fetchUpcomingAssignments,
} = useUser();
const [classroom, setClassroom] = useState(null); const [classroom, setClassroom] = useState(null);
const [selectedTabOption, setSelectedTabOption] = useState( const [selectedTabOption, setSelectedTabOption] = useState(
TAB_OPTIONS.map(o => o.value).indexOf('announcements') TAB_OPTIONS.map(o => o.value).indexOf('announcements')
@ -40,11 +44,13 @@ function Classroom() {
async function getSelectedTabData() { async function getSelectedTabData() {
setTabData(null); setTabData(null);
if (selectedTabOption === 0) { if (selectedTabOption === 0) {
console.log('Fetch announcements'); const announcements = await fetchClassroomAnnouncements(params.id);
const result = await fetchClassroomAnnouncements(params.id); const upcomingAssignments = await fetchUpcomingAssignments(params.id);
setTabData({ setTabData({
tab: TAB_OPTIONS[selectedTabOption].value, tab: TAB_OPTIONS[selectedTabOption].value,
data: [...result.data], announcements: [...announcements.data],
upcomingAssignments: [...upcomingAssignments.data],
}); });
} else if (selectedTabOption === 1) { } else if (selectedTabOption === 1) {
console.log('Fetch assignments'); console.log('Fetch assignments');
@ -53,7 +59,12 @@ function Classroom() {
} }
} }
getSelectedTabData(); getSelectedTabData();
}, [fetchClassroomAnnouncements, selectedTabOption, params]); }, [
fetchClassroomAnnouncements,
fetchUpcomingAssignments,
selectedTabOption,
params,
]);
return ( return (
<View <View
@ -61,10 +72,9 @@ function Classroom() {
classroom={classroom} classroom={classroom}
selectedTabOption={selectedTabOption} selectedTabOption={selectedTabOption}
onSelectTabOption={onSelectTabOption} onSelectTabOption={onSelectTabOption}
announcements={ announcementsTabData={
tabData && tabData.tab === 'announcements' ? tabData : null tabData && tabData.tab === 'announcements' ? tabData : null
} }
people={tabData && tabData.tab === 'people' ? tabData : null}
/> />
); );
} }

View file

@ -89,6 +89,19 @@ const allAssignments = [
], ],
classrooms: allClassrooms.filter(c => c.id === '321'), classrooms: allClassrooms.filter(c => c.id === '321'),
}, },
{
id: '0128',
title:
'Prova 2 - Visualização de Dados. Matemática e Estatística em CD. Análise de Dados',
dueDate: '2022-09-01 23:59',
scores: [
{
classroomId: '321',
value: 30,
},
],
classrooms: allClassrooms.filter(c => c.id === '321'),
},
{ {
id: '1234', id: '1234',
title: 'Trabalho NoSQL', title: 'Trabalho NoSQL',
@ -197,6 +210,35 @@ const allClassroomAnnouncements = [
}, },
]; ];
const allUpcomingAssignments = [
{
id: '5435',
title:
'Prova 1 - Armazenamento de Dados. Python em CD. Armazenamento Analítico',
dueDate: '2022-07-01 23:59',
scores: [
{
classroomId: '321',
value: 30,
},
],
classrooms: allClassrooms.filter(c => c.id === '321'),
},
{
id: '0128',
title:
'Prova 2 - Visualização de Dados. Matemática e Estatística em CD. Análise de Dados',
dueDate: '2022-09-01 23:59',
scores: [
{
classroomId: '321',
value: 30,
},
],
classrooms: allClassrooms.filter(c => c.id === '321'),
},
];
const faq = [ const faq = [
{ {
question: 'Como faço para acessar a biblicoteca virtual?', question: 'Como faço para acessar a biblicoteca virtual?',
@ -244,4 +286,5 @@ export {
faq, faq,
user, user,
authFailure, authFailure,
allUpcomingAssignments,
}; };

View file

@ -6,6 +6,7 @@ import {
user, user,
authFailure, authFailure,
allClassroomAnnouncements, allClassroomAnnouncements,
allUpcomingAssignments,
} from './mocks'; } from './mocks';
const getClassrooms = userId => const getClassrooms = userId =>
@ -32,6 +33,16 @@ const getClassroomAnnouncementsById = classId =>
}; };
}); });
const getUpcomingAssignmentsById = classId =>
sleep(3000).then(() => {
console.log('classId ' + classId);
return {
data: allUpcomingAssignments.filter(a =>
a.classrooms.filter(c => c.id === classId)
),
};
});
const getAssignments = userId => const getAssignments = userId =>
sleep(4000).then(() => { sleep(4000).then(() => {
console.log('userId: ' + userId); console.log('userId: ' + userId);
@ -63,6 +74,7 @@ export {
getClassroomById, getClassroomById,
getAssignments, getAssignments,
getClassroomAnnouncementsById, getClassroomAnnouncementsById,
getUpcomingAssignmentsById,
getFaq, getFaq,
getUser, getUser,
}; };