Extract announcements to separated container

This commit is contained in:
Leonardo Murça 2022-08-03 18:12:27 -03:00
parent 55f090f1fa
commit 2a0c5d49a0
7 changed files with 238 additions and 64 deletions

View file

@ -0,0 +1,33 @@
import { Avatar, Card, Stack, Typography } from '@mui/material';
import { Container } from '@mui/system';
import dayjs from 'dayjs';
import { styles } from './styles';
function AnnouncementCard({ announcement }) {
const { cardContainer, typographyName, typographyCreatedAt, textContainer } =
styles;
return (
<Card sx={cardContainer} elevation={4} variant="elevation">
<Stack alignItems="center" direction="row" spacing={1}>
<Avatar
key={announcement.user.id}
alt={announcement.user.name}
src={announcement.user.avatar}
/>
<Stack>
<Typography sx={typographyName} variant="body1">
{announcement.user.name}
</Typography>
<Typography sx={typographyCreatedAt} variant="body1">
{dayjs(announcement.createdAt).format('DD [de] MMM [de] YYYY')}
</Typography>
</Stack>
</Stack>
<Container sx={textContainer} disableGutters>
{announcement.text}
</Container>
</Card>
);
}
export default AnnouncementCard;

View file

@ -0,0 +1,26 @@
const cardContainer = {
width: '100%',
padding: '20px',
};
const typographyName = {
fontWeight: 400,
};
const typographyCreatedAt = {
fontWeight: 400,
fontSize: '12px',
};
const textContainer = {
marginTop: '20px',
};
const styles = {
cardContainer,
typographyName,
typographyCreatedAt,
textContainer,
};
export { styles };

View file

