From d6cf2296232682e5847d48cdc84f415e68326dad Mon Sep 17 00:00:00 2001 From: Lucas Hicks Date: Wed, 25 Oct 2023 14:56:42 +1000 Subject: [PATCH 1/2] Inverts figurines endpoint. --- db-handler/app/constants.py | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/db-handler/app/constants.py b/db-handler/app/constants.py index 425334b..be15b6f 100644 --- a/db-handler/app/constants.py +++ b/db-handler/app/constants.py @@ -25,5 +25,5 @@ LOGGER_TIME_FORMAT = '%I:%M:%S %p' # Values for microcontroller and servos/actuators -FREE = 0 # 0 is sent to the microcontroller if user is not busy -BUSY = 1 # 1 is sent to the microcontroller if user is busy +FREE = 1 # 1 is sent to the microcontroller if user is not busy +BUSY = 0 # 0 is sent to the microcontroller if user is busy From bebf8c9a8cf3fc92eaf11a205d767dd259618a50 Mon Sep 17 00:00:00 2001 From: alilaherty Date: Wed, 25 Oct 2023 15:20:40 +1000 Subject: [PATCH 2/2] upcoming event --- .../components/widgets/SuggestedTimeWidget.js | 41 +++++++++++++++++-- .../src/components/widgets/Widgets.css | 19 +++++++++ 2 files changed, 57 insertions(+), 3 deletions(-) diff --git a/ui-display/frontend-app/src/components/widgets/SuggestedTimeWidget.js b/ui-display/frontend-app/src/components/widgets/SuggestedTimeWidget.js index d42e0cb..9e4c5b1 100644 --- a/ui-display/frontend-app/src/components/widgets/SuggestedTimeWidget.js +++ b/ui-display/frontend-app/src/components/widgets/SuggestedTimeWidget.js @@ -35,7 +35,7 @@ export default function SuggestedTimeWidget() { } const [suggestedTime, setSuggestedTime] = useState(""); - const [timeDelta, setTimeDelta] = useState(0); + const [upcomingEvent, setUpcomingEvent] = useState(null); const [loading, setLoading] = useState(true); const baseURL = 'https://localhost:8000/display/'; @@ -43,8 +43,8 @@ export default function SuggestedTimeWidget() { useEffect(() => { const interval = setInterval(()=>{ fetchData(); - //fetchTime(); - },50000); + fetchEvents(); + },5000); /* DEFAULT BEHAVIOUR: GET SINGLE RECOMMENDATION OF NEXT NEAREST TIME */ const fetchData = async () => { console.log('data fetched'); @@ -108,6 +108,33 @@ export default function SuggestedTimeWidget() { } }; + const fetchEvents = async () => { + const response = await fetch("http://localhost:8000/display/family-timeslots"); + const data = await response.json(); + if (data && data.body) { + const timeSlotsAllWeek = Array.from(data.body); + console.log("events:", timeSlotsAllWeek); + // filter out any days already passed + // TODO what do we do when the week is nearly over? + const trueNow = new Date(); + const dayName = Constants.DAYS[addSeconds(trueNow, Constants.TIME_DELTA).getDay()]; + + const timeSlots = timeSlotsAllWeek.filter(timeSlot => + (Constants.DAY_POSITIONS[timeSlot.day] > Constants.DAY_POSITIONS[dayName]) + || (Constants.DAY_POSITIONS[timeSlot.day] === Constants.DAY_POSITIONS[dayName] + && timeSlot.slot_num > currentToTimeSlotNum())); + console.log("events filtered", timeSlots); + + if (timeSlots && timeSlots.length > 0) { + console.log("upcoming", timeSlots[0]); + setUpcomingEvent(timeSlots[0]); + } else { + console.log("no upcoming events"); + setUpcomingEvent(null); + } + + } + }; return () => clearInterval(interval); //fetchData(); @@ -122,6 +149,14 @@ export default function SuggestedTimeWidget() { <>

Suggested Time 🪩

Everybody is next free {suggestedTime}.

+ {upcomingEvent ? +

And good news! 🥳 You've got + {(upcomingEvent.data && upcomingEvent.data.length > 1) ? ` ${upcomingEvent.data} ` : " something "} + coming up {dayAndTimeToDate(upcomingEvent['day'], upcomingEvent['time'])} 💗 +

+ : +

Maybe pencil something in!

+ } } diff --git a/ui-display/frontend-app/src/components/widgets/Widgets.css b/ui-display/frontend-app/src/components/widgets/Widgets.css index 929b41c..cfdabf6 100644 --- a/ui-display/frontend-app/src/components/widgets/Widgets.css +++ b/ui-display/frontend-app/src/components/widgets/Widgets.css @@ -34,6 +34,25 @@ color: var(--darkgrey); } +.SuggestedTime-box h3, p { + padding: 0; + margin: 0; +} +.SuggestedTime-box h3 { + padding-bottom: 0.1em; + font-size: 1em; +} + +.SuggestedTime-box h1 { + margin-top: 0.2em; + font-size: 1.75em; +} + +.SuggestedTime-box p { + font-size: 0.75em; + margin-bottom: 0.5em; +} + .Weather-box { font-family: Nightingale; font-size: 30px;