Skip to content
Snippets Groups Projects
Commit c19fbd06 authored by Serdar D's avatar Serdar D
Browse files

Search angepasst.

parent a82ca115
No related branches found
No related tags found
1 merge request!6Sort + Search UI
Checking pipeline status
"use client"
import ArrowCircleRightRoundedIcon from '@mui/icons-material/ArrowCircleRightRounded'; import ArrowCircleRightRoundedIcon from '@mui/icons-material/ArrowCircleRightRounded';
import SearchIcon from '@mui/icons-material/Search'; import SearchIcon from '@mui/icons-material/Search';
import { Container, IconButton, InputAdornment, TextField } from '@mui/material'; import { Container, IconButton, InputAdornment, TextField } from '@mui/material';
import { useState } from 'react';
import { getGames } from '@/lib/igdb';
import { IGame } from '@/types/types';
import Game from './Game';
export default function Search() {
const [searchText, setSearchText] = useState('');
const [searchResults, setSearchResults] = useState<IGame[]>([]);
export default function SearchInput() { const handleSearch = (event: React.ChangeEvent<HTMLInputElement>) => {
const handleSearch = (event: { target: { value: any; }; }) => {
const searchText = event.target.value; const searchText = event.target.value;
console.log('Search:', searchText); setSearchText(searchText);
};
const handleSearchSubmit = async () => {
// Suche der Games durch eigene Sucheingaben.
const games = await getGames(); // Funktion um die Games aus Datenbank zu getten
//Es wird geschaut ob gamename(mit to lower Case), dem suchtext (searchText mit to lower case) entspricht.
const filteredGames = games.filter(game => game.name.toLowerCase().includes(searchText.toLowerCase()));
setSearchResults(filteredGames);
}; };
return ( return (
...@@ -14,6 +31,7 @@ export default function SearchInput() { ...@@ -14,6 +31,7 @@ export default function SearchInput() {
placeholder="Search" placeholder="Search"
variant="outlined" variant="outlined"
size="small" size="small"
value={searchText}
onChange={handleSearch} onChange={handleSearch}
InputProps={{ InputProps={{
startAdornment: ( startAdornment: (
...@@ -23,7 +41,8 @@ export default function SearchInput() { ...@@ -23,7 +41,8 @@ export default function SearchInput() {
), ),
endAdornment: ( endAdornment: (
<InputAdornment position="end"> <InputAdornment position="end">
<IconButton edge="end" aria-label="start search"> {/* Gesucht wird erst wenn auf Suche geklickt wird. */}
<IconButton edge="end" aria-label="start search" onClick={handleSearchSubmit}>
<ArrowCircleRightRoundedIcon /> <ArrowCircleRightRoundedIcon />
</IconButton> </IconButton>
</InputAdornment> </InputAdornment>
...@@ -33,6 +52,11 @@ export default function SearchInput() { ...@@ -33,6 +52,11 @@ export default function SearchInput() {
}, },
}} }}
/> />
{/* Anzeigen der Suchergebnisse */}
{searchResults.map(game => (
<Game key={game.id} id={game.id} name={game.name} cover={game.cover} />
))}
</Container> </Container>
); );
}; }
\ No newline at end of file \ No newline at end of file
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment