From 1e280e9d05a627bad11fd536aef4daee9801f76c Mon Sep 17 00:00:00 2001 From: Martin Berka Date: Mon, 4 Mar 2024 23:35:58 +0100 Subject: [PATCH] =?UTF-8?q?Mo=C5=BEnost=20zad=C3=A1n=C3=AD=20obecn=C3=A9?= =?UTF-8?q?=20pozn=C3=A1mky=20k=20volb=C4=9B?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- client/src/App.tsx | 43 +++++++++++++++------- client/src/api/FoodApi.ts | 4 ++ client/src/components/modals/NoteModal.tsx | 35 ++++++++++++++++++ server/src/routes/foodRoutes.ts | 26 ++++++++++++- server/src/routes/pizzaDayRoutes.ts | 4 +- server/src/service.ts | 26 +++++++++++++ types/Types.ts | 1 + 7 files changed, 122 insertions(+), 17 deletions(-) create mode 100644 client/src/components/modals/NoteModal.tsx diff --git a/client/src/App.tsx b/client/src/App.tsx index 401bb8a..523ca55 100644 --- a/client/src/App.tsx +++ b/client/src/App.tsx @@ -12,15 +12,16 @@ import SelectSearch, { SelectedOptionValue } from 'react-select-search'; import 'react-select-search/style.css'; import './App.css'; import { SelectSearchOption } from 'react-select-search'; -import { faCircleCheck, faTrashCan } from '@fortawesome/free-regular-svg-icons'; +import { faCircleCheck, faNoteSticky, faTrashCan } from '@fortawesome/free-regular-svg-icons'; import { useSettings } from './context/settings'; import { ClientData, Restaurants, Food, Order, Locations, PizzaOrder, PizzaDayState, FoodChoices, DayMenu, DepartureTime } from './types'; import Footer from './components/Footer'; import { faChainBroken, faChevronLeft, faChevronRight, faGear, faSatelliteDish, faSearch } from '@fortawesome/free-solid-svg-icons'; import Loader from './components/Loader'; import { getData, errorHandler, getQrUrl } from './api/Api'; -import { addChoice, removeChoices, removeChoice, changeDepartureTime, jdemeObed } from './api/FoodApi'; +import { addChoice, removeChoices, removeChoice, changeDepartureTime, jdemeObed, updateNote } from './api/FoodApi'; import { getHumanDateTime } from './Utils'; +import NoteModal from './components/modals/NoteModal'; const EVENT_CONNECT = "connect" @@ -37,10 +38,11 @@ function App() { const choiceRef = useRef(null); const foodChoiceRef = useRef(null); const departureChoiceRef = useRef(null); - const poznamkaRef = useRef(null); + const pizzaPoznamkaRef = useRef(null); const [failure, setFailure] = useState(false); const [dayIndex, setDayIndex] = useState(); const [loadingPizzaDay, setLoadingPizzaDay] = useState(false); + const [noteModalOpen, setNoteModalOpen] = useState(false); // Prazvláštní workaround, aby socket.io listener viděl aktuální hodnotu // https://medium.com/@kishorkrishna/cant-access-latest-state-inside-socket-io-listener-heres-how-to-fix-it-1522a5abebdb const dayIndexRef = useRef(dayIndex); @@ -210,6 +212,17 @@ function App() { } } + const saveNote = async (note?: string) => { + if (auth?.login) { + if (note != null && note.length > 70) { + alert("Poznámka může mít maximálně 70 znaků"); + return; + } + await errorHandler(() => updateNote(note, dayIndex)); + setNoteModalOpen(false); + } + } + const pizzaSuggestions = useMemo(() => { if (!data?.pizzaList) { return []; @@ -243,12 +256,12 @@ function App() { await removePizza(pizzaOrder); } - const handlePoznamkaChange = async () => { - if (poznamkaRef.current?.value && poznamkaRef.current.value.length > 100) { - alert("Poznámka může mít maximálně 100 znaků"); + const handlePizzaPoznamkaChange = async () => { + if (pizzaPoznamkaRef.current?.value && pizzaPoznamkaRef.current.value.length > 70) { + alert("Poznámka může mít maximálně 70 znaků"); return; } - updatePizzaDayNote(poznamkaRef.current?.value); + updatePizzaDayNote(pizzaPoznamkaRef.current?.value); } // const addToCart = async () => { @@ -360,10 +373,7 @@ function App() { Poslední změny:
    -
  • Možnost skrytí polévek
  • -
  • Možnost "Rozhoduji se"
  • -
  • Neuskakování data vlevo při přechodu na pondělí
  • -
  • Mělo tu toho být už mnohem víc, ale zasekl jsem se snahou nahradit pizza search box
  • +
  • Anděloviny
{dayIndex != null && @@ -436,6 +446,10 @@ function App() { } {login} {userPayload.departureTime && ({userPayload.departureTime})} + {userPayload.note && ({userPayload.note})} + {login === auth.login && canChangeChoice && { + setNoteModalOpen(true); + }} title='Upravit poznámku' className='action-icon' icon={faNoteSticky} />} {login === auth.login && canChangeChoice && { doRemoveChoices(locationKey); }} title={`Odstranit volbu ${locationName}, včetně případných zvolených jídel`} className='action-icon' icon={faTrashCan} />} @@ -564,15 +578,15 @@ function App() { placeholder='Vyhledat pizzu...' onChange={handlePizzaChange} /> - Poznámka: { + Poznámka: { if (event.key === 'Enter') { - handlePoznamkaChange(); + handlePizzaPoznamkaChange(); } }} /> @@ -593,6 +607,7 @@ function App() { }