From 54a849a84904a7b08a9eb668dc73a807dfda562a Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Leonardo=20Mur=C3=A7a?= Date: Thu, 11 Aug 2022 19:50:46 -0300 Subject: [PATCH] Refactir getSelectedTabData to use switch case --- src/screens/Classroom/index.js | 34 +++++++++++++++++++++++++++------- 1 file changed, 27 insertions(+), 7 deletions(-) diff --git a/src/screens/Classroom/index.js b/src/screens/Classroom/index.js index f86ae13..83f3d9e 100644 --- a/src/screens/Classroom/index.js +++ b/src/screens/Classroom/index.js @@ -31,19 +31,39 @@ function Classroom() { }); }, [fetchClassroomAnnouncements, fetchUpcomingAssignments, params.id]); + const fetchAndPopulateAssignmentsTabData = useCallback(async () => { + console.log('Fetch assignments'); + }, []); + + const fetchAndPopulatePoepleTabData = useCallback(async () => { + console.log('Fetch assignments'); + }, []); + useEffect(() => { async function getSelectedTabData() { setTabData(null); - if (selectedTabOption === 0) { - fetchAndPopulateAnnouncementsTabData(); - } else if (selectedTabOption === 1) { - console.log('Fetch assignments'); - } else if (selectedTabOption === 2) { - console.log('Fetch people'); + switch (selectedTabOption) { + case TAB_OPTIONS.announcements.value: + fetchAndPopulateAnnouncementsTabData(); + break; + case TAB_OPTIONS.assignments.value: + fetchAndPopulateAssignmentsTabData(); + break; + case TAB_OPTIONS.people.value: + fetchAndPopulatePoepleTabData(); + break; + default: + console.log('Invalid tab option'); } } getSelectedTabData(); - }, [selectedTabOption, params, fetchAndPopulateAnnouncementsTabData]); + }, [ + selectedTabOption, + params, + fetchAndPopulateAnnouncementsTabData, + fetchAndPopulateAssignmentsTabData, + fetchAndPopulatePoepleTabData, + ]); useEffect(() => { async function getClassroomById(classId) {