diff --git a/src/screens/Classroom/View.js b/src/screens/Classroom/View.js index 6d5c212..5bd84e7 100644 --- a/src/screens/Classroom/View.js +++ b/src/screens/Classroom/View.js @@ -12,7 +12,13 @@ import { import { TAB_OPTIONS } from './tabOptions'; import styles from './styles'; -function View({ layoutType, classroom, selectedTabOption, onSelectTabOption }) { +function View({ + layoutType, + classroom, + selectedTabOption, + onSelectTabOption, + announcements, +}) { const { title, container, paper, tabs, avatar, tooltip } = styles[layoutType]; return ( @@ -53,6 +59,28 @@ function View({ layoutType, classroom, selectedTabOption, onSelectTabOption }) { )} + {announcements === null ? ( +

Loading...

+ ) : ( + announcements.data.map(announcement => ( + + + + {announcement.user.name} + + {announcement.text} + + )) + )} ); } diff --git a/src/screens/Classroom/index.js b/src/screens/Classroom/index.js index cd27864..669c49a 100644 --- a/src/screens/Classroom/index.js +++ b/src/screens/Classroom/index.js @@ -14,7 +14,7 @@ function Classroom() { TAB_OPTIONS.map(o => o.value).indexOf('announcements') ); - const [announcements, setAnnouncements] = useState(null); + const [tabData, setTabData] = useState(null); const onSelectTabOption = (_, value) => { setSelectedTabOption(value); @@ -38,10 +38,14 @@ function Classroom() { useEffect(() => { async function getSelectedTabData() { + setTabData(null); if (selectedTabOption === 0) { console.log('Fetch announcements'); const result = await fetchClassroomAnnouncements(params.id); - setAnnouncements(result.data); + setTabData({ + tab: TAB_OPTIONS[selectedTabOption].value, + data: [...result.data], + }); } else if (selectedTabOption === 1) { console.log('Fetch assignments'); } else if (selectedTabOption === 2) { @@ -57,6 +61,9 @@ function Classroom() { classroom={classroom} selectedTabOption={selectedTabOption} onSelectTabOption={onSelectTabOption} + announcements={ + tabData && tabData.tab === 'announcements' ? tabData : null + } /> ); }