Refactir getSelectedTabData to use switch case

This commit is contained in:
Leonardo Murça 2022-08-11 19:50:46 -03:00
parent 49163a9d7f
commit 54a849a849

View file

@ -31,19 +31,39 @@ function Classroom() {
}); });
}, [fetchClassroomAnnouncements, fetchUpcomingAssignments, params.id]); }, [fetchClassroomAnnouncements, fetchUpcomingAssignments, params.id]);
const fetchAndPopulateAssignmentsTabData = useCallback(async () => {
console.log('Fetch assignments');
}, []);
const fetchAndPopulatePoepleTabData = useCallback(async () => {
console.log('Fetch assignments');
}, []);
useEffect(() => { useEffect(() => {
async function getSelectedTabData() { async function getSelectedTabData() {
setTabData(null); setTabData(null);
if (selectedTabOption === 0) { switch (selectedTabOption) {
case TAB_OPTIONS.announcements.value:
fetchAndPopulateAnnouncementsTabData(); fetchAndPopulateAnnouncementsTabData();
} else if (selectedTabOption === 1) { break;
console.log('Fetch assignments'); case TAB_OPTIONS.assignments.value:
} else if (selectedTabOption === 2) { fetchAndPopulateAssignmentsTabData();
console.log('Fetch people'); break;
case TAB_OPTIONS.people.value:
fetchAndPopulatePoepleTabData();
break;
default:
console.log('Invalid tab option');
} }
} }
getSelectedTabData(); getSelectedTabData();
}, [selectedTabOption, params, fetchAndPopulateAnnouncementsTabData]); }, [
selectedTabOption,
params,
fetchAndPopulateAnnouncementsTabData,
fetchAndPopulateAssignmentsTabData,
fetchAndPopulatePoepleTabData,
]);
useEffect(() => { useEffect(() => {
async function getClassroomById(classId) { async function getClassroomById(classId) {