Add professor class grades placeholder screen

This commit is contained in:
Leonardo Murça 2022-12-14 09:48:45 -03:00
parent 7a59fbc836
commit 0f3fe5494f
7 changed files with 73 additions and 0 deletions

View file

@ -0,0 +1,34 @@
function GradesTab({ gradesTabData, layoutType }) {
const layoutResolver = (state, grades, layoutType) => {
if (layoutType === 'desktop') {
switch (state) {
case 'loading':
return <h1>Loading...</h1>;
case 'idle':
return <h1>Grades Tab</h1>;
case 'gone':
return null;
default:
return null;
}
} else if (layoutType === 'mobile') {
switch (state) {
case 'loading':
return <h1>Loading...</h1>;
case 'idle':
return <h1>Grades Tab</h1>;
case 'gone':
return null;
default:
return null;
}
}
};
return layoutResolver(
gradesTabData && gradesTabData.state,
gradesTabData && gradesTabData.grades,
layoutType
);
}
export default GradesTab;

View file

@ -1,6 +1,7 @@
import { Container } from '@mui/system'; import { Container } from '@mui/system';
import AnnouncementsTab from './AnnouncementsTab'; import AnnouncementsTab from './AnnouncementsTab';
import AssignmentsTab from './AssignmentsTab'; import AssignmentsTab from './AssignmentsTab';
import GradesTab from './GradesTab';
import Header from './Header'; import Header from './Header';
import PeopleTab from './PeopleTab'; import PeopleTab from './PeopleTab';
import styles from './styles'; import styles from './styles';
@ -13,6 +14,7 @@ function View({
announcementsTabData, announcementsTabData,
assignmentsTabData, assignmentsTabData,
peopleTabData, peopleTabData,
gradesTabData,
isLoading, isLoading,
}) { }) {
const { container } = styles[layoutType]; const { container } = styles[layoutType];
@ -35,6 +37,7 @@ function View({
assignmentsTabData={assignmentsTabData} assignmentsTabData={assignmentsTabData}
/> />
<PeopleTab layoutType={layoutType} peopleTabData={peopleTabData} /> <PeopleTab layoutType={layoutType} peopleTabData={peopleTabData} />
<GradesTab layoutType={layoutType} gradesTabData={gradesTabData} />
</Container> </Container>
); );
} }

View file

@ -68,6 +68,17 @@ function Classroom() {
}); });
}, [userService, params.id]); }, [userService, params.id]);
const fetchAndPopulateGradesTabData = useCallback(async () => {
setTabData({ tab: 'people', state: 'loading' });
const grades = await userService.fetchPeopleByClassId(params.id);
setTabData({
tab: 'grades',
state: 'idle',
grades: [...grades.data],
});
}, [userService, params.id]);
useEffect(() => { useEffect(() => {
async function getSelectedTabData() { async function getSelectedTabData() {
switch (selectedTabOption) { switch (selectedTabOption) {
@ -80,6 +91,9 @@ function Classroom() {
case TAB_OPTIONS.people.value: case TAB_OPTIONS.people.value:
fetchAndPopulatePeopleTabData(); fetchAndPopulatePeopleTabData();
break; break;
case TAB_OPTIONS.grades.value:
fetchAndPopulateGradesTabData();
break;
default: default:
console.log('Invalid tab option'); console.log('Invalid tab option');
} }
@ -91,6 +105,7 @@ function Classroom() {
fetchAndPopulateAnnouncementsTabData, fetchAndPopulateAnnouncementsTabData,
fetchAndPopulateAssignmentsTabData, fetchAndPopulateAssignmentsTabData,
fetchAndPopulatePeopleTabData, fetchAndPopulatePeopleTabData,
fetchAndPopulateGradesTabData,
]); ]);
return ( return (
@ -108,6 +123,9 @@ function Classroom() {
peopleTabData={ peopleTabData={
tabData && tabData.tab === 'people' ? tabData : { state: 'gone' } tabData && tabData.tab === 'people' ? tabData : { state: 'gone' }
} }
gradesTabData={
tabData && tabData.tab === 'grades' ? tabData : { state: 'gone' }
}
isLoading={tabData && tabData.state === 'loading'} isLoading={tabData && tabData.state === 'loading'}
/> />
); );

View file

@ -19,4 +19,6 @@ export default class ProfessorService {
ProfessorApi.getClassroomAnnouncementsById(classId); ProfessorApi.getClassroomAnnouncementsById(classId);
fetchPeopleByClassId = classId => ProfessorApi.getPeopleByClassId(classId); fetchPeopleByClassId = classId => ProfessorApi.getPeopleByClassId(classId);
fetchGradesByClassId = classId => ProfessorApi.getGradesByClassId(classId);
} }

View file

@ -11,6 +11,7 @@ import {
allPeople, allPeople,
professorClassrooms, professorClassrooms,
assignmentsToReview, assignmentsToReview,
grades,
} from './responses'; } from './responses';
const CommonApi = { const CommonApi = {
@ -134,6 +135,13 @@ const ProfessorApi = {
data: assignmentsToReview, data: assignmentsToReview,
}; };
}), }),
getGradesByClassId: classId =>
sleep(400).then(() => {
console.log('Getting grades' + classId);
return {
data: grades,
};
}),
}; };
export { StudentApi, ProfessorApi, CommonApi }; export { StudentApi, ProfessorApi, CommonApi };

View file

@ -643,6 +643,13 @@ const allPeople = [
}, },
]; ];
// TODO: Mock correct data
const grades = [
{
id: 'Some grade',
},
];
const studentUser = { const studentUser = {
id: '123', id: '123',
ra: '0021123', ra: '0021123',
@ -693,4 +700,5 @@ export {
allUpcomingAssignments, allUpcomingAssignments,
professorClassrooms, professorClassrooms,
assignmentsToReview, assignmentsToReview,
grades,
}; };