This commit is contained in:
+22
-10
@@ -428,31 +428,43 @@ function App() {
|
||||
}
|
||||
|
||||
const pizzaSuggestions = useMemo(() => {
|
||||
if (!data?.pizzaList) {
|
||||
if (!data?.pizzaList && !data?.salatList) {
|
||||
return [];
|
||||
}
|
||||
const suggestions: SelectSearchOption[] = [];
|
||||
data.pizzaList.forEach((pizza, index) => {
|
||||
data.pizzaList?.forEach((pizza, index) => {
|
||||
const group: SelectSearchOption = { name: pizza.name, type: "group", items: [] }
|
||||
pizza.sizes.forEach((size, sizeIndex) => {
|
||||
const name = `${size.size} (${size.price} Kč)`;
|
||||
const value = `${index}|${sizeIndex}`;
|
||||
const value = `pizza|${index}|${sizeIndex}`;
|
||||
group.items?.push({ name, value });
|
||||
})
|
||||
suggestions.push(group);
|
||||
})
|
||||
});
|
||||
if (data.salatList?.length) {
|
||||
const salatGroup: SelectSearchOption = { name: "Saláty", type: "group", items: [] }
|
||||
data.salatList.forEach((salat, index) => {
|
||||
salatGroup.items?.push({ name: `${salat.name} (${salat.price} Kč)`, value: `salat|${index}` });
|
||||
});
|
||||
suggestions.push(salatGroup);
|
||||
}
|
||||
return suggestions;
|
||||
}, [data?.pizzaList]);
|
||||
}, [data?.pizzaList, data?.salatList]);
|
||||
|
||||
const handlePizzaChange = async (value: SelectedOptionValue | SelectedOptionValue[]) => {
|
||||
if (auth?.login && data?.pizzaList) {
|
||||
if (auth?.login) {
|
||||
if (typeof value !== 'string') {
|
||||
throw new TypeError('Nepodporovaný typ hodnoty: ' + typeof value);
|
||||
}
|
||||
const s = value.split('|');
|
||||
const pizzaIndex = Number.parseInt(s[0]);
|
||||
const pizzaSizeIndex = Number.parseInt(s[1]);
|
||||
await addPizza({ body: { pizzaIndex, pizzaSizeIndex } });
|
||||
if (s[0] === 'salat') {
|
||||
const salatIndex = Number.parseInt(s[1]);
|
||||
await addPizza({ body: { salatIndex } });
|
||||
} else {
|
||||
const pizzaIndex = Number.parseInt(s[1]);
|
||||
const pizzaSizeIndex = Number.parseInt(s[2]);
|
||||
await addPizza({ body: { pizzaIndex, pizzaSizeIndex } });
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -821,7 +833,7 @@ function App() {
|
||||
<SelectSearch
|
||||
search={true}
|
||||
options={pizzaSuggestions}
|
||||
placeholder='Vyhledat pizzu...'
|
||||
placeholder='Vyhledat pizzu nebo salát...'
|
||||
onChange={handlePizzaChange}
|
||||
onBlur={_ => { }}
|
||||
onFocus={_ => { }}
|
||||
|
||||
Reference in New Issue
Block a user