From e9696f722cbbbaf191bf6052b7ee7a6fbe432202 Mon Sep 17 00:00:00 2001 From: Martin Berka Date: Mon, 9 Mar 2026 10:16:14 +0100 Subject: [PATCH] =?UTF-8?q?feat:=20automatick=C3=BD=20v=C3=BDb=C4=9Br=20v?= =?UTF-8?q?=C3=BDchoz=C3=ADho=20=C4=8Dasu?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- client/src/App.tsx | 18 +++++++++++++++++- server/changelogs/2026-03-09.json | 3 +++ 2 files changed, 20 insertions(+), 1 deletion(-) create mode 100644 server/changelogs/2026-03-09.json diff --git a/client/src/App.tsx b/client/src/App.tsx index 086e72c..d642daa 100644 --- a/client/src/App.tsx +++ b/client/src/App.tsx @@ -287,6 +287,7 @@ function App() { try { await addChoice({ body: { locationKey: location, foodIndex, dayIndex } }); + await tryAutoSelectDepartureTime(); } catch (error: any) { alert(`Chyba při změně volby: ${error.message || error}`); } @@ -313,6 +314,10 @@ function App() { foodChoiceRef.current.value = ""; } choiceRef.current?.blur(); + // Automatický výběr času odchodu pouze pro restaurace s menu + if (Object.keys(Restaurant).includes(locationKey)) { + await tryAutoSelectDepartureTime(); + } } catch (error: any) { alert(`Chyba při změně volby: ${error.message || error}`); // Reset výběru zpět @@ -337,6 +342,7 @@ function App() { const locationKey = choiceRef.current.value as LunchChoice; if (auth?.login) { await addChoice({ body: { locationKey, foodIndex: Number(event.target.value), dayIndex } }); + await tryAutoSelectDepartureTime(); } } } @@ -468,6 +474,16 @@ function App() { } } + // Automaticky nastaví preferovaný čas odchodu 10:45, pokud tento čas ještě nenastal (nebo jde o budoucí den) + const tryAutoSelectDepartureTime = async () => { + const preferredTime = "10:45" as DepartureTime; + const isToday = dayIndex === data?.todayDayIndex; + if ((!isToday || isInTheFuture(preferredTime)) && departureChoiceRef.current) { + departureChoiceRef.current.value = preferredTime; + await changeDepartureTime({ body: { time: preferredTime, dayIndex } }); + } + } + const handleDayChange = async (dayIndex: number) => { setDayIndex(dayIndex); dayIndexRef.current = dayIndex; @@ -629,7 +645,7 @@ function App() { {Object.values(DepartureTime) - .filter(time => isInTheFuture(time)) + .filter(time => dayIndex !== data.todayDayIndex || isInTheFuture(time)) .map(time => )} } diff --git a/server/changelogs/2026-03-09.json b/server/changelogs/2026-03-09.json new file mode 100644 index 0000000..216ac8d --- /dev/null +++ b/server/changelogs/2026-03-09.json @@ -0,0 +1,3 @@ +[ + "Automatický výběr výchozího času preferovaného odchodu" +] \ No newline at end of file