Rename existing methods and add assignments tab
This commit is contained in:
parent
c557480e65
commit
c9a099dd88
8 changed files with 94 additions and 37 deletions
|
@ -2,12 +2,13 @@ import { createContext, useContext, useEffect, useState } from 'react';
|
||||||
import { useLocation } from 'react-router-dom';
|
import { useLocation } from 'react-router-dom';
|
||||||
import { useAuthState } from './auth';
|
import { useAuthState } from './auth';
|
||||||
import {
|
import {
|
||||||
getAssignments,
|
getAllAssignments,
|
||||||
|
getAssignmentsByClassId,
|
||||||
getClassroomAnnouncementsById,
|
getClassroomAnnouncementsById,
|
||||||
getClassroomById,
|
getClassroomById,
|
||||||
getClassrooms,
|
getClassrooms,
|
||||||
getFaq,
|
getFaq,
|
||||||
getUpcomingAssignmentsById,
|
getUpcomingAssignmentsByClassId,
|
||||||
} from '../services/user-service';
|
} from '../services/user-service';
|
||||||
|
|
||||||
const UserContext = createContext();
|
const UserContext = createContext();
|
||||||
|
@ -27,7 +28,9 @@ function UserProvider(props) {
|
||||||
|
|
||||||
const fetchClassrooms = () => getClassrooms(user.id);
|
const fetchClassrooms = () => getClassrooms(user.id);
|
||||||
|
|
||||||
const fetchAssignments = () => getAssignments(user.id);
|
const fetchAllAssignments = () => getAllAssignments(user.id);
|
||||||
|
|
||||||
|
const fetchAssignmentsByClassId = classId => getAssignmentsByClassId(classId);
|
||||||
|
|
||||||
const fetchClassroomById = classId => getClassroomById(classId);
|
const fetchClassroomById = classId => getClassroomById(classId);
|
||||||
|
|
||||||
|
@ -36,19 +39,20 @@ function UserProvider(props) {
|
||||||
const fetchClassroomAnnouncements = classId =>
|
const fetchClassroomAnnouncements = classId =>
|
||||||
getClassroomAnnouncementsById(classId);
|
getClassroomAnnouncementsById(classId);
|
||||||
|
|
||||||
const fetchUpcomingAssignments = classId =>
|
const fetchUpcomingAssignmentsByClassId = classId =>
|
||||||
getUpcomingAssignmentsById(classId);
|
getUpcomingAssignmentsByClassId(classId);
|
||||||
|
|
||||||
return (
|
return (
|
||||||
<UserContext.Provider
|
<UserContext.Provider
|
||||||
value={{
|
value={{
|
||||||
state,
|
state,
|
||||||
fetchClassrooms,
|
fetchClassrooms,
|
||||||
fetchAssignments,
|
fetchAllAssignments,
|
||||||
|
fetchAssignmentsByClassId,
|
||||||
fetchClassroomById,
|
fetchClassroomById,
|
||||||
fetchFAQ,
|
fetchFAQ,
|
||||||
fetchClassroomAnnouncements,
|
fetchClassroomAnnouncements,
|
||||||
fetchUpcomingAssignments,
|
fetchUpcomingAssignmentsByClassId,
|
||||||
}}
|
}}
|
||||||
{...props}
|
{...props}
|
||||||
/>
|
/>
|
||||||
|
@ -59,21 +63,23 @@ function useUser() {
|
||||||
const {
|
const {
|
||||||
state,
|
state,
|
||||||
fetchClassrooms,
|
fetchClassrooms,
|
||||||
fetchAssignments,
|
fetchAllAssignments,
|
||||||
|
fetchAssignmentsByClassId,
|
||||||
fetchClassroomById,
|
fetchClassroomById,
|
||||||
fetchFAQ,
|
fetchFAQ,
|
||||||
fetchClassroomAnnouncements,
|
fetchClassroomAnnouncements,
|
||||||
fetchUpcomingAssignments,
|
fetchUpcomingAssignmentsByClassId,
|
||||||
} = useContext(UserContext);
|
} = useContext(UserContext);
|
||||||
|
|
||||||
return {
|
return {
|
||||||
state,
|
state,
|
||||||
fetchClassrooms,
|
fetchClassrooms,
|
||||||
fetchAssignments,
|
fetchAllAssignments,
|
||||||
|
fetchAssignmentsByClassId,
|
||||||
fetchClassroomById,
|
fetchClassroomById,
|
||||||
fetchFAQ,
|
fetchFAQ,
|
||||||
fetchClassroomAnnouncements,
|
fetchClassroomAnnouncements,
|
||||||
fetchUpcomingAssignments,
|
fetchUpcomingAssignmentsByClassId,
|
||||||
};
|
};
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -17,7 +17,7 @@ import jitsiLogo from '../../../assets/jitsi.svg';
|
||||||
function AnnouncementsTab({ layoutType, announcementsTabData, classroom }) {
|
function AnnouncementsTab({ layoutType, announcementsTabData, classroom }) {
|
||||||
const { container } = styles[layoutType];
|
const { container } = styles[layoutType];
|
||||||
if (layoutType === 'desktop') {
|
if (layoutType === 'desktop') {
|
||||||
return announcementsTabData === null ? (
|
return announcementsTabData && announcementsTabData.state === 'loading' ? (
|
||||||
<Grid sx={container} container spacing={2}>
|
<Grid sx={container} container spacing={2}>
|
||||||
<Grid sx={{ padding: '0 !important' }} item xs={4}>
|
<Grid sx={{ padding: '0 !important' }} item xs={4}>
|
||||||
{createArrayFrom1ToN(3).map(i => (
|
{createArrayFrom1ToN(3).map(i => (
|
||||||
|
@ -42,7 +42,7 @@ function AnnouncementsTab({ layoutType, announcementsTabData, classroom }) {
|
||||||
))}
|
))}
|
||||||
</Grid>
|
</Grid>
|
||||||
</Grid>
|
</Grid>
|
||||||
) : (
|
) : announcementsTabData.state === 'gone' ? null : (
|
||||||
<Grid sx={container} container spacing={2}>
|
<Grid sx={container} container spacing={2}>
|
||||||
<Grid sx={{ padding: '0 !important' }} item xs={4}>
|
<Grid sx={{ padding: '0 !important' }} item xs={4}>
|
||||||
<Stack gap="30px">
|
<Stack gap="30px">
|
||||||
|
@ -123,7 +123,7 @@ function AnnouncementsTab({ layoutType, announcementsTabData, classroom }) {
|
||||||
</Grid>
|
</Grid>
|
||||||
);
|
);
|
||||||
} else if (layoutType === 'mobile') {
|
} else if (layoutType === 'mobile') {
|
||||||
return announcementsTabData === null ? (
|
return announcementsTabData && announcementsTabData.state === 'loading' ? (
|
||||||
<Stack
|
<Stack
|
||||||
alignItems="center"
|
alignItems="center"
|
||||||
justifyContent="center"
|
justifyContent="center"
|
||||||
|
@ -151,7 +151,7 @@ function AnnouncementsTab({ layoutType, announcementsTabData, classroom }) {
|
||||||
/>
|
/>
|
||||||
))}
|
))}
|
||||||
</Stack>
|
</Stack>
|
||||||
) : (
|
) : announcementsTabData.state === 'gone' ? null : (
|
||||||
<Stack
|
<Stack
|
||||||
alignItems="center"
|
alignItems="center"
|
||||||
justifyContent="center"
|
justifyContent="center"
|
||||||
|
|
9
src/screens/Classroom/AssignmentsTab/index.js
Normal file
9
src/screens/Classroom/AssignmentsTab/index.js
Normal file
|
@ -0,0 +1,9 @@
|
||||||
|
function AssignmentsTab({ assignmentsTabData }) {
|
||||||
|
return assignmentsTabData && assignmentsTabData.state === 'loading' ? (
|
||||||
|
<h1>Loading..</h1>
|
||||||
|
) : assignmentsTabData.state === 'gone' ? null : (
|
||||||
|
<h1>Assignments Tab</h1>
|
||||||
|
);
|
||||||
|
}
|
||||||
|
|
||||||
|
export default AssignmentsTab;
|
|
@ -2,6 +2,7 @@ import { Container } from '@mui/material';
|
||||||
|
|
||||||
import Header from './Header';
|
import Header from './Header';
|
||||||
import AnnouncementsTab from './AnnouncementsTab';
|
import AnnouncementsTab from './AnnouncementsTab';
|
||||||
|
import AssignmentsTab from './AssignmentsTab';
|
||||||
|
|
||||||
import styles from './styles';
|
import styles from './styles';
|
||||||
|
|
||||||
|
@ -11,6 +12,7 @@ function View({
|
||||||
selectedTabOption,
|
selectedTabOption,
|
||||||
onSelectTabOption,
|
onSelectTabOption,
|
||||||
announcementsTabData,
|
announcementsTabData,
|
||||||
|
assignmentsTabData,
|
||||||
}) {
|
}) {
|
||||||
const { container } = styles[layoutType];
|
const { container } = styles[layoutType];
|
||||||
return (
|
return (
|
||||||
|
@ -26,6 +28,7 @@ function View({
|
||||||
announcementsTabData={announcementsTabData}
|
announcementsTabData={announcementsTabData}
|
||||||
classroom={classroom && classroom}
|
classroom={classroom && classroom}
|
||||||
/>
|
/>
|
||||||
|
<AssignmentsTab assignmentsTabData={assignmentsTabData} />
|
||||||
</Container>
|
</Container>
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
|
|
|
@ -11,29 +11,45 @@ function Classroom() {
|
||||||
const {
|
const {
|
||||||
fetchClassroomById,
|
fetchClassroomById,
|
||||||
fetchClassroomAnnouncements,
|
fetchClassroomAnnouncements,
|
||||||
fetchUpcomingAssignments,
|
fetchUpcomingAssignmentsByClassId,
|
||||||
|
fetchAssignmentsByClassId,
|
||||||
} = useUser();
|
} = useUser();
|
||||||
const [classroom, setClassroom] = useState(null);
|
const [classroom, setClassroom] = useState(null);
|
||||||
const [selectedTabOption, setSelectedTabOption] = useState(
|
const [selectedTabOption, setSelectedTabOption] = useState(
|
||||||
TAB_OPTIONS.announcements.value
|
TAB_OPTIONS.announcements.value
|
||||||
);
|
);
|
||||||
|
|
||||||
const [tabData, setTabData] = useState(TAB_OPTIONS.announcements);
|
const [tabData, setTabData] = useState(null);
|
||||||
|
|
||||||
const fetchAndPopulateAnnouncementsTabData = useCallback(async () => {
|
const fetchAndPopulateAnnouncementsTabData = useCallback(async () => {
|
||||||
|
setTabData({ tab: 'announcements', state: 'loading' });
|
||||||
const announcements = await fetchClassroomAnnouncements(params.id);
|
const announcements = await fetchClassroomAnnouncements(params.id);
|
||||||
const upcomingAssignments = await fetchUpcomingAssignments(params.id);
|
const upcomingAssignments = await fetchUpcomingAssignmentsByClassId(
|
||||||
|
params.id
|
||||||
|
);
|
||||||
|
|
||||||
setTabData({
|
setTabData({
|
||||||
tab: 'announcements',
|
tab: 'announcements',
|
||||||
|
state: 'idle',
|
||||||
announcements: [...announcements.data],
|
announcements: [...announcements.data],
|
||||||
upcomingAssignments: [...upcomingAssignments.data],
|
upcomingAssignments: [...upcomingAssignments.data],
|
||||||
});
|
});
|
||||||
}, [fetchClassroomAnnouncements, fetchUpcomingAssignments, params.id]);
|
}, [
|
||||||
|
fetchClassroomAnnouncements,
|
||||||
|
fetchUpcomingAssignmentsByClassId,
|
||||||
|
params.id,
|
||||||
|
]);
|
||||||
|
|
||||||
const fetchAndPopulateAssignmentsTabData = useCallback(async () => {
|
const fetchAndPopulateAssignmentsTabData = useCallback(async () => {
|
||||||
console.log('Fetch assignments');
|
setTabData({ tab: 'assignments', state: 'loading' });
|
||||||
}, []);
|
const assignments = await fetchAssignmentsByClassId(params.id);
|
||||||
|
|
||||||
|
setTabData({
|
||||||
|
tab: 'assignments',
|
||||||
|
state: 'idle',
|
||||||
|
assignments: [...assignments.data],
|
||||||
|
});
|
||||||
|
}, [fetchAssignmentsByClassId, params.id]);
|
||||||
|
|
||||||
const fetchAndPopulatePoepleTabData = useCallback(async () => {
|
const fetchAndPopulatePoepleTabData = useCallback(async () => {
|
||||||
console.log('Fetch assignments');
|
console.log('Fetch assignments');
|
||||||
|
@ -41,7 +57,6 @@ function Classroom() {
|
||||||
|
|
||||||
useEffect(() => {
|
useEffect(() => {
|
||||||
async function getSelectedTabData() {
|
async function getSelectedTabData() {
|
||||||
setTabData(null);
|
|
||||||
switch (selectedTabOption) {
|
switch (selectedTabOption) {
|
||||||
case TAB_OPTIONS.announcements.value:
|
case TAB_OPTIONS.announcements.value:
|
||||||
fetchAndPopulateAnnouncementsTabData();
|
fetchAndPopulateAnnouncementsTabData();
|
||||||
|
@ -89,7 +104,10 @@ function Classroom() {
|
||||||
selectedTabOption={selectedTabOption}
|
selectedTabOption={selectedTabOption}
|
||||||
onSelectTabOption={(_, value) => setSelectedTabOption(value)}
|
onSelectTabOption={(_, value) => setSelectedTabOption(value)}
|
||||||
announcementsTabData={
|
announcementsTabData={
|
||||||
tabData && tabData.tab === 'announcements' ? tabData : null
|
tabData && tabData.tab === 'announcements' ? tabData : { state: 'gone' }
|
||||||
|
}
|
||||||
|
assignmentsTabData={
|
||||||
|
tabData && tabData.tab === 'assignments' ? tabData : { state: 'gone' }
|
||||||
}
|
}
|
||||||
/>
|
/>
|
||||||
);
|
);
|
||||||
|
|
|
@ -9,7 +9,7 @@ function Home() {
|
||||||
useDocumentTitle('Página Inicial');
|
useDocumentTitle('Página Inicial');
|
||||||
const navigate = useNavigate();
|
const navigate = useNavigate();
|
||||||
const layoutType = useLayoutType();
|
const layoutType = useLayoutType();
|
||||||
const { fetchClassrooms, fetchAssignments } = useUser();
|
const { fetchClassrooms, fetchAllAssignments } = useUser();
|
||||||
const [classrooms, setClassrooms] = useState(null);
|
const [classrooms, setClassrooms] = useState(null);
|
||||||
const [assignments, setAssignments] = useState(null);
|
const [assignments, setAssignments] = useState(null);
|
||||||
|
|
||||||
|
@ -23,11 +23,11 @@ function Home() {
|
||||||
|
|
||||||
useEffect(() => {
|
useEffect(() => {
|
||||||
async function getAssignments() {
|
async function getAssignments() {
|
||||||
const result = await fetchAssignments();
|
const result = await fetchAllAssignments();
|
||||||
setAssignments(result.data);
|
setAssignments(result.data);
|
||||||
}
|
}
|
||||||
getAssignments();
|
getAssignments();
|
||||||
}, [fetchAssignments]);
|
}, [fetchAllAssignments]);
|
||||||
|
|
||||||
const onClickClassCard = id => {
|
const onClickClassCard = id => {
|
||||||
navigate(`/class/${id}`, { replace: true });
|
navigate(`/class/${id}`, { replace: true });
|
||||||
|
|
|
@ -318,6 +318,18 @@ const allUpcomingAssignments = [
|
||||||
],
|
],
|
||||||
classrooms: allClassrooms.filter(c => c.id === '321'),
|
classrooms: allClassrooms.filter(c => c.id === '321'),
|
||||||
},
|
},
|
||||||
|
{
|
||||||
|
id: '1234',
|
||||||
|
title: 'Trabalho NoSQL',
|
||||||
|
dueDate: '2022-06-29 22:00',
|
||||||
|
scores: [
|
||||||
|
{
|
||||||
|
classroomId: '666',
|
||||||
|
value: 35,
|
||||||
|
},
|
||||||
|
],
|
||||||
|
classrooms: allClassrooms.filter(c => c.id === '666'),
|
||||||
|
},
|
||||||
];
|
];
|
||||||
|
|
||||||
const faq = [
|
const faq = [
|
||||||
|
|
|
@ -11,7 +11,7 @@ import {
|
||||||
|
|
||||||
const getClassrooms = userId =>
|
const getClassrooms = userId =>
|
||||||
sleep(3000).then(() => {
|
sleep(3000).then(() => {
|
||||||
console.log('userId: ' + userId);
|
console.log('Get classrooms ' + userId);
|
||||||
return {
|
return {
|
||||||
data: allClassrooms,
|
data: allClassrooms,
|
||||||
};
|
};
|
||||||
|
@ -19,7 +19,7 @@ const getClassrooms = userId =>
|
||||||
|
|
||||||
const getClassroomById = classId =>
|
const getClassroomById = classId =>
|
||||||
sleep(3000).then(() => {
|
sleep(3000).then(() => {
|
||||||
console.log('classId ' + classId);
|
console.log('Get classroom by id ' + classId);
|
||||||
return {
|
return {
|
||||||
data: allClassrooms.filter(c => c.id === classId)[0],
|
data: allClassrooms.filter(c => c.id === classId)[0],
|
||||||
};
|
};
|
||||||
|
@ -27,30 +27,38 @@ const getClassroomById = classId =>
|
||||||
|
|
||||||
const getClassroomAnnouncementsById = classId =>
|
const getClassroomAnnouncementsById = classId =>
|
||||||
sleep(3000).then(() => {
|
sleep(3000).then(() => {
|
||||||
console.log('classId ' + classId);
|
console.log('Get classroon announcements by id ' + classId);
|
||||||
return {
|
return {
|
||||||
data: allClassroomAnnouncements.filter(c => c.classroom.id === classId),
|
data: allClassroomAnnouncements.filter(c => c.classroom.id === classId),
|
||||||
};
|
};
|
||||||
});
|
});
|
||||||
|
|
||||||
const getUpcomingAssignmentsById = classId =>
|
const getUpcomingAssignmentsByClassId = classId =>
|
||||||
sleep(3000).then(() => {
|
sleep(3000).then(() => {
|
||||||
console.log('classId ' + classId);
|
console.log('Getting upcoming assignments by class id ' + classId);
|
||||||
return {
|
return {
|
||||||
data: allUpcomingAssignments.filter(a =>
|
data: allUpcomingAssignments.filter(
|
||||||
a.classrooms.filter(c => c.id === classId)
|
a => a.classrooms.filter(c => c.id === classId)[0]
|
||||||
),
|
),
|
||||||
};
|
};
|
||||||
});
|
});
|
||||||
|
|
||||||
const getAssignments = userId =>
|
const getAllAssignments = userId =>
|
||||||
sleep(4000).then(() => {
|
sleep(4000).then(() => {
|
||||||
console.log('userId: ' + userId);
|
console.log('Getting all assignments ' + userId);
|
||||||
return {
|
return {
|
||||||
data: allAssignments,
|
data: allAssignments,
|
||||||
};
|
};
|
||||||
});
|
});
|
||||||
|
|
||||||
|
const getAssignmentsByClassId = classId =>
|
||||||
|
sleep(4000).then(() => {
|
||||||
|
console.log('Getting assignments by class id ' + classId);
|
||||||
|
return {
|
||||||
|
data: allAssignments.filter(a => a.classrooms[0].id === classId),
|
||||||
|
};
|
||||||
|
});
|
||||||
|
|
||||||
const getFaq = () =>
|
const getFaq = () =>
|
||||||
sleep(2000).then(() => {
|
sleep(2000).then(() => {
|
||||||
console.log('Fetching FAQ...');
|
console.log('Fetching FAQ...');
|
||||||
|
@ -72,9 +80,10 @@ const getUser = shouldFail =>
|
||||||
export {
|
export {
|
||||||
getClassrooms,
|
getClassrooms,
|
||||||
getClassroomById,
|
getClassroomById,
|
||||||
getAssignments,
|
getAllAssignments,
|
||||||
|
getAssignmentsByClassId,
|
||||||
getClassroomAnnouncementsById,
|
getClassroomAnnouncementsById,
|
||||||
getUpcomingAssignmentsById,
|
getUpcomingAssignmentsByClassId,
|
||||||
getFaq,
|
getFaq,
|
||||||
getUser,
|
getUser,
|
||||||
};
|
};
|
||||||
|
|
Loading…
Reference in a new issue