Refactor: remove duplicated styles

This commit is contained in:
Mosh Hamedani 2023-03-01 11:05:50 -08:00
parent efcd3c596e
commit 83e825fe9c
4 changed files with 27 additions and 4 deletions

View file

@ -11,7 +11,7 @@ interface Props {
const GameCard = ({ game }: Props) => { const GameCard = ({ game }: Props) => {
return ( return (
<Card width='300px' borderRadius={10} overflow='hidden'> <Card>
<Image src={getCroppedImageUrl(game.background_image)} /> <Image src={getCroppedImageUrl(game.background_image)} />
<CardBody> <CardBody>
<Heading fontSize='2xl'>{game.name}</Heading> <Heading fontSize='2xl'>{game.name}</Heading>

View file

@ -0,0 +1,16 @@
import { Box } from "@chakra-ui/react";
import { ReactNode } from "react";
interface Props {
children: ReactNode;
}
const GameCardContainer = ({ children }: Props) => {
return (
<Box width="300px" borderRadius={10} overflow="hidden">
{children}
</Box>
);
};
export default GameCardContainer;

View file

@ -2,7 +2,7 @@ import { Card, CardBody, Skeleton, SkeletonText } from '@chakra-ui/react'
const GameCardSkeleton = () => { const GameCardSkeleton = () => {
return ( return (
<Card width='300px' borderRadius={10} overflow='hidden'> <Card>
<Skeleton height="200px" /> <Skeleton height="200px" />
<CardBody> <CardBody>
<SkeletonText /> <SkeletonText />

View file

@ -1,6 +1,7 @@
import { SimpleGrid, Text } from "@chakra-ui/react"; import { SimpleGrid, Text } from "@chakra-ui/react";
import useGames from "../hooks/useGames"; import useGames from "../hooks/useGames";
import GameCard from "./GameCard"; import GameCard from "./GameCard";
import GameCardContainer from "./GameCardContainer";
import GameCardSkeleton from "./GameCardSkeleton"; import GameCardSkeleton from "./GameCardSkeleton";
const GameGrid = () => { const GameGrid = () => {
@ -16,9 +17,15 @@ const GameGrid = () => {
spacing={10} spacing={10}
> >
{isLoading && {isLoading &&
skeletons.map((skeleton) => <GameCardSkeleton key={skeleton} />)} skeletons.map((skeleton) => (
<GameCardContainer>
<GameCardSkeleton key={skeleton} />
</GameCardContainer>
))}
{games.map((game) => ( {games.map((game) => (
<GameCard key={game.id} game={game} /> <GameCardContainer>
<GameCard key={game.id} game={game} />
</GameCardContainer>
))} ))}
</SimpleGrid> </SimpleGrid>
</> </>