Keresés
This commit is contained in:
1 parent
bdac48678b
commit
65dafdd4c0
2 files changed
+24
-3
No files matched your search
@@ -6,7 +6,7 @@ function Cocktail({cocktail}) {
|
||||
<div class="bg-white rounded-xl shadow-md overflow-hidden border border-orange-100 transform hover:scale-105 transition-transform duration-300">
|
||||
{/*<!-- Kép helye -->*/}
|
||||
<div class="h-48 bg-orange-200 flex items-center justify-center relative">
|
||||
<img src={cocktail.strImageSource} alt="" class="w-full h-full object-cover absolute inset-0" id="cocktail-image"/>
|
||||
<img src={cocktail.strDrinkThumb} alt="" class="w-full h-full object-cover absolute inset-0" id="cocktail-image"/>
|
||||
<div class="absolute inset-0 bg-black opacity-20"></div>
|
||||
<span class="relative z-10 text-white font-bold text-lg px-3 py-1 bg-orange-600 rounded-full">
|
||||
Koktél
|
||||
|
||||
@@ -1,5 +1,5 @@
|
||||
import { useState } from "react";
|
||||
|
||||
import Cocktail from "./Cocktail";
|
||||
|
||||
|
||||
function SearchName() {
|
||||
@@ -7,6 +7,13 @@ function SearchName() {
|
||||
const [cocktails,setCocktails]=useState([]);
|
||||
const [cocktailName,setCocktailName]=useState("");
|
||||
|
||||
const getCocktails=(cocktail)=>{
|
||||
fetch(`https://www.thecocktaildb.com/api/json/v1/1/search.php?s=${cocktail}`)
|
||||
.then(res=>res.json())
|
||||
.then(adat=>setCocktails(adat.drinks))
|
||||
.catch(err=>alert(err));
|
||||
}
|
||||
|
||||
return (
|
||||
<main class="max-w-5xl mx-auto px-4 sm:px-6 lg:px-8 py-12">
|
||||
{/* komment*/}
|
||||
@@ -29,7 +36,7 @@ function SearchName() {
|
||||
id="cocktail-name-input"/>
|
||||
</div>
|
||||
<div class="flex space-x-4">
|
||||
<button type="submit" class="flex-1 bg-orange-500 hover:bg-orange-600 text-white font-bold py-3 px-4 rounded-lg transition-colors duration-300 shadow-md">
|
||||
<button type="button" onClick={()=>getCocktails(cocktailName)} class="flex-1 bg-orange-500 hover:bg-orange-600 text-white font-bold py-3 px-4 rounded-lg transition-colors duration-300 shadow-md">
|
||||
Keresés
|
||||
</button>
|
||||
<button type="button" class="flex-1 bg-white border border-orange-300 hover:bg-orange-50 text-orange-700 font-bold py-3 px-4 rounded-lg transition-colors duration-300">
|
||||
@@ -45,6 +52,20 @@ function SearchName() {
|
||||
<p class="col-span-full text-center text-gray-500 py-12 text-lg">
|
||||
Írj be egy koktél nevet a keresőbe, hogy megjelenjen az eredmény!
|
||||
</p>
|
||||
{
|
||||
(cocktails && cocktails.length>0) ?
|
||||
<>
|
||||
{
|
||||
cocktails.map((cocktail)=>(<Cocktail key={cocktail.idDrink} cocktail={cocktail} />))
|
||||
}
|
||||
</>
|
||||
:
|
||||
<>
|
||||
<p class="col-span-full text-center text-gray-500 py-12 text-lg">
|
||||
Nincs ilyen koktél!
|
||||
</p>
|
||||
</>
|
||||
}
|
||||
</div>
|
||||
|
||||
|
||||
|
||||
Reference in new issue
Block a user