Skip to content
This repository has been archived by the owner on Sep 29, 2024. It is now read-only.

Commit

Permalink
Improve search functionality and display
Browse files Browse the repository at this point in the history
  • Loading branch information
mirak55 committed Jun 10, 2024
1 parent 6c06f17 commit 83b0e7f
Showing 1 changed file with 9 additions and 7 deletions.
16 changes: 9 additions & 7 deletions frontend/src/components/SearchSite/SearchSite.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@ export default function SearchSite({ allRecipes }: { allRecipes: any[] }) {
}
}

let heading = "Unsere Empfehlungen"


const randomRecipes = allRecipes
.sort(() => Math.random() - Math.random())
Expand Down Expand Up @@ -54,14 +54,15 @@ export default function SearchSite({ allRecipes }: { allRecipes: any[] }) {

const [searchInput, setSearchInput] = useState<string>('');
const [filteredRecipes, setFilteredRecipes] = useState(allRecipes);

const [heading, setHeading] = useState<string>("Unsere Empfehlungen");
const [recipes, setRecipes] = useState<string>("items");

const handleSearch = () => {
const filteredRecipes = allRecipes.filter(recipe =>
recipe.name.toLowerCase().includes(searchInput)
recipe.name.toLowerCase().includes(searchInput.toLocaleLowerCase())
);

const items = filteredRecipes.map((recipe) => {
const filtered = filteredRecipes.map((recipe) => {
const img = `data:image/jpeg;base64,${recipe.picture}`;
return (
<DisplayRecipe
Expand All @@ -79,8 +80,9 @@ export default function SearchSite({ allRecipes }: { allRecipes: any[] }) {
);
});

setFilteredRecipes(items);
heading = "Suchergebnisse"
setFilteredRecipes(filtered);
setHeading("Suchergebnisse");
setRecipes("filtered");
};

const handleSearchInput = (event: ChangeEvent<HTMLInputElement>): void => {
Expand Down Expand Up @@ -126,7 +128,7 @@ export default function SearchSite({ allRecipes }: { allRecipes: any[] }) {
<div id="display_recipes_wrapper">
<AliceCarousel
mouseTracking
items={items}
items={recipes === "items" ? items : filteredRecipes}
autoPlay
autoPlayInterval={4000}
disableDotsControls
Expand Down

0 comments on commit 83b0e7f

Please sign in to comment.