Add desktop skeleton loading for assignment

This commit is contained in:
Leonardo Murça 2022-09-17 17:02:27 -03:00
parent af37f8a863
commit fb6e3ba82a
3 changed files with 61 additions and 3 deletions

View file

@ -1,13 +1,22 @@
import parse from 'html-react-parser'; import parse from 'html-react-parser';
import { Box, Button, Container, Stack, Typography } from '@mui/material'; import {
Box,
Button,
Container,
Skeleton,
Stack,
Typography,
} from '@mui/material';
import dayjs from 'dayjs'; import dayjs from 'dayjs';
import { capitalizeFirstLetter } from '../../utils/capitalizeFirstLetter'; import { capitalizeFirstLetter } from '../../utils/capitalizeFirstLetter';
import styles from './styles'; import styles from './styles';
import { createArrayFrom1ToN } from '../../utils/createArrayFrom1ToN';
function View({ assignment, dropzone, layoutType }) { function View({ assignment, dropzone, layoutType }) {
const { const {
container, container,
loadingContainer,
headerStack, headerStack,
title, title,
classroomColorStack, classroomColorStack,
@ -21,7 +30,40 @@ function View({ assignment, dropzone, layoutType }) {
} = styles[layoutType]; } = styles[layoutType];
return assignment === null ? ( return assignment === null ? (
<h1>Loading...</h1> <Container sx={loadingContainer} disableGutters>
<Stack sx={headerStack}>
<Skeleton variant="rectangular" width="100%" height={60} />
<Skeleton
sx={{ marginTop: '20px' }}
variant="rectangular"
width="30%"
height={20}
/>
<Stack sx={subHeaderStack}>
<Skeleton variant="rectangular" width="20%" height={20} />
<Skeleton variant="rectangular" width="50%" height={20} />
</Stack>
</Stack>
<Stack sx={descriptionStack}>
{createArrayFrom1ToN(12).map(i => (
<Skeleton
key={i}
variant="text"
sx={{ marginTop: i % 4 === 1 && '20px', fontSize: '1rem' }}
/>
))}
</Stack>
<Stack sx={dropzoneStack} flexDirection="column" alignItems="flex-end">
<Skeleton variant="rectangular" width="100%" height={150} />
<Skeleton
sx={{ marginTop: '30px' }}
variant="rectangular"
width="30%"
height={40}
/>
</Stack>
</Container>
) : ( ) : (
<Container sx={container} disableGutters> <Container sx={container} disableGutters>
<Stack sx={headerStack}> <Stack sx={headerStack}>

View file

@ -7,6 +7,14 @@ const desktopContainer = {
marginTop: '30px', marginTop: '30px',
}; };
const desktopLoadingContainer = {
width: '100%',
display: 'flex',
flexDirection: 'column',
alignItems: 'center',
marginTop: '50px',
};
const desktopHeaderStack = { const desktopHeaderStack = {
width: '70%', width: '70%',
paddingBottom: '5px', paddingBottom: '5px',
@ -68,6 +76,7 @@ const desktopButton = {
const desktop = { const desktop = {
container: desktopContainer, container: desktopContainer,
loadingContainer: desktopLoadingContainer,
headerStack: desktopHeaderStack, headerStack: desktopHeaderStack,
title: desktopTitle, title: desktopTitle,
classroomColorStack: desktopClassroomColorStack, classroomColorStack: desktopClassroomColorStack,
@ -86,6 +95,11 @@ const mobileContainer = {
marginBottom: '100px', marginBottom: '100px',
}; };
const mobileLoadingContainer = {
...desktopLoadingContainer,
marginBottom: '100px',
};
const mobileHeaderStack = { const mobileHeaderStack = {
...desktopHeaderStack, ...desktopHeaderStack,
width: '90%', width: '90%',
@ -136,6 +150,7 @@ const mobileButton = {
const mobile = { const mobile = {
container: mobileContainer, container: mobileContainer,
loadingContainer: mobileLoadingContainer,
headerStack: mobileHeaderStack, headerStack: mobileHeaderStack,
title: mobileTitle, title: mobileTitle,
classroomColorStack: mobileClassroomColorStack, classroomColorStack: mobileClassroomColorStack,
@ -151,6 +166,7 @@ const mobile = {
// ========== Unset ========== // ========== Unset ==========
const unset = { const unset = {
container: null, container: null,
loadingContainer: null,
headerStack: null, headerStack: null,
title: null, title: null,
classroomColorStack: null, classroomColorStack: null,

View file

@ -53,7 +53,7 @@ const getAllAssignments = userId =>
}); });
const getAssignmentById = assignmentId => const getAssignmentById = assignmentId =>
sleep(400).then(() => { sleep(4000).then(() => {
console.log('Getting assignment by id ' + assignmentId); console.log('Getting assignment by id ' + assignmentId);
return { return {
data: allAssignments.filter(a => a.id === assignmentId)[0], data: allAssignments.filter(a => a.id === assignmentId)[0],