добавлены события
This commit is contained in:
@@ -13,6 +13,7 @@ import LocalBarIcon from '@mui/icons-material/LocalBar';
|
||||
import {paths} from "../../path";
|
||||
import {useAlert} from "../../hooks/useAlert";
|
||||
import {useUser} from "../../hooks/useUser";
|
||||
import {cocktailClient} from "../../lib/clients/CocktailClient";
|
||||
|
||||
function renderFavouriteBadge(handleFavourite, row) {
|
||||
const childIcon = row.rating.favourite ? <FavoriteIcon/> : <FavoriteBorderIcon/>;
|
||||
@@ -35,7 +36,7 @@ function renderRating(handleChangeRating, row) {
|
||||
}
|
||||
|
||||
export function Cocktail({row, handleFavourite, handleChangeRating, handleSelect, deleteHandler}) {
|
||||
const {notImplement} = useAlert();
|
||||
const {createError, createSuccess} = useAlert();
|
||||
const {user} = useUser();
|
||||
return (
|
||||
<Grid item sx={{pr: 2}}>
|
||||
@@ -59,7 +60,8 @@ export function Cocktail({row, handleFavourite, handleChangeRating, handleSelect
|
||||
image={row.image.includes("thecocktaildb") ? (row.image + "/preview") : row.image}
|
||||
/>
|
||||
<CardActions>
|
||||
<IconButton sx={{m: 0}} size='small' onClick={() => notImplement()}>
|
||||
<IconButton sx={{m: 0}} size='small'
|
||||
onClick={() => cocktailClient.drinkCocktail(row.id, createSuccess, createError)}>
|
||||
<LocalBarIcon fontSize='small'/>
|
||||
</IconButton>
|
||||
{renderFavouriteBadge(handleFavourite, row)}
|
||||
|
||||
@@ -196,6 +196,12 @@ class CocktailClient {
|
||||
}).catch(() => createError("Ошибка сохранения"))
|
||||
}
|
||||
|
||||
drinkCocktail(id, createSuccess, createError) {
|
||||
api().post(`${requests.cocktails.drink}/${id}`)
|
||||
.then(() => createSuccess("Бон аппетит"))
|
||||
.catch(() => createError("Ошибка отметки коктейля"))
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
export const cocktailClient = new CocktailClient();
|
||||
@@ -37,6 +37,7 @@ export const requests = {
|
||||
modal: routes.cocktail + "/modal?id=",
|
||||
favourite: routes.cocktail + "/favourite?id=",
|
||||
rating: routes.cocktail + "/rating?id=",
|
||||
drink: routes.cocktail + "/drink",
|
||||
},
|
||||
glass: {
|
||||
list: routes.glass,
|
||||
|
||||
Reference in New Issue
Block a user