Refactor Information screen

This commit is contained in:
Leonardo Murça 2022-07-06 14:31:59 -03:00
parent 68be170ffe
commit 119dd7df4f
2 changed files with 140 additions and 29 deletions

View file

@ -9,34 +9,41 @@ import {
} from '@mui/material';
import { createArrayFrom1ToN } from '../../utils/createArrayFrom1ToN';
import styles from './styles';
function View({ faq, layoutType }) {
const {
stackContainer,
skeletonTitle,
skeletonQuestion,
skeletonStack,
accordionSkeletonStack,
title,
accordionSummary,
} = styles[layoutType];
if (layoutType === 'desktop') {
return (
<Stack sx={{ paddingTop: '80px' }} alignItems="center" height="100vh">
<Stack sx={stackContainer} alignItems="center" height="100vh">
{faq === null ? (
<Stack width="70%" alignItems="center" gap="10px">
<Skeleton
variant="rectangular"
width={500}
height={50}
sx={{ marginBottom: '20px' }}
/>
<Stack {...skeletonStack}>
<Skeleton {...skeletonTitle} />
{createArrayFrom1ToN(6).map(i => (
<Skeleton
key={i}
variant="rectangular"
width={window.innerWidth * 0.6}
height={50}
width={skeletonQuestion.width(window.innerWidth)}
height={skeletonQuestion.height}
/>
))}
</Stack>
) : faq.length !== 0 ? (
<Stack width="70%" alignItems="center" gap="10px">
<h1 style={{ textAlign: 'center' }}>Perguntas Frequentes</h1>
<Stack {...accordionSkeletonStack}>
<h1 style={title}>Perguntas Frequentes</h1>
{faq.map((f, index) => (
<Accordion key={index}>
<AccordionSummary
sx={{ backgroundColor: '#f7f7f7' }}
sx={accordionSummary}
expandIcon={<ExpandMore />}
aria-controls="panel1a-content"
id="panel1a-header"
@ -56,34 +63,26 @@ function View({ faq, layoutType }) {
);
} else if (layoutType === 'mobile') {
return (
<Stack
sx={{ paddingTop: '30px', paddingBottom: '100px' }}
alignItems="center"
>
<Stack sx={stackContainer} alignItems="center">
{faq === null ? (
<Stack width="70%" alignItems="center" gap="10px">
<Skeleton
variant="rectangular"
width={200}
height={50}
sx={{ marginBottom: '20px' }}
/>
<Stack {...skeletonStack}>
<Skeleton {...skeletonTitle} />
{createArrayFrom1ToN(6).map(i => (
<Skeleton
key={i}
variant="rectangular"
width={window.innerWidth * 0.9}
height={80}
width={skeletonQuestion.width(window.innerWidth)}
height={skeletonQuestion.height}
/>
))}
</Stack>
) : faq.length !== 0 ? (
<Stack width="90%" alignItems="center" gap="10px">
<h1 style={{ textAlign: 'center' }}>Perguntas Frequentes</h1>
<Stack {...accordionSkeletonStack}>
<h1 style={title}>Perguntas Frequentes</h1>
{faq.map((f, index) => (
<Accordion key={index}>
<AccordionSummary
sx={{ backgroundColor: '#f7f7f7' }}
sx={accordionSummary}
expandIcon={<ExpandMore />}
aria-controls="panel1a-content"
id="panel1a-header"

View file

@ -0,0 +1,112 @@
// ========== Desktop ==========
const desktopStackContainer = {
paddingTop: '80px',
};
const desktopSkeletonTitle = {
variant: 'rectangular',
width: 500,
height: 50,
sx: {
marginBottom: '20px',
},
};
const desktopSkeletonQuestion = {
width: innerWidth => innerWidth * 0.6,
height: 50,
};
const desktopSkeletonStack = {
width: '70%',
alignItems: 'center',
gap: '10px',
};
const desktopAccordionSkeletonStack = {
width: '70%',
alignItems: 'center',
gap: '10px',
};
const desktopTitle = {
textAlign: 'center',
};
const desktopAccordionSummary = {
backgroundColor: '#f7f7f7',
};
const desktop = {
stackContainer: desktopStackContainer,
skeletonTitle: desktopSkeletonTitle,
skeletonQuestion: desktopSkeletonQuestion,
skeletonStack: desktopSkeletonStack,
accordionSkeletonStack: desktopAccordionSkeletonStack,
title: desktopTitle,
accordionSummary: desktopAccordionSummary,
};
// ========== Mobile ==========
const mobileStackContainer = {
paddingTop: '30px',
paddingBottom: '100px',
};
const mobileSkeletonTitle = {
variant: 'rectangular',
width: 200,
height: 50,
sx: {
marginBottom: '20px',
},
};
const mobileSkeletonQuestion = {
width: innerWidth => innerWidth * 0.9,
height: 80,
};
const mobileSkeletonStack = {
width: '70%',
alignItems: 'center',
gap: '10px',
};
const mobileAccordionSkeletonStack = {
width: '90%',
alignItems: 'center',
gap: '10px',
};
const mobileTitle = {
textAlign: 'center',
};
const mobileAccordionSummary = {
backgroundColor: '#f7f7f7',
};
const mobile = {
stackContainer: mobileStackContainer,
skeletonTitle: mobileSkeletonTitle,
skeletonQuestion: mobileSkeletonQuestion,
skeletonStack: mobileSkeletonStack,
accordionSkeletonStack: mobileAccordionSkeletonStack,
title: mobileTitle,
accordionSummary: mobileAccordionSummary,
};
// ========== Unset ==========
const unset = {
stackContainer: null,
skeletonTitle: null,
skeletonQuestion: null,
skeletonStack: null,
accordionSkeletonStack: null,
title: null,
accordionSummary: null,
};
const styles = { desktop, mobile, unset };
export default styles;