Skip to content

Commit

Permalink
add skeleton cards (#492)
Browse files Browse the repository at this point in the history
* add skeleton cards

* lint fixes
  • Loading branch information
GhostOf0days authored May 13, 2024
1 parent 4b884d1 commit 1663536
Show file tree
Hide file tree
Showing 2 changed files with 74 additions and 1 deletion.
63 changes: 63 additions & 0 deletions src/components/EateryCardSkeleton.tsx
Original file line number Diff line number Diff line change
@@ -0,0 +1,63 @@
import {
Card,
CardHeader,
styled,
Grid,
CardContent,
Avatar,
Skeleton,
} from '@mui/material';

const StyledCard = styled(Card)({
backgroundColor: '#23272A',
border: '2px solid rgba(0, 0, 0, 0.2)',
textAlign: 'left',
borderRadius: 7,
height: '100%',
justifyContent: 'flex-start',
});

const StyledCardHeader = styled(CardHeader)({
fontWeight: 500,
backgroundColor: '#1D1F21',
});

const SkeletonText = styled(Skeleton)({
marginBottom: '12px',
});

function EateryCardSkeleton() {
return (
<Grid item xs={12} md={4} lg={3} xl={3}>
<StyledCard>
<StyledCardHeader
title={
<Skeleton variant="text" sx={{ fontSize: '1rem' }} />
}
avatar={
<Avatar
sx={{
width: 12,
height: 12,
backgroundColor: '#1D1F21',
}}
>
<Skeleton
variant="circular"
width={40}
height={40}
/>
</Avatar>
}
/>
<CardContent>
<SkeletonText variant="text" sx={{ fontSize: '2rem' }} />
<SkeletonText variant="text" sx={{ fontSize: '1rem' }} />
<SkeletonText variant="text" sx={{ fontSize: '1.2rem' }} />
</CardContent>
</StyledCard>
</Grid>
);
}

export default EateryCardSkeleton;
12 changes: 11 additions & 1 deletion src/pages/ListPage.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@ import { Typography, Grid, Alert, styled } from '@mui/material';
import { useEffect, useMemo, useState, useLayoutEffect } from 'react';
import Fuse from 'fuse.js';
import EateryCard from '../components/EateryCard';
import EateryCardSkeleton from '../components/EateryCardSkeleton';
import NoResultsError from '../components/NoResultsError';
import getGreeting from '../util/greeting';
import './ListPage.css';
Expand Down Expand Up @@ -171,7 +172,16 @@ function ListPage({
/>
</header>
{(() => {
if (locations === undefined) return undefined; // still loading
if (locations === undefined) {
// Display skeleton cards while loading
return (
<Grid container spacing={2}>
{Array.from({ length: 36 }).map((_, index) => (
<EateryCardSkeleton key={index} />
))}
</Grid>
);
}
if (locations.length === 0)
return (
<ErrorText variant="h4">
Expand Down

0 comments on commit 1663536

Please sign in to comment.