mirror of
https://github.com/mosh-hamedani/game-hub.git
synced 2026-05-21 12:14:32 +02:00
Implement searching
This commit is contained in:
parent
7c572a4560
commit
f002e86214
|
|
@ -13,6 +13,7 @@ export interface GameQuery {
|
||||||
genre: Genre | null;
|
genre: Genre | null;
|
||||||
platform: Platform | null;
|
platform: Platform | null;
|
||||||
sortOrder: string;
|
sortOrder: string;
|
||||||
|
searchText: string;
|
||||||
}
|
}
|
||||||
|
|
||||||
function App() {
|
function App() {
|
||||||
|
|
@ -30,7 +31,7 @@ function App() {
|
||||||
}}
|
}}
|
||||||
>
|
>
|
||||||
<GridItem area="nav">
|
<GridItem area="nav">
|
||||||
<NavBar />
|
<NavBar onSearch={(searchText) => setGameQuery({ ...gameQuery, searchText })} />
|
||||||
</GridItem>
|
</GridItem>
|
||||||
<Show above="lg">
|
<Show above="lg">
|
||||||
<GridItem area="aside" paddingX={5}>
|
<GridItem area="aside" paddingX={5}>
|
||||||
|
|
|
||||||
|
|
@ -3,11 +3,15 @@ import logo from '../assets/logo.webp';
|
||||||
import ColorModeSwitch from './ColorModeSwitch';
|
import ColorModeSwitch from './ColorModeSwitch';
|
||||||
import SearchInput from './SearchInput';
|
import SearchInput from './SearchInput';
|
||||||
|
|
||||||
const NavBar = () => {
|
interface Props {
|
||||||
|
onSearch: (searchText: string) => void;
|
||||||
|
}
|
||||||
|
|
||||||
|
const NavBar = ({ onSearch }: Props) => {
|
||||||
return (
|
return (
|
||||||
<HStack padding='10px'>
|
<HStack padding='10px'>
|
||||||
<Image src={logo} boxSize='60px' />
|
<Image src={logo} boxSize='60px' />
|
||||||
<SearchInput />
|
<SearchInput onSearch={onSearch} />
|
||||||
<ColorModeSwitch />
|
<ColorModeSwitch />
|
||||||
</HStack>
|
</HStack>
|
||||||
)
|
)
|
||||||
|
|
|
||||||
|
|
@ -1,12 +1,24 @@
|
||||||
import { Input, InputGroup, InputLeftElement } from "@chakra-ui/react";
|
import { Input, InputGroup, InputLeftElement } from "@chakra-ui/react";
|
||||||
|
import { useRef } from "react";
|
||||||
import { BsSearch } from "react-icons/bs";
|
import { BsSearch } from "react-icons/bs";
|
||||||
|
|
||||||
const SearchInput = () => {
|
interface Props {
|
||||||
|
onSearch: (searchText: string) => void;
|
||||||
|
}
|
||||||
|
|
||||||
|
const SearchInput = ({ onSearch }: Props) => {
|
||||||
|
const ref = useRef<HTMLInputElement>(null);
|
||||||
|
|
||||||
return (
|
return (
|
||||||
<InputGroup>
|
<form onSubmit={(event) => {
|
||||||
<InputLeftElement children={<BsSearch />} />
|
event.preventDefault();
|
||||||
<Input borderRadius={20} placeholder="Search games..." variant="filled" />
|
if (ref.current) onSearch(ref.current.value);
|
||||||
</InputGroup>
|
}}>
|
||||||
|
<InputGroup>
|
||||||
|
<InputLeftElement children={<BsSearch />} />
|
||||||
|
<Input ref={ref} borderRadius={20} placeholder="Search games..." variant="filled" />
|
||||||
|
</InputGroup>
|
||||||
|
</form>
|
||||||
);
|
);
|
||||||
};
|
};
|
||||||
|
|
||||||
|
|
|
||||||
|
|
@ -23,7 +23,8 @@ const useGames = (gameQuery: GameQuery) =>
|
||||||
params: {
|
params: {
|
||||||
genres: gameQuery.genre?.id,
|
genres: gameQuery.genre?.id,
|
||||||
platforms: gameQuery.platform?.id,
|
platforms: gameQuery.platform?.id,
|
||||||
ordering: gameQuery.sortOrder
|
ordering: gameQuery.sortOrder,
|
||||||
|
search: gameQuery.searchText
|
||||||
},
|
},
|
||||||
},
|
},
|
||||||
[gameQuery]
|
[gameQuery]
|
||||||
|
|
|
||||||
|
|
@ -0,0 +1,3 @@
|
||||||
|
form {
|
||||||
|
width: 100%;
|
||||||
|
}
|
||||||
Loading…
Reference in a new issue