From c3b820e05c363ce61d876f23ac5d20a3d104fd0a Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Leonardo=20Mur=C3=A7a?= Date: Tue, 21 Jun 2022 14:55:39 -0300 Subject: [PATCH] Create list of classrooms for home page --- src/components/ClassCard.js | 54 ++++++++++++++++++++++++++++++++ src/context/user.js | 58 +++++++++++++++++++++++------------ src/screens/Home/index.js | 61 +++++++++++++++++++++++++++++++++---- 3 files changed, 147 insertions(+), 26 deletions(-) create mode 100644 src/components/ClassCard.js diff --git a/src/components/ClassCard.js b/src/components/ClassCard.js new file mode 100644 index 0000000..6131912 --- /dev/null +++ b/src/components/ClassCard.js @@ -0,0 +1,54 @@ +import { + Card, + CardContent, + Typography, + CardActionArea, + Container, + Avatar, + Stack, +} from '@mui/material'; + +function ClassCard({ abbreviation, title, teachers }) { + return ( + + + +

{abbreviation}

+
+ + + {title} + + {teachers.map(teacher => ( + + + + {teacher.name} + + + ))} + +
+
+ ); +} + +export default ClassCard; diff --git a/src/context/user.js b/src/context/user.js index 291084c..4e768fb 100644 --- a/src/context/user.js +++ b/src/context/user.js @@ -11,27 +11,55 @@ const getClassrooms = userId => { name: 'Introdução à Ciência de Dados', abbreviation: 'ICD', - teacher: 'Carlos Alexandre Silva', + teachers: [ + { + name: 'Carlos Alexandre Silva', + avatar: + 'https://lh3.googleusercontent.com/a-/AOh14GgmBInEbkv1D4FuLyz64phoyOfI4Y8kql8LYVy0_w=s75-c', + }, + ], }, { name: 'Gestão de Projetos', abbreviation: 'GP', - teacher: 'Míriam Lúcia Barbosa', + teachers: [ + { + name: 'Míriam Lúcia Barbosa', + avatar: '/assets/miriam.jpg', + }, + ], }, { name: 'Banco de Dados II', abbreviation: 'BDII', - teacher: 'Cristiane Norbiato Targa', + teachers: [ + { + name: 'Cristiane Norbiato Targa', + avatar: + 'https://lh3.googleusercontent.com/a-/AOh14GhwNeQ0h2eKl2WXGuwyDzvLWtrvyrG2kJtZ7A1EBw=s75-c', + }, + ], }, { name: 'Contabilidade Básica', abbreviation: 'CB', - teacher: 'Alexandre Couto Cardoso', + teachers: [ + { + name: 'Alexandre Couto Cardoso', + avatar: '/assets/alex.jpg', + }, + ], }, { name: 'Linguagens de Programação', abbreviation: 'LP', - teacher: 'Gabriel Felipe Cândido Novy', + teachers: [ + { + name: 'Gabriel Felipe Cândido Novy', + avatar: + 'https://lh3.googleusercontent.com/a-/AOh14GgvfrD--cl25V_3UOAR93sN_jKdYNJ9PXhUH2zXhQ=s75-c', + }, + ], }, ], }; @@ -45,7 +73,6 @@ function UserProvider(props) { const [state, setState] = useState({ status: 'idle', user: null, - classrooms: [], error: null, pathname: '', }); @@ -54,30 +81,21 @@ function UserProvider(props) { setState({ user, pathname }); }, [user, pathname]); - const classrooms = () => { - setState({ ...state, status: 'pending' }); - getClassrooms(user.id).then(data => - setState({ - status: 'success', - user, - classrooms: data.data, - error: null, - pathname, - }) - ); + const fetchClassrooms = () => { + return getClassrooms(user.id); }; - return ; + return ; } function useUser() { - const { state, classrooms } = useContext(UserContext); + const { state, fetchClassrooms } = useContext(UserContext); const isPending = state.status === 'pending'; return { state, isPending, - classrooms, + fetchClassrooms, }; } diff --git a/src/screens/Home/index.js b/src/screens/Home/index.js index cf56389..24bd98a 100644 --- a/src/screens/Home/index.js +++ b/src/screens/Home/index.js @@ -1,14 +1,63 @@ +import { useEffect, useState } from 'react'; +import { CircularProgress, Grid, Stack } from '@mui/material'; import { useUser } from '../../context/user'; +import ClassCard from '../../components/ClassCard'; + function Home() { - const { isPending, classrooms } = useUser(); + const { fetchClassrooms } = useUser(); + const [classrooms, setClassrooms] = useState(null); + + useEffect(() => { + async function getClassrooms() { + const result = await fetchClassrooms(); + setClassrooms(result.data); + } + getClassrooms(); + }, [fetchClassrooms]); return ( -
-

Página inicial

- - {isPending &&

Loading...

} -
+ + +

Turmas

+ + {classrooms === null ? ( + + ) : classrooms.length !== 0 ? ( + classrooms.map(classroom => ( + + )) + ) : ( +

Nenhuma sala de aula encontrada!

+ )} +
+
+ +

Atividades

+

Atribuídas

+ + {classrooms === null ? ( + + ) : classrooms.length !== 0 ? ( + classrooms.map(classroom => ( + + )) + ) : ( +

Nenhuma sala de aula encontrada!

+ )} +
+
+
); }