2023-02-28 21:17:58 +01:00
|
|
|
import { SimpleGrid, Text } from "@chakra-ui/react";
|
2023-03-02 21:01:04 +01:00
|
|
|
import { GameQuery } from "../App";
|
2023-03-02 20:25:18 +01:00
|
|
|
import useGames, { Platform } 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 {
|
2023-03-02 21:01:04 +01:00
|
|
|
gameQuery: GameQuery
|
2023-03-02 18:23:53 +01:00
|
|
|
}
|
|
|
|
|
|
2023-03-02 21:01:04 +01:00
|
|
|
const GameGrid = ({ gameQuery }: Props) => {
|
|
|
|
|
const { data, error, isLoading } = useGames(gameQuery);
|
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
|
2023-03-06 17:10:03 +01:00
|
|
|
columns={{ sm: 1, md: 2, lg: 3, xl: 4 }}
|
2023-02-28 21:17:58 +01:00
|
|
|
padding="10px"
|
2023-03-06 17:10:03 +01:00
|
|
|
spacing={6}
|
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;
|