Skip to content
This repository has been archived by the owner on Oct 7, 2023. It is now read-only.

Commit

Permalink
feat: add loading
Browse files Browse the repository at this point in the history
  • Loading branch information
rwietter committed Jul 1, 2023
1 parent 81881b5 commit c685ab7
Show file tree
Hide file tree
Showing 12 changed files with 86 additions and 12 deletions.
4 changes: 2 additions & 2 deletions domains/dashboard/Dashboard.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -19,15 +19,15 @@ const Dashboard = ({ clinicalData }: ComponentProps): ReactNode => {
return <h1>Erro ao carregar dados</h1>;
}

if (loading) return <p className='text-zinc-950 text-center'>Carregando...</p>;
if (loading) return <DashboardSkeleton />;

const dataset = typeof data !== 'undefined' ? data : clinicalData;

return (
<div className='bg-primary overflow-hidden w-screen min-h-screen text-foreground font-sans'>
<Header />
<Sidebar />
<main className='px-2 md:px-12 m-auto md:ml-16 mt-16 bg-background rounded-tl-3xl'>
<main className='px-2 md:px-12 m-auto md:ml-16 min-h-[calc(100vh-4rem)] mt-16 bg-background rounded-tl-3xl'>
<Banner />
<Cards
countPatients={dataset?.countPatients}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -36,8 +36,6 @@ const DashboardSkeleton = (): ReactNode => (
<section className='w-full h-full grid xl:grid-cols-2 grid-flow-row py-8 gap-x-4 gap-y-14 max-w-full md:px-5 place-items-center'>
<GridItem />
<GridItem />
<GridItem />
<GridItem />
</section>
</main>
</div>
Expand Down
12 changes: 6 additions & 6 deletions domains/dashboard/features/Cards/Cards.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -10,29 +10,29 @@ const Cards: FC<CardProps> = ({ countPatients = 0, countDeadPatients = 0 }) => {
const confirmedCases = Intl.NumberFormat('pt-BR').format(countPatients);
const deaths = Intl.NumberFormat('pt-BR').format(countDeadPatients);

const fatality = countDeadPatients / countPatients;
const fatalityRate = (fatality * 100).toFixed(2);
const fatality: number = countDeadPatients / countPatients;
const fatalityRate = isNaN(fatality * 100) ? 0 : (fatality * 100).toFixed(2);

return (
<section className='w-full grid md:grid-cols-3 gap-6 lg:gap-25 xl:gap-32 px-5 pt-10'>
<div className='h-32 bg-white rounded-2xl flex flex-col flex-1 justify-evenly p-3 relative border-2 border-slate-200'>
<div className='absolute rounded-sm bg-indigo-600 border-green-400 left-[-3px] top-5 h-9 w-[.35rem]'></div>
<div className='absolute rounded-sm bg-indigo-600 border-green-400 left-[-3px] top-6 h-9 w-[.35rem]'></div>
<h1 className='text-xl uppercase font-normal font-sans text-foreground'>
Casos Confirmados
</h1>
<h2 className='text-xl text-foreground font-semibold'>{confirmedCases}</h2>
</div>

<div className='h-32 bg-white rounded-2xl flex flex-col flex-1 justify-evenly p-3 relative border-2 border-slate-200'>
<div className='absolute rounded-sm bg-rose-500 border-green-400 left-[-3px] top-5 h-9 w-[.35rem]'></div>
<div className='absolute rounded-sm bg-rose-500 border-green-400 left-[-3px] top-6 h-9 w-[.35rem]'></div>
<h1 className='text-xl font-normal uppercase font-sans text-foreground'>Mortes</h1>
<h2 className='text-xl text-slate-800 font-semibold'>{deaths}</h2>
</div>

<div className='h-32 bg-white rounded-2xl flex flex-col flex-1 justify-evenly p-3 relative border-2 border-slate-200'>
<div className='absolute rounded-sm bg-emerald-400 border-green-400 left-[-3px] top-5 h-9 w-[.35rem]'></div>
<div className='absolute rounded-sm bg-emerald-400 border-green-400 left-[-3px] top-6 h-9 w-[.35rem]'></div>
<h1 className='text-xl font-normal uppercase font-sans text-foreground'>Letalidade</h1>
<h2 className='text-xl text-foreground font-semibold'>{fatalityRate}%</h2>
<h2 className='text-xl text-foreground font-semibold'>{fatalityRate} %</h2>
</div>
</section>
);
Expand Down
2 changes: 1 addition & 1 deletion domains/dashboard/features/PatientsByAge/PatientsByAge.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@ const orderByAge = ({ countPatientsByAge }: IPatientsByAge): PatientByAge[] => {

const PatientsByAge: FC<IPatientsByAge> = ({ countPatientsByAge }) => {
// eslint-disable-next-line no-extra-boolean-cast
if (!Boolean(countPatientsByAge)) return null;
if (countPatientsByAge.length <= 0) return null;

const sortedDataChart = orderByAge({ countPatientsByAge });

Expand Down
2 changes: 1 addition & 1 deletion domains/dashboard/features/Sidebar/Sidebar.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@ const Sidebar = (): ReactNode => {
};

return (
<aside className='bg-primary bg-opacity-80 fixed w-full h-16 bottom-0 md:h-screen md:w-16 md:left-0 z-0 flex items-center justify-center md:flex-col backdrop-blur-sm'>
<aside className='bg-primary bg-opacity-80 fixed z-10 w-full h-16 bottom-0 md:h-screen md:w-16 md:left-0 z-0 flex items-center justify-center md:flex-col backdrop-blur-sm'>
<Link href='/' className={isLinkActive('/')}>
<BiHomeAlt size={23} color={isColorActive('/')} />
</Link>
Expand Down
2 changes: 2 additions & 0 deletions domains/dashboard/features/Symptoms/Symptoms.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,8 @@ const Symptoms: FC<ComponentProps> = ({ countPatientsSymptoms }) => {
const [, ...labels] = Object.keys(countPatientsSymptoms);
const [, ...values] = Object.values(countPatientsSymptoms);

if (values.every((count) => count <= 0)) return null;

const percentages = calculatePercentages(values);

const dataset = {
Expand Down
30 changes: 30 additions & 0 deletions package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

1 change: 1 addition & 0 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -53,6 +53,7 @@
"react-chartjs-2": "^5.2.0",
"react-dom": "^18.2.0",
"react-icons": "^4.9.0",
"react-topbar-progress-indicator": "^4.1.1",
"recharts": "^2.7.0",
"tailwindcss": "3.3.2",
"zustand": "^4.3.8"
Expand Down
2 changes: 2 additions & 0 deletions pages/_app.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,7 @@ import {
} from 'chart.js';
import { ApolloProvider } from '@apollo/client';
import { client } from '@/services/graphql/apollo';
import { LoadingIndicator } from '@/shared/components/LoadingIndicator';

ChartJS.defaults.scale.grid.display = false;

Expand Down Expand Up @@ -64,6 +65,7 @@ const MyApp = ({ Component, pageProps }: AppProps): ReactNode => {
content='covid, covid-19, covid19, coronavírus, pandemia, brasil, dados, informações, gráficos, gráficos interativos, gráficos animados, gráficos animados interativos, gráficos animados interativos covid-19'
/>
</Head>
<LoadingIndicator />
<ApolloProvider client={client}>
<Component {...pageProps} />
</ApolloProvider>
Expand Down
28 changes: 28 additions & 0 deletions shared/components/LoadingIndicator/LoadingIndicator.tsx
Original file line number Diff line number Diff line change
@@ -0,0 +1,28 @@
import { type ReactNode, useState } from 'react';
import LoaderRouterIndicator from 'react-topbar-progress-indicator';
import { Router } from 'next/router';

const LoadingIndicator = (): ReactNode => {
const [progress, setProgress] = useState(false);

LoaderRouterIndicator.config({
barColors: {
0: '#ffbe0b',
1.0: '#fb5607',
},
barThickness: 4,
shadowBlur: 0,
});

Router.events.on('routeChangeStart', () => {
setProgress(true);
});

Router.events.on('routeChangeComplete', () => {
setProgress(false);
});

return <div>{progress && <LoaderRouterIndicator />}</div>;
};

export { LoadingIndicator };
1 change: 1 addition & 0 deletions shared/components/LoadingIndicator/index.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
export { LoadingIndicator } from './LoadingIndicator';
12 changes: 12 additions & 0 deletions yarn.lock
Original file line number Diff line number Diff line change
Expand Up @@ -5089,6 +5089,13 @@
"prismjs" "^1.27.0"
"refractor" "^3.6.0"

"react-topbar-progress-indicator@^4.1.1":
"integrity" "sha512-Oy3ENNKfymt16zoz5SYy/WOepMurB0oeZEyvuHm8JZ3jrTCe1oAUD7fG6HhYt5sg8Wcg5gdkzSWItaFF6c6VhA=="
"resolved" "https://registry.npmjs.org/react-topbar-progress-indicator/-/react-topbar-progress-indicator-4.1.1.tgz"
"version" "4.1.1"
dependencies:
"topbar" "^0.1.3"

"react-transition-group@2.9.0":
"integrity" "sha512-+HzNTCHpeQyl4MJ/bdE0u6XRMe9+XG/+aL4mCxVN4DnPBQ0/5bfHWPDuOZUzYdMj94daZaZdCCc1Dzt9R/xSSg=="
"resolved" "https://registry.npmjs.org/react-transition-group/-/react-transition-group-2.9.0.tgz"
Expand Down Expand Up @@ -5842,6 +5849,11 @@
"resolved" "https://registry.npmjs.org/toggle-selection/-/toggle-selection-1.0.6.tgz"
"version" "1.0.6"

"topbar@^0.1.3":
"integrity" "sha512-P3n4WnN4GFd2mQXDo30rQmsAGe4V1bVkggtTreSbNyL50Fyc+eVkW5oatSLeGQmJoan2TLIgoXUZypN+6nw4MQ=="
"resolved" "https://registry.npmjs.org/topbar/-/topbar-0.1.4.tgz"
"version" "0.1.4"

"tough-cookie@~2.5.0":
"integrity" "sha512-nlLsUzgm1kfLXSXfRZMc1KLAugd4hqJHDTvc2hDIwS3mZAfMEuMbc03SujMF+GEcpaX/qboeycw6iO8JwVv2+g=="
"resolved" "https://registry.npmjs.org/tough-cookie/-/tough-cookie-2.5.0.tgz"
Expand Down

0 comments on commit c685ab7

Please sign in to comment.