diff --git a/client/src/App.tsx b/client/src/App.tsx index 3372732..408a6ac 100644 --- a/client/src/App.tsx +++ b/client/src/App.tsx @@ -44,6 +44,7 @@ function App() { const [food, setFood] = useState<{ [key in Restaurants]: Menu }>(); const [myOrder, setMyOrder] = useState(); const [foodChoiceList, setFoodChoiceList] = useState(); + const [closed, setClosed] = useState(false); const socket = useContext(SocketContext); const choiceRef = useRef(null); const foodChoiceRef = useRef(null); @@ -111,22 +112,26 @@ function App() { useEffect(() => { if (choiceRef?.current?.value && choiceRef.current.value !== "") { // TODO: wtf, cos pil, když jsi tohle psal? - const locationIndex = Object.values(Locations).indexOf(choiceRef?.current?.value as unknown as Locations); + const key = choiceRef?.current?.value; + const locationIndex = Object.keys(Locations).indexOf(key as unknown as Locations); const locationsKey = Object.keys(Locations)[locationIndex]; const restaurantKey = Object.keys(Restaurants).indexOf(locationsKey); if (restaurantKey > -1 && food) { const restaurant = Object.values(Restaurants)[restaurantKey]; setFoodChoiceList(food[restaurant].food); + setClosed(food[restaurant].closed); } else { setFoodChoiceList(undefined); + setClosed(false); } } else { setFoodChoiceList(undefined); + setClosed(false); } }, [choiceRef.current?.value, food]) const doAddChoice = async (event: React.ChangeEvent) => { - const index = Object.values(Locations).indexOf(event.target.value as unknown as Locations); + const index = Object.keys(Locations).indexOf(event.target.value as unknown as Locations); if (auth?.login) { await addChoice(index); if (foodChoiceRef.current?.value) { @@ -137,8 +142,9 @@ function App() { const doAddFoodChoice = async (event: React.ChangeEvent) => { if (event.target.value && foodChoiceList?.length && choiceRef.current?.value) { + const restaurantKey = choiceRef.current.value; if (auth?.login) { - const locationIndex = Object.values(Locations).indexOf(choiceRef.current.value as unknown as Locations); + const locationIndex = Object.keys(Locations).indexOf(restaurantKey as unknown as Locations); await addChoice(locationIndex, Number(event.target.value)); } } @@ -243,20 +249,28 @@ function App() { } const renderFoodTable = (name: string, menu: Menu) => { - return -

{name}

- {menu?.lastUpdate && Poslední aktualizace: {menu.lastUpdate}} - + let content; + if (menu?.closed) { + content =

Zavřeno

+ } else if (menu?.food?.length > 0) { + content =
- {menu?.food?.length > 0 ? menu.food.map((f: any, index: number) => + {menu.food.map((f: any, index: number) => - ) :

Hmmmmm podivné.... nic se nevrátilo

} + )}
{f.amount} {f.name} {f.price}
+ } else { + content =

Chyba načtení dat

+ } + return +

{name}

+ {menu?.lastUpdate && Poslední aktualizace: {menu.lastUpdate}} + {content} } @@ -285,6 +299,7 @@ function App() {
  • Zobrazení jména uživatele místo loginu při přihlášení přes Authelia
  • Funkční odhlášení přes Authelia
  • Oprava stahování pizz z Pizza Chefie
  • +
  • Pokročilá AI dektece zavřených podniků
  • Dnes je {data.date}

    @@ -298,23 +313,27 @@ function App() {

    Jak to dnes vidíš s obědem?

    - - - - - - - + {Object.entries(Locations) + .filter(entry => { + // TODO: wtf, cos pil, když jsi tohle psal? v2 + const key = entry[0]; + const locationIndex = Object.keys(Locations).indexOf(key as unknown as Locations); + const locationsKey = Object.keys(Locations)[locationIndex]; + const restaurantKey = Object.keys(Restaurants).indexOf(locationsKey); + const v = Object.values(Restaurants)[restaurantKey]; + return v == null || !food[v].closed; + }) + .map(entry => )} Je možné vybrat jen jednu možnost. Výběr jiné odstraní předchozí. - {foodChoiceList && <> + {foodChoiceList && !closed && <>

    Na co dobrého? (nepovinné)

    {foodChoiceList.map((food, index) => )} } - {foodChoiceList && <> + {foodChoiceList && !closed && <>

    V kolik hodin preferuješ odchod?

    diff --git a/server/src/service.ts b/server/src/service.ts index 1d0e15b..3af00dc 100644 --- a/server/src/service.ts +++ b/server/src/service.ts @@ -75,6 +75,7 @@ export async function getRestaurantMenu(restaurant: Restaurants, date?: Date, mo if (!clientData?.menus?.[restaurant]) { clientData.menus[restaurant] = { lastUpdate: getHumanTime(new Date()), + closed: false, food: [], }; switch (restaurant) { @@ -82,7 +83,11 @@ export async function getRestaurantMenu(restaurant: Restaurants, date?: Date, mo clientData.menus[restaurant].food = await getMenuSladovnicka(date, mock); break; case Restaurants.UMOTLIKU: - clientData.menus[restaurant].food = await getMenuUMotliku(date, mock); + const uMotlikuFood = await getMenuUMotliku(date, mock); + clientData.menus[restaurant].food = uMotlikuFood; + if (uMotlikuFood.length === 1 && uMotlikuFood[0].name.toLowerCase() === 'zavřeno') { + clientData.menus[restaurant].closed = true; + } break; case Restaurants.TECHTOWER: clientData.menus[restaurant].food = await getMenuTechTower(date, mock); diff --git a/types/Types.ts b/types/Types.ts index fe2cb87..91480ed 100644 --- a/types/Types.ts +++ b/types/Types.ts @@ -80,6 +80,7 @@ export interface ClientData { /** Nabídka jídel jednoho podniku. */ export interface Menu { lastUpdate: string, // human-readable čas poslední aktualizace menu + closed: boolean, // příznak, zda je daný podnik aktuálně zavřený food: Food[], // seznam jídel v menu }