Add classroom announcements fetch

This commit is contained in:
Leonardo Murça 2022-08-03 16:03:45 -03:00
parent 291da0589f
commit e9103bc956
4 changed files with 116 additions and 4 deletions

View file

@ -3,6 +3,7 @@ import { useLocation } from 'react-router-dom';
import { useAuthState } from './auth'; import { useAuthState } from './auth';
import { import {
getAssignments, getAssignments,
getClassroomAnnouncementsById,
getClassroomById, getClassroomById,
getClassrooms, getClassrooms,
getFaq, getFaq,
@ -31,6 +32,9 @@ function UserProvider(props) {
const fetchFAQ = () => getFaq(); const fetchFAQ = () => getFaq();
const fetchClassroomAnnouncements = classId =>
getClassroomAnnouncementsById(classId);
return ( return (
<UserContext.Provider <UserContext.Provider
value={{ value={{
@ -39,6 +43,7 @@ function UserProvider(props) {
fetchAssignments, fetchAssignments,
fetchClassroomById, fetchClassroomById,
fetchFAQ, fetchFAQ,
fetchClassroomAnnouncements,
}} }}
{...props} {...props}
/> />
@ -52,6 +57,7 @@ function useUser() {
fetchAssignments, fetchAssignments,
fetchClassroomById, fetchClassroomById,
fetchFAQ, fetchFAQ,
fetchClassroomAnnouncements,
} = useContext(UserContext); } = useContext(UserContext);
return { return {
@ -60,6 +66,7 @@ function useUser() {
fetchAssignments, fetchAssignments,
fetchClassroomById, fetchClassroomById,
fetchFAQ, fetchFAQ,
fetchClassroomAnnouncements,
}; };
} }

View file

@ -8,12 +8,14 @@ import View from './View';
function Classroom() { function Classroom() {
const params = useParams(); const params = useParams();
const layoutType = useLayoutType(); const layoutType = useLayoutType();
const { fetchClassroomById } = useUser(); const { fetchClassroomById, fetchClassroomAnnouncements } = useUser();
const [classroom, setClassroom] = useState(null); const [classroom, setClassroom] = useState(null);
const [selectedTabOption, setSelectedTabOption] = useState( const [selectedTabOption, setSelectedTabOption] = useState(
TAB_OPTIONS.map(o => o.value).indexOf('announcements') TAB_OPTIONS.map(o => o.value).indexOf('announcements')
); );
const [announcements, setAnnouncements] = useState(null);
const onSelectTabOption = (_, value) => { const onSelectTabOption = (_, value) => {
setSelectedTabOption(value); setSelectedTabOption(value);
}; };
@ -34,6 +36,21 @@ function Classroom() {
} }
}, [classroom]); }, [classroom]);
useEffect(() => {
async function getSelectedTabData() {
if (selectedTabOption === 0) {
console.log('Fetch announcements');
const result = await fetchClassroomAnnouncements(params.id);
setAnnouncements(result.data);
} else if (selectedTabOption === 1) {
console.log('Fetch assignments');
} else if (selectedTabOption === 2) {
console.log('Fetch people');
}
}
getSelectedTabData();
}, [fetchClassroomAnnouncements, selectedTabOption, params]);
return ( return (
<View <View
layoutType={layoutType} layoutType={layoutType}

View file

@ -6,6 +6,7 @@ const allClassrooms = [
color: '#006FF2', color: '#006FF2',
teachers: [ teachers: [
{ {
id: '2342',
name: 'Carlos Alexandre Silva', name: 'Carlos Alexandre Silva',
avatar: avatar:
'https://images.unsplash.com/photo-1535713875002-d1d0cf377fde?ixlib=rb-1.2.1&ixid=MnwxMjA3fDB8MHxwaG90by1wYWdlfHx8fGVufDB8fHx8&auto=format&fit=crop&w=50&q=80', 'https://images.unsplash.com/photo-1535713875002-d1d0cf377fde?ixlib=rb-1.2.1&ixid=MnwxMjA3fDB8MHxwaG90by1wYWdlfHx8fGVufDB8fHx8&auto=format&fit=crop&w=50&q=80',
@ -19,11 +20,13 @@ const allClassrooms = [
color: '#7900F2', color: '#7900F2',
teachers: [ teachers: [
{ {
id: '1234',
name: 'Míriam Lúcia Barbosa', name: 'Míriam Lúcia Barbosa',
avatar: avatar:
'https://images.unsplash.com/photo-1580489944761-15a19d654956?ixlib=rb-1.2.1&ixid=MnwxMjA3fDB8MHxwaG90by1wYWdlfHx8fGVufDB8fHx8&auto=format&fit=crop&w=50&q=80', 'https://images.unsplash.com/photo-1580489944761-15a19d654956?ixlib=rb-1.2.1&ixid=MnwxMjA3fDB8MHxwaG90by1wYWdlfHx8fGVufDB8fHx8&auto=format&fit=crop&w=50&q=80',
}, },
{ {
id: '4321',
name: 'Alexandre Couto Cardoso', name: 'Alexandre Couto Cardoso',
avatar: '/assets/alex.jpg', avatar: '/assets/alex.jpg',
}, },
@ -36,6 +39,7 @@ const allClassrooms = [
color: '#FF7A00', color: '#FF7A00',
teachers: [ teachers: [
{ {
id: '6781',
name: 'Cristiane Norbiato Targa', name: 'Cristiane Norbiato Targa',
avatar: avatar:
'https://lh3.googleusercontent.com/a-/AOh14GhwNeQ0h2eKl2WXGuwyDzvLWtrvyrG2kJtZ7A1EBw=s75-c', 'https://lh3.googleusercontent.com/a-/AOh14GhwNeQ0h2eKl2WXGuwyDzvLWtrvyrG2kJtZ7A1EBw=s75-c',
@ -49,6 +53,7 @@ const allClassrooms = [
color: '#BB0000', color: '#BB0000',
teachers: [ teachers: [
{ {
id: '4321',
name: 'Alexandre Couto Cardoso', name: 'Alexandre Couto Cardoso',
avatar: '/assets/alex.jpg', avatar: '/assets/alex.jpg',
}, },
@ -61,6 +66,7 @@ const allClassrooms = [
color: '#039200', color: '#039200',
teachers: [ teachers: [
{ {
id: '9999',
name: 'Gabriel Felipe Cândido Novy', name: 'Gabriel Felipe Cândido Novy',
avatar: avatar:
'https://lh3.googleusercontent.com/a-/AOh14GgvfrD--cl25V_3UOAR93sN_jKdYNJ9PXhUH2zXhQ=s75-c', 'https://lh3.googleusercontent.com/a-/AOh14GgvfrD--cl25V_3UOAR93sN_jKdYNJ9PXhUH2zXhQ=s75-c',
@ -138,6 +144,59 @@ const allAssignments = [
}, },
]; ];
const allClassroomAnnouncements = [
{
id: '850006245121695744',
classId: '321',
createdAt: 'Thu Apr 06 15:24:15 +0000 2017',
text: '1/ Today we\u2019re sharing our vision for the future of the Twitter API platform!\nhttps://t.co/XweGngmxlP',
user: {
id: '2342',
name: 'Carlos Alexandre Silva',
avatar:
'https://images.unsplash.com/photo-1535713875002-d1d0cf377fde?ixlib=rb-1.2.1&ixid=MnwxMjA3fDB8MHxwaG90by1wYWdlfHx8fGVufDB8fHx8&auto=format&fit=crop&w=50&q=80',
},
classroom: {
id: '321',
name: 'Introdução à Ciência de Dados',
abbreviation: 'ICD',
color: '#006FF2',
teachers: [
{
name: 'Carlos Alexandre Silva',
avatar:
'https://images.unsplash.com/photo-1535713875002-d1d0cf377fde?ixlib=rb-1.2.1&ixid=MnwxMjA3fDB8MHxwaG90by1wYWdlfHx8fGVufDB8fHx8&auto=format&fit=crop&w=50&q=80',
},
],
},
},
{
id: '39450273466121695744',
classId: '321',
createdAt: 'Thu Apr 06 15:24:15 +0000 2017',
text: 'Mussum Ipsum, cacilds vidis litro abertis. Quem manda na minha terra sou euzis!Viva Forevis aptent taciti sociosqu ad litora torquent.Nullam volutpat risus nec leo commodo, ut interdum diam laoreet. Sed non consequat odio.Quem num gosta di mim que vai caçá sua turmis!',
user: {
id: '2342',
name: 'Carlos Alexandre Silva',
avatar:
'https://images.unsplash.com/photo-1535713875002-d1d0cf377fde?ixlib=rb-1.2.1&ixid=MnwxMjA3fDB8MHxwaG90by1wYWdlfHx8fGVufDB8fHx8&auto=format&fit=crop&w=50&q=80',
},
classroom: {
id: '321',
name: 'Introdução à Ciência de Dados',
abbreviation: 'ICD',
color: '#006FF2',
teachers: [
{
name: 'Carlos Alexandre Silva',
avatar:
'https://images.unsplash.com/photo-1535713875002-d1d0cf377fde?ixlib=rb-1.2.1&ixid=MnwxMjA3fDB8MHxwaG90by1wYWdlfHx8fGVufDB8fHx8&auto=format&fit=crop&w=50&q=80',
},
],
},
},
];
const faq = [ const faq = [
{ {
question: 'Como faço para acessar a biblicoteca virtual?', question: 'Como faço para acessar a biblicoteca virtual?',
@ -178,4 +237,11 @@ const authFailure = {
message: 'Falha na autenticação', message: 'Falha na autenticação',
}; };
export { allClassrooms, allAssignments, faq, user, authFailure }; export {
allClassrooms,
allAssignments,
allClassroomAnnouncements,
faq,
user,
authFailure,
};

View file

@ -1,5 +1,12 @@
import { sleep } from '../utils/sleep'; import { sleep } from '../utils/sleep';
import { allClassrooms, allAssignments, faq, user, authFailure } from './mocks'; import {
allClassrooms,
allAssignments,
faq,
user,
authFailure,
allClassroomAnnouncements,
} from './mocks';
const getClassrooms = userId => const getClassrooms = userId =>
sleep(3000).then(() => { sleep(3000).then(() => {
@ -17,6 +24,14 @@ const getClassroomById = classId =>
}; };
}); });
const getClassroomAnnouncementsById = classId =>
sleep(3000).then(() => {
console.log('classId ' + classId);
return {
data: allClassroomAnnouncements.filter(c => c.classId === classId),
};
});
const getAssignments = userId => const getAssignments = userId =>
sleep(4000).then(() => { sleep(4000).then(() => {
console.log('userId: ' + userId); console.log('userId: ' + userId);
@ -43,4 +58,11 @@ const getUser = shouldFail =>
} }
}); });
export { getClassrooms, getClassroomById, getAssignments, getFaq, getUser }; export {
getClassrooms,
getClassroomById,
getAssignments,
getClassroomAnnouncementsById,
getFaq,
getUser,
};