This commit is contained in:
parent
f9c7d647f7
commit
8dda6b1014
@ -348,8 +348,9 @@ function App() {
|
|||||||
const hideSoups = settings?.hideSoups;
|
const hideSoups = settings?.hideSoups;
|
||||||
content = <Table striped bordered hover>
|
content = <Table striped bordered hover>
|
||||||
<tbody style={{ cursor: 'pointer' }}>
|
<tbody style={{ cursor: 'pointer' }}>
|
||||||
{menu.food.filter(f => (hideSoups ? !f.isSoup : true)).map((f: any, index: number) =>
|
{menu.food.map((f: Food, index: number) =>
|
||||||
<tr key={index} onClick={() => doAddClickFoodChoice(location, hideSoups ? index + 1 : index)}>
|
(!hideSoups || !f.isSoup) &&
|
||||||
|
<tr key={f.name} onClick={() => doAddClickFoodChoice(location, index)}>
|
||||||
<td>{f.amount}</td>
|
<td>{f.amount}</td>
|
||||||
<td>{f.name}</td>
|
<td>{f.name}</td>
|
||||||
<td>{f.price}</td>
|
<td>{f.price}</td>
|
||||||
|
@ -331,6 +331,7 @@ export async function addChoice(login: string, trusted: boolean, locationKey: Lo
|
|||||||
const selectedDate = formatDate(usedDate);
|
const selectedDate = formatDate(usedDate);
|
||||||
let data: DayData = await storage.getData(selectedDate);
|
let data: DayData = await storage.getData(selectedDate);
|
||||||
validateTrusted(data, login, trusted);
|
validateTrusted(data, login, trusted);
|
||||||
|
await validateFoodIndex(locationKey, foodIndex, date);
|
||||||
// Pokud měníme pouze lokaci, mažeme případné předchozí
|
// Pokud měníme pouze lokaci, mažeme případné předchozí
|
||||||
if (foodIndex == null) {
|
if (foodIndex == null) {
|
||||||
data = await removeChoiceIfPresent(login, selectedDate);
|
data = await removeChoiceIfPresent(login, selectedDate);
|
||||||
@ -358,6 +359,24 @@ export async function addChoice(login: string, trusted: boolean, locationKey: Lo
|
|||||||
return data;
|
return data;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Zvaliduje platnost indexu jídla pro vybranou lokalitu a datum.
|
||||||
|
*
|
||||||
|
* @param locationKey vybraná lokalita
|
||||||
|
* @param foodIndex index jídla pro danou lokalitu
|
||||||
|
* @param date datum, pro které je validace prováděna
|
||||||
|
*/
|
||||||
|
async function validateFoodIndex(locationKey: LocationKey, foodIndex?: number, date?: Date) {
|
||||||
|
if (locationKey in Restaurants && foodIndex != null) {
|
||||||
|
const usedDate = date ?? getToday();
|
||||||
|
const restaurantKey = Restaurants[locationKey as keyof typeof Restaurants]
|
||||||
|
const menu = await getRestaurantMenu(restaurantKey, usedDate);
|
||||||
|
if (foodIndex > (menu.food.length - 1)) {
|
||||||
|
throw new Error(`Neplatný index ${foodIndex} pro lokalitu ${locationKey}`);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Aktualizuje poznámku k aktuálně vybrané možnosti.
|
* Aktualizuje poznámku k aktuálně vybrané možnosti.
|
||||||
*
|
*
|
||||||
|
Loading…
x
Reference in New Issue
Block a user