@ -2,6 +2,7 @@ import {
Avatar, Avatar,
AvatarGroup, AvatarGroup,
Container, Container,
Grid,
Paper, Paper,
Stack, Stack,
Tab, Tab,
@ -11,6 +12,7 @@ import {
} from '@mui/material'; } from '@mui/material';
import { TAB_OPTIONS } from './tabOptions'; import { TAB_OPTIONS } from './tabOptions';
import styles from './styles'; import styles from './styles';
import AnnouncementCard from '../../components/AnnouncementCard';
function View({ function View({
layoutType, layoutType,
@ -20,13 +22,19 @@ function View({
announcements, announcements,
}) { }) {
const { title, container, paper, tabs, avatar, tooltip } = styles[layoutType]; const { title, container, paper, tabs, avatar, tooltip } = styles[layoutType];
if (layoutType === 'desktop') {
return ( return (
<Container disableGutters sx={container}> <Container disableGutters sx={container}>
{classroom === null ? ( {classroom === null ? (
<h1>Loading...</h1> <h1>Loading...</h1>
) : ( ) : (
<Container disableGutters> <Container disableGutters>
<Paper sx={paper(classroom.color)} elevation={4} variant="elevation"> <Paper
sx={paper(classroom.color)}
elevation={4}
variant="elevation"
>
<h1 style={title}>{classroom.name}</h1> <h1 style={title}>{classroom.name}</h1>
<Stack alignItems="center" direction="row" spacing={1}> <Stack alignItems="center" direction="row" spacing={1}>
<AvatarGroup total={classroom.teachers.length}> <AvatarGroup total={classroom.teachers.length}>
@ -40,7 +48,11 @@ function View({
))} ))}
</AvatarGroup> </AvatarGroup>
<Tooltip title={classroom.teachers.map(t => t.name).join(', ')}> <Tooltip title={classroom.teachers.map(t => t.name).join(', ')}>
<Typography sx={tooltip} variant="body3" color="text.secondary"> <Typography
sx={tooltip}
variant="body3"
color="text.secondary"
>
{classroom.teachers.map(t => t.name).join(', ')} {classroom.teachers.map(t => t.name).join(', ')}
</Typography> </Typography>
</Tooltip> </Tooltip>
@ -62,27 +74,129 @@ function View({
{announcements === null ? ( {announcements === null ? (
<h1>Loading...</h1> <h1>Loading...</h1>
) : ( ) : (
announcements.data.map(announcement => ( <Grid sx={container} container spacing={2}>
<Paper <Grid item xs={4}>
sx={{ marginTop: '30px' }} <Container
disableGutters
sx={{
backgroundColor: 'tomato',
height: '100vh',
textAlign: 'center',
}}
>
Left
</Container>
</Grid>
<Grid item xs={8}>
<Stack
sx={{ width: '100%' }}
alignItems="center"
justifyContent="center"
flexWrap="wrap"
direction="row"
gap="30px"
>
{announcements.data.map(announcement => (
<AnnouncementCard
key={announcement.id} key={announcement.id}
announcement={announcement}
/>
))}
</Stack>
</Grid>
</Grid>
)}
</Container>
);
} else if (layoutType === 'mobile') {
return (
<Container disableGutters sx={container}>
{classroom === null ? (
<h1>Loading...</h1>
) : (
<Container disableGutters>
<Paper
sx={paper(classroom.color)}
elevation={4} elevation={4}
variant="elevation" variant="elevation"
> >
<h1 style={title}>{classroom.name}</h1>
<Stack alignItems="center" direction="row" spacing={1}> <Stack alignItems="center" direction="row" spacing={1}>
<AvatarGroup total={classroom.teachers.length}>
{classroom.teachers.map(t => (
<Avatar <Avatar
key={announcement.user.id} key={t.name}
alt={announcement.user.name} alt={t.name}
src={announcement.user.avatar} src={t.avatar}
sx={avatar}
/> />
<Typography variant="body1">{announcement.user.name}</Typography> ))}
</AvatarGroup>
<Tooltip title={classroom.teachers.map(t => t.name).join(', ')}>
<Typography
sx={tooltip}
variant="body3"
color="text.secondary"
>
{classroom.teachers.map(t => t.name).join(', ')}
</Typography>
</Tooltip>
</Stack> </Stack>
{announcement.text} <Tabs
value={selectedTabOption}
onChange={onSelectTabOption}
aria-label="Tabs para informações da disciplina"
variant="fullWidth"
sx={tabs}
>
{TAB_OPTIONS.map(option => (
<Tab key={option.value} label={option.lable} />
))}
</Tabs>
</Paper> </Paper>
)) </Container>
)}
{announcements === null ? (
<h1>Loading...</h1>
) : (
<Stack
alignItems="center"
justifyContent="center"
flexWrap="wrap"
direction="row"
gap="30px"
sx={{ marginTop: '30px' }}
>
<Container
disableGutters
sx={{
backgroundColor: 'tomato',
height: '400px',
textAlign: 'center',
}}
>
Left
</Container>
<Stack
sx={{ width: '100%' }}
alignItems="center"
justifyContent="center"
flexWrap="wrap"
direction="row"
gap="30px"
>
{announcements.data.map(announcement => (
<AnnouncementCard
key={announcement.id}
announcement={announcement}
/>
))}
</Stack>
</Stack>
)} )}
</Container> </Container>
); );
} }
}
export default View; export default View;

View file

@ -64,6 +64,7 @@ function Classroom() {
announcements={ announcements={
tabData && tabData.tab === 'announcements' ? tabData : null tabData && tabData.tab === 'announcements' ? tabData : null
} }
people={tabData && tabData.tab === 'people' ? tabData : null}
/> />
); );
} }

View file

@ -54,10 +54,10 @@ const mobileTitle = {
const mobileContainer = { const mobileContainer = {
width: '90%', width: '90%',
height: '100vh',
backgroundColor: '#red', backgroundColor: '#red',
padding: 0, padding: 0,
marginTop: '30px', marginTop: '30px',
paddingBottom: '100px',
}; };
const mobilePaper = classColor => ({ const mobilePaper = classColor => ({

View file

@ -147,9 +147,8 @@ const allAssignments = [
const allClassroomAnnouncements = [ const allClassroomAnnouncements = [
{ {
id: '850006245121695744', id: '850006245121695744',
classId: '321', createdAt: '2022-08-01T16:00:00.000Z',
createdAt: 'Thu Apr 06 15:24:15 +0000 2017', text: 'Mussum Ipsum, cacilds vidis litro abertis. Viva Forevis aptent taciti sociosqu ad litora torquent.Quem num gosta di mim que vai caçá sua turmis!Posuere libero varius. Nullam a nisl ut ante blandit hendrerit. Aenean sit amet nisi.Mais vale um bebadis conhecidiss, que um alcoolatra anonimis.\n\n Cevadis im ampola pa arma uma pindureta.Paisis, filhis, espiritis santis.Quem manda na minha terra sou euzis!Per aumento de cachacis, eu reclamis.',
text: '1/ Today we\u2019re sharing our vision for the future of the Twitter API platform!\nhttps://t.co/XweGngmxlP',
user: { user: {
id: '2342', id: '2342',
name: 'Carlos Alexandre Silva', name: 'Carlos Alexandre Silva',
@ -169,11 +168,11 @@ const allClassroomAnnouncements = [
}, },
], ],
}, },
attachments: null,
}, },
{ {
id: '39450273466121695744', id: '39450273466121695744',
classId: '321', createdAt: '2022-05-26T16:00:00.000Z',
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!', 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: { user: {
id: '2342', id: '2342',
@ -194,6 +193,7 @@ const allClassroomAnnouncements = [
}, },
], ],
}, },
attachments: null,
}, },
]; ];

View file

@ -28,7 +28,7 @@ const getClassroomAnnouncementsById = classId =>
sleep(3000).then(() => { sleep(3000).then(() => {
console.log('classId ' + classId); console.log('classId ' + classId);
return { return {
data: allClassroomAnnouncements.filter(c => c.classId === classId), data: allClassroomAnnouncements.filter(c => c.classroom.id === classId),
}; };
}); });