Build platform selector

This commit is contained in:
Mosh Hamedani 2023-03-02 10:45:45 -08:00
parent 7df3a833d9
commit 577c8c75a6
3 changed files with 35 additions and 0 deletions

View file

@ -3,6 +3,7 @@ import { useState } from "react";
import GameGrid from "./components/GameGrid"; import GameGrid from "./components/GameGrid";
import GenreList from "./components/GenreList"; import GenreList from "./components/GenreList";
import NavBar from "./components/NavBar"; import NavBar from "./components/NavBar";
import PlatformSelector from "./components/PlatformSelector";
import { Genre } from "./hooks/useGenres"; import { Genre } from "./hooks/useGenres";
function App() { function App() {
@ -28,6 +29,7 @@ function App() {
</GridItem> </GridItem>
</Show> </Show>
<GridItem area="main"> <GridItem area="main">
<PlatformSelector />
<GameGrid selectedGenre={selectedGenre} /> <GameGrid selectedGenre={selectedGenre} />
</GridItem> </GridItem>
</Grid> </Grid>

View file

@ -0,0 +1,22 @@
import { Button, Menu, MenuButton, MenuItem, MenuList } from "@chakra-ui/react";
import { BsChevronDown } from "react-icons/bs";
import usePlatforms from "../hooks/usePlatforms";
const PlatformSelector = () => {
const { data, error } = usePlatforms();
if (error) return null;
return (
<Menu>
<MenuButton as={Button} rightIcon={<BsChevronDown />}>
Platforms
</MenuButton>
<MenuList>
{data.map(platform => <MenuItem key={platform.id}>{platform.name}</MenuItem>)}
</MenuList>
</Menu>
);
};
export default PlatformSelector;

11
src/hooks/usePlatforms.ts Normal file
View file

@ -0,0 +1,11 @@
import useData from "./useData";
interface Platform {
id: number;
name: string;
slug: string;
}
const usePlatforms = () => useData<Platform>('/platforms/lists/parents');
export default usePlatforms;