mosh-game-hub/src/components/GameGrid.tsx

41 lines
1 KiB
TypeScript
Raw Normal View History

2023-02-28 21:17:58 +01:00
import { SimpleGrid, Text } from "@chakra-ui/react";
import useGames from "../hooks/useGames";
2023-03-02 18:23:53 +01:00
import { Genre } from "../hooks/useGenres";
2023-02-28 21:17:58 +01:00
import GameCard from "./GameCard";
2023-03-01 20:05:50 +01:00
import GameCardContainer from "./GameCardContainer";
2023-03-01 19:53:06 +01:00
import GameCardSkeleton from "./GameCardSkeleton";
2023-02-28 20:13:26 +01:00
2023-03-02 18:23:53 +01:00
interface Props {
selectedGenre: Genre | null
}
const GameGrid = ({ selectedGenre }: Props) => {
const { data, error, isLoading } = useGames(selectedGenre);
2023-03-01 19:53:06 +01:00
const skeletons = [1, 2, 3, 4, 5, 6];
2023-02-28 20:13:26 +01:00
return (
<>
{error && <Text>{error}</Text>}
2023-02-28 21:17:58 +01:00
<SimpleGrid
columns={{ sm: 1, md: 2, lg: 3, xl: 5 }}
padding="10px"
2023-03-02 16:25:08 +01:00
spacing={3}
2023-02-28 21:17:58 +01:00
>
2023-03-01 19:53:06 +01:00
{isLoading &&
2023-03-01 20:05:50 +01:00
skeletons.map((skeleton) => (
2023-03-02 18:23:53 +01:00
<GameCardContainer key={skeleton}>
<GameCardSkeleton />
2023-03-01 20:05:50 +01:00
</GameCardContainer>
))}
2023-03-01 22:03:57 +01:00
{data.map((game) => (
2023-03-02 18:23:53 +01:00
<GameCardContainer key={game.id}>
<GameCard game={game} />
2023-03-01 20:05:50 +01:00
</GameCardContainer>
2023-02-28 20:13:26 +01:00
))}
2023-02-28 21:17:58 +01:00
</SimpleGrid>
2023-02-28 20:13:26 +01:00
</>
);
};
export default GameGrid;