Доработка фронта

This commit is contained in:
Kayashov.SM
2025-04-21 16:22:36 +04:00
parent 704875d297
commit 23316b79f0
13 changed files with 211 additions and 85 deletions

View File

@@ -0,0 +1,61 @@
import * as React from "react";
export const SelectContext = React.createContext(undefined);
export function SelectProvider({children}) {
const [selected, setSelected] = React.useState({
cocktail: null,
ingredient: null
});
const selectCocktail = (row) => {
setSelected((prev) => ({
...prev,
cocktail: row
}))
}
const getCocktail = () => {
return selected.cocktail
}
const getOpenCocktail = () => {
return selected.cocktail !== null;
}
const closeCocktail = () => {
setSelected((prevState) => ({
...prevState,
cocktail: null,
}))
}
const selectIngredient = (row) => {
setSelected((prev) => ({
...prev,
ingredient: row
}))
}
const closeIngredient = () => {
setSelected((prevState) => ({
...prevState,
ingredient: null
}))
}
const getIngredient = () => {
return selected.ingredient
}
const getOpenIngredient = () => {
return selected.ingredient !== null
}
return <SelectContext.Provider value={{...selected,
selectCocktail,
getCocktail,
getOpenCocktail,
closeCocktail,
selectIngredient,
closeIngredient,
getIngredient,
getOpenIngredient
}}>{children}</SelectContext.Provider>;
}
export const SelectConsumer = SelectContext.Consumer;