From 393a224cea231f342c003aa08a973d8bc7b6b1d4 Mon Sep 17 00:00:00 2001 From: Jay Nagpaul Date: Fri, 15 Nov 2024 14:40:45 -0500 Subject: [PATCH 1/2] Fix modal queue --- ...dalQueueManager.tsx => DashboardModal.tsx} | 62 +-- mobile/package.json | 10 +- mobile/screens/User/UserDashboardScreen.tsx | 10 +- mobile/yarn.lock | 399 ++++++++++++------ package-lock.json | 347 --------------- 5 files changed, 284 insertions(+), 544 deletions(-) rename mobile/components/{ModalQueueManager.tsx => DashboardModal.tsx} (50%) delete mode 100644 package-lock.json diff --git a/mobile/components/ModalQueueManager.tsx b/mobile/components/DashboardModal.tsx similarity index 50% rename from mobile/components/ModalQueueManager.tsx rename to mobile/components/DashboardModal.tsx index df32c1ae..8f96872e 100644 --- a/mobile/components/ModalQueueManager.tsx +++ b/mobile/components/DashboardModal.tsx @@ -1,4 +1,4 @@ -import React, { useState, useEffect, useRef } from "react"; +import React from "react"; import { View, Modal, @@ -10,58 +10,24 @@ import { import { MaterialIcons } from "@expo/vector-icons"; import { ModalContent } from "../utils/types"; -const ModalQueueManager = ({ - modals, - onComplete, +const DashboardModal = ({ + content, + onClose, }: { - modals: ModalContent[]; - onComplete: () => void; + content: ModalContent | null; + onClose: () => void; }) => { - const [currentModal, setCurrentModal] = useState(null); - const [queue, setQueue] = useState([]); - const seenTypes = useRef>(new Set()); - - // Process new modals - useEffect(() => { - if (modals.length > 0) { - // Filter out modals that have already been seen based on type - const newModals = modals.filter((modal) => { - if (!seenTypes.current.has(modal.type)) { - seenTypes.current.add(modal.type); // Mark as seen immediately - return true; - } - return false; - }); - - if (newModals.length > 0) { - setQueue((prev) => [...prev, ...newModals]); - } - } - }, [modals]); - - // Show next modal - useEffect(() => { - if (queue.length > 0 && !currentModal) { - const nextModal = queue[0]; - setCurrentModal(nextModal); - setQueue((prev) => prev.slice(1)); - } - }, [queue, currentModal]); - const handleCloseModal = () => { - setCurrentModal(null); - if (queue.length === 0) { - onComplete?.(); - } + onClose(); }; - if (!currentModal) return null; + if (!content) return null; return ( Vibration.vibrate(10000)} > @@ -72,11 +38,9 @@ const ModalQueueManager = ({ > - {currentModal.content} - {currentModal.additionalContent && ( - - {currentModal.additionalContent} - + {content.content} + {content.additionalContent && ( + {content.additionalContent} )} @@ -127,4 +91,4 @@ const styles = StyleSheet.create({ }, }); -export default ModalQueueManager; +export default DashboardModal; diff --git a/mobile/package.json b/mobile/package.json index 8c35e34d..6d8aa353 100644 --- a/mobile/package.json +++ b/mobile/package.json @@ -22,23 +22,23 @@ "babel-preset-expo": "~12.0.0", "crypto-browserify": "^3.12.0", "dayjs": "^1.11.13", - "expo": "^52.0.5", + "expo": "^52.0.7", "expo-av": "~15.0.1", - "expo-constants": "~17.0.2", + "expo-constants": "~17.0.3", "expo-doctor": "^1.10.1", "expo-file-system": "~18.0.3", "expo-haptics": "~14.0.0", - "expo-image-picker": "~16.0.1", + "expo-image-picker": "~16.0.2", "expo-linking": "~7.0.2", "expo-media-library": "~17.0.2", - "expo-splash-screen": "~0.29.8", + "expo-splash-screen": "~0.29.10", "expo-status-bar": "~2.0.0", "expo-video-thumbnails": "~9.0.2", "firebase": "^9.9.4", "mongoose": "^6.5.2", "react": "18.3.1", "react-dom": "18.3.1", - "react-native": "0.76.1", + "react-native": "0.76.2", "react-native-config": "^1.5.3", "react-native-dropdown-picker": "^5.4.2", "react-native-fiesta": "^0.7.0", diff --git a/mobile/screens/User/UserDashboardScreen.tsx b/mobile/screens/User/UserDashboardScreen.tsx index 3627795c..5acbc5fb 100644 --- a/mobile/screens/User/UserDashboardScreen.tsx +++ b/mobile/screens/User/UserDashboardScreen.tsx @@ -38,7 +38,7 @@ import { endOfExecutionHandler, ErrorWrapper } from "../../utils/error"; import ErrorBox from "../../components/ErrorBox"; import shadowStyle from "../../utils/styles"; import { userSendEmail } from "../../actions/Email"; -import ModalQueueManager from "../../components/ModalQueueManager"; +import DashboardModal from "../../components/DashboardModal"; export default function UserDashboardScreen(props: any) { const [hoursCompleted, setHoursCompleted] = useState(0); @@ -325,9 +325,11 @@ export default function UserDashboardScreen(props: any) { {new Date().getDate() === 1 ? : null} {new Date().getMonth() === 1 ? : null} - setModalQueue([])} + { + setModalQueue((prev) => prev.slice(1)); + }} /> =6.9.0" - } - }, - "node_modules/ansi-regex": { - "version": "5.0.1", - "resolved": "https://registry.npmjs.org/ansi-regex/-/ansi-regex-5.0.1.tgz", - "integrity": "sha512-quJQXlTSUGL2LH9SUXo8VwsY4soanhgo6LNSm84E1LBcE8s3O0wpdiRzyR9z/ZZJMlMWv37qOOb9pdJlMUEKFQ==", - "license": "MIT", - "engines": { - "node": ">=8" - } - }, - "node_modules/ansi-styles": { - "version": "4.3.0", - "resolved": "https://registry.npmjs.org/ansi-styles/-/ansi-styles-4.3.0.tgz", - "integrity": "sha512-zbB9rCJAT1rbjiVDb2hqKFHNYLxgtk8NURxZ3IZwD3F6NtxbXZQCnnSi1Lkx+IDohdPlFp222wVALIheZJQSEg==", - "license": "MIT", - "dependencies": { - "color-convert": "^2.0.1" - }, - "engines": { - "node": ">=8" - }, - "funding": { - "url": "https://github.com/chalk/ansi-styles?sponsor=1" - } - }, - "node_modules/chalk": { - "version": "4.1.2", - "resolved": "https://registry.npmjs.org/chalk/-/chalk-4.1.2.tgz", - "integrity": "sha512-oKnbhFyRIXpUuez8iBMmyEa4nbj4IOQyuhc/wy9kY7/WVPcwIO9VA668Pu8RkO7+0G76SLROeyw9CpQ061i4mA==", - "license": "MIT", - "dependencies": { - "ansi-styles": "^4.1.0", - "supports-color": "^7.1.0" - }, - "engines": { - "node": ">=10" - }, - "funding": { - "url": "https://github.com/chalk/chalk?sponsor=1" - } - }, - "node_modules/chalk/node_modules/supports-color": { - "version": "7.2.0", - "resolved": "https://registry.npmjs.org/supports-color/-/supports-color-7.2.0.tgz", - "integrity": "sha512-qpCAvRl9stuOHveKsn7HncJRvv501qIacKzQlO/+Lwxc9+0q2wLyv4Dfvt80/DPn2pqOBsJdDiogXGR9+OvwRw==", - "license": "MIT", - "dependencies": { - "has-flag": "^4.0.0" - }, - "engines": { - "node": ">=8" - } - }, - "node_modules/cliui": { - "version": "8.0.1", - "resolved": "https://registry.npmjs.org/cliui/-/cliui-8.0.1.tgz", - "integrity": "sha512-BSeNnyus75C4//NQ9gQt1/csTXyo/8Sb+afLAkzAptFuMsod9HFokGNudZpi/oQV73hnVK+sR+5PVRMd+Dr7YQ==", - "license": "ISC", - "dependencies": { - "string-width": "^4.2.0", - "strip-ansi": "^6.0.1", - "wrap-ansi": "^7.0.0" - }, - "engines": { - "node": ">=12" - } - }, - "node_modules/color-convert": { - "version": "2.0.1", - "resolved": "https://registry.npmjs.org/color-convert/-/color-convert-2.0.1.tgz", - "integrity": "sha512-RRECPsj7iu/xb5oKYcsFHSppFNnsj/52OVTRKb4zP5onXwVF3zVmmToNcOfGC+CRDpfK/U584fMg38ZHCaElKQ==", - "license": "MIT", - "dependencies": { - "color-name": "~1.1.4" - }, - "engines": { - "node": ">=7.0.0" - } - }, - "node_modules/color-name": { - "version": "1.1.4", - "resolved": "https://registry.npmjs.org/color-name/-/color-name-1.1.4.tgz", - "integrity": "sha512-dOy+3AuW3a2wNbZHIuMZpTcgjGuLU/uBL/ubcZF9OXbDo8ff4O8yVp5Bf0efS8uEoYo5q4Fx7dY9OgQGXgAsQA==", - "license": "MIT" - }, - "node_modules/concurrently": { - "version": "7.6.0", - "resolved": "https://registry.npmjs.org/concurrently/-/concurrently-7.6.0.tgz", - "integrity": "sha512-BKtRgvcJGeZ4XttiDiNcFiRlxoAeZOseqUvyYRUp/Vtd+9p1ULmeoSqGsDA+2ivdeDFpqrJvGvmI+StKfKl5hw==", - "license": "MIT", - "dependencies": { - "chalk": "^4.1.0", - "date-fns": "^2.29.1", - "lodash": "^4.17.21", - "rxjs": "^7.0.0", - "shell-quote": "^1.7.3", - "spawn-command": "^0.0.2-1", - "supports-color": "^8.1.0", - "tree-kill": "^1.2.2", - "yargs": "^17.3.1" - }, - "bin": { - "conc": "dist/bin/concurrently.js", - "concurrently": "dist/bin/concurrently.js" - }, - "engines": { - "node": "^12.20.0 || ^14.13.0 || >=16.0.0" - }, - "funding": { - "url": "https://github.com/open-cli-tools/concurrently?sponsor=1" - } - }, - "node_modules/date-fns": { - "version": "2.30.0", - "resolved": "https://registry.npmjs.org/date-fns/-/date-fns-2.30.0.tgz", - "integrity": "sha512-fnULvOpxnC5/Vg3NCiWelDsLiUc9bRwAPs/+LfTLNvetFCtCTN+yQz15C/fs4AwX1R9K5GLtLfn8QW+dWisaAw==", - "license": "MIT", - "dependencies": { - "@babel/runtime": "^7.21.0" - }, - "engines": { - "node": ">=0.11" - }, - "funding": { - "type": "opencollective", - "url": "https://opencollective.com/date-fns" - } - }, - "node_modules/emoji-regex": { - "version": "8.0.0", - "resolved": "https://registry.npmjs.org/emoji-regex/-/emoji-regex-8.0.0.tgz", - "integrity": "sha512-MSjYzcWNOA0ewAHpz0MxpYFvwg6yjy1NG3xteoqz644VCo/RPgnr1/GGt+ic3iJTzQ8Eu3TdM14SawnVUmGE6A==", - "license": "MIT" - }, - "node_modules/escalade": { - "version": "3.2.0", - "resolved": "https://registry.npmjs.org/escalade/-/escalade-3.2.0.tgz", - "integrity": "sha512-WUj2qlxaQtO4g6Pq5c29GTcWGDyd8itL8zTlipgECz3JesAiiOKotd8JU6otB3PACgG6xkJUyVhboMS+bje/jA==", - "license": "MIT", - "engines": { - "node": ">=6" - } - }, - "node_modules/get-caller-file": { - "version": "2.0.5", - "resolved": "https://registry.npmjs.org/get-caller-file/-/get-caller-file-2.0.5.tgz", - "integrity": "sha512-DyFP3BM/3YHTQOCUL/w0OZHR0lpKeGrxotcHWcqNEdnltqFwXVfhEBQ94eIo34AfQpo0rGki4cyIiftY06h2Fg==", - "license": "ISC", - "engines": { - "node": "6.* || 8.* || >= 10.*" - } - }, - "node_modules/has-flag": { - "version": "4.0.0", - "resolved": "https://registry.npmjs.org/has-flag/-/has-flag-4.0.0.tgz", - "integrity": "sha512-EykJT/Q1KjTWctppgIAgfSO0tKVuZUjhgMr17kqTumMl6Afv3EISleU7qZUzoXDFTAHTDC4NOoG/ZxU3EvlMPQ==", - "license": "MIT", - "engines": { - "node": ">=8" - } - }, - "node_modules/is-fullwidth-code-point": { - "version": "3.0.0", - "resolved": "https://registry.npmjs.org/is-fullwidth-code-point/-/is-fullwidth-code-point-3.0.0.tgz", - "integrity": "sha512-zymm5+u+sCsSWyD9qNaejV3DFvhCKclKdizYaJUuHA83RLjb7nSuGnddCHGv0hk+KY7BMAlsWeK4Ueg6EV6XQg==", - "license": "MIT", - "engines": { - "node": ">=8" - } - }, - "node_modules/lodash": { - "version": "4.17.21", - "resolved": "https://registry.npmjs.org/lodash/-/lodash-4.17.21.tgz", - "integrity": "sha512-v2kDEe57lecTulaDIuNTPy3Ry4gLGJ6Z1O3vE1krgXZNrsQ+LFTGHVxVjcXPs17LhbZVGedAJv8XZ1tvj5FvSg==", - "license": "MIT" - }, - "node_modules/regenerator-runtime": { - "version": "0.14.1", - "resolved": "https://registry.npmjs.org/regenerator-runtime/-/regenerator-runtime-0.14.1.tgz", - "integrity": "sha512-dYnhHh0nJoMfnkZs6GmmhFknAGRrLznOu5nc9ML+EJxGvrx6H7teuevqVqCuPcPK//3eDrrjQhehXVx9cnkGdw==", - "license": "MIT" - }, - "node_modules/require-directory": { - "version": "2.1.1", - "resolved": "https://registry.npmjs.org/require-directory/-/require-directory-2.1.1.tgz", - "integrity": "sha512-fGxEI7+wsG9xrvdjsrlmL22OMTTiHRwAMroiEeMgq8gzoLC/PQr7RsRDSTLUg/bZAZtF+TVIkHc6/4RIKrui+Q==", - "license": "MIT", - "engines": { - "node": ">=0.10.0" - } - }, - "node_modules/rxjs": { - "version": "7.8.1", - "resolved": "https://registry.npmjs.org/rxjs/-/rxjs-7.8.1.tgz", - "integrity": "sha512-AA3TVj+0A2iuIoQkWEK/tqFjBq2j+6PO6Y0zJcvzLAFhEFIO3HL0vls9hWLncZbAAbK0mar7oZ4V079I/qPMxg==", - "license": "Apache-2.0", - "dependencies": { - "tslib": "^2.1.0" - } - }, - "node_modules/shell-quote": { - "version": "1.8.1", - "resolved": "https://registry.npmjs.org/shell-quote/-/shell-quote-1.8.1.tgz", - "integrity": "sha512-6j1W9l1iAs/4xYBI1SYOVZyFcCis9b4KCLQ8fgAGG07QvzaRLVVRQvAy85yNmmZSjYjg4MWh4gNvlPujU/5LpA==", - "license": "MIT", - "funding": { - "url": "https://github.com/sponsors/ljharb" - } - }, - "node_modules/spawn-command": { - "version": "0.0.2", - "resolved": "https://registry.npmjs.org/spawn-command/-/spawn-command-0.0.2.tgz", - "integrity": "sha512-zC8zGoGkmc8J9ndvml8Xksr1Amk9qBujgbF0JAIWO7kXr43w0h/0GJNM/Vustixu+YE8N/MTrQ7N31FvHUACxQ==" - }, - "node_modules/string-width": { - "version": "4.2.3", - "resolved": "https://registry.npmjs.org/string-width/-/string-width-4.2.3.tgz", - "integrity": "sha512-wKyQRQpjJ0sIp62ErSZdGsjMJWsap5oRNihHhu6G7JVO/9jIB6UyevL+tXuOqrng8j/cxKTWyWUwvSTriiZz/g==", - "license": "MIT", - "dependencies": { - "emoji-regex": "^8.0.0", - "is-fullwidth-code-point": "^3.0.0", - "strip-ansi": "^6.0.1" - }, - "engines": { - "node": ">=8" - } - }, - "node_modules/strip-ansi": { - "version": "6.0.1", - "resolved": "https://registry.npmjs.org/strip-ansi/-/strip-ansi-6.0.1.tgz", - "integrity": "sha512-Y38VPSHcqkFrCpFnQ9vuSXmquuv5oXOKpGeT6aGrr3o3Gc9AlVa6JBfUSOCnbxGGZF+/0ooI7KrPuUSztUdU5A==", - "license": "MIT", - "dependencies": { - "ansi-regex": "^5.0.1" - }, - "engines": { - "node": ">=8" - } - }, - "node_modules/supports-color": { - "version": "8.1.1", - "resolved": "https://registry.npmjs.org/supports-color/-/supports-color-8.1.1.tgz", - "integrity": "sha512-MpUEN2OodtUzxvKQl72cUF7RQ5EiHsGvSsVG0ia9c5RbWGL2CI4C7EpPS8UTBIplnlzZiNuV56w+FuNxy3ty2Q==", - "license": "MIT", - "dependencies": { - "has-flag": "^4.0.0" - }, - "engines": { - "node": ">=10" - }, - "funding": { - "url": "https://github.com/chalk/supports-color?sponsor=1" - } - }, - "node_modules/tree-kill": { - "version": "1.2.2", - "resolved": "https://registry.npmjs.org/tree-kill/-/tree-kill-1.2.2.tgz", - "integrity": "sha512-L0Orpi8qGpRG//Nd+H90vFB+3iHnue1zSSGmNOOCh1GLJ7rUKVwV2HvijphGQS2UmhUZewS9VgvxYIdgr+fG1A==", - "license": "MIT", - "bin": { - "tree-kill": "cli.js" - } - }, - "node_modules/tslib": { - "version": "2.7.0", - "resolved": "https://registry.npmjs.org/tslib/-/tslib-2.7.0.tgz", - "integrity": "sha512-gLXCKdN1/j47AiHiOkJN69hJmcbGTHI0ImLmbYLHykhgeN0jVGola9yVjFgzCUklsZQMW55o+dW7IXv3RCXDzA==", - "license": "0BSD" - }, - "node_modules/wrap-ansi": { - "version": "7.0.0", - "resolved": "https://registry.npmjs.org/wrap-ansi/-/wrap-ansi-7.0.0.tgz", - "integrity": "sha512-YVGIj2kamLSTxw6NsZjoBxfSwsn0ycdesmc4p+Q21c5zPuZ1pl+NfxVdxPtdHvmNVOQ6XSYG4AUtyt/Fi7D16Q==", - "license": "MIT", - "dependencies": { - "ansi-styles": "^4.0.0", - "string-width": "^4.1.0", - "strip-ansi": "^6.0.0" - }, - "engines": { - "node": ">=10" - }, - "funding": { - "url": "https://github.com/chalk/wrap-ansi?sponsor=1" - } - }, - "node_modules/y18n": { - "version": "5.0.8", - "resolved": "https://registry.npmjs.org/y18n/-/y18n-5.0.8.tgz", - "integrity": "sha512-0pfFzegeDWJHJIAmTLRP2DwHjdF5s7jo9tuztdQxAhINCdvS+3nGINqPd00AphqJR/0LhANUS6/+7SCb98YOfA==", - "license": "ISC", - "engines": { - "node": ">=10" - } - }, - "node_modules/yargs": { - "version": "17.7.2", - "resolved": "https://registry.npmjs.org/yargs/-/yargs-17.7.2.tgz", - "integrity": "sha512-7dSzzRQ++CKnNI/krKnYRV7JKKPUXMEh61soaHKg9mrWEhzFWhFnxPxGl+69cD1Ou63C13NUPCnmIcrvqCuM6w==", - "license": "MIT", - "dependencies": { - "cliui": "^8.0.1", - "escalade": "^3.1.1", - "get-caller-file": "^2.0.5", - "require-directory": "^2.1.1", - "string-width": "^4.2.3", - "y18n": "^5.0.5", - "yargs-parser": "^21.1.1" - }, - "engines": { - "node": ">=12" - } - }, - "node_modules/yargs-parser": { - "version": "21.1.1", - "resolved": "https://registry.npmjs.org/yargs-parser/-/yargs-parser-21.1.1.tgz", - "integrity": "sha512-tVpsJW7DdjecAiFpbIB1e3qxIQsE6NoPc5/eTdrbbIC4h0LVsWhnoa3g+m2HclBIujHzsxZ4VJVA+GUuc2/LBw==", - "license": "ISC", - "engines": { - "node": ">=12" - } - } - } -} From de19d7d6cdc940ad8cc4816f197ee7f3afdb65ab Mon Sep 17 00:00:00 2001 From: Jay Nagpaul Date: Fri, 15 Nov 2024 15:58:57 -0500 Subject: [PATCH 2/2] Fix race condition --- mobile/screens/User/UserDashboardScreen.tsx | 119 ++++++++++++-------- 1 file changed, 72 insertions(+), 47 deletions(-) diff --git a/mobile/screens/User/UserDashboardScreen.tsx b/mobile/screens/User/UserDashboardScreen.tsx index 5acbc5fb..4aa724e5 100644 --- a/mobile/screens/User/UserDashboardScreen.tsx +++ b/mobile/screens/User/UserDashboardScreen.tsx @@ -1,4 +1,4 @@ -import React, { useEffect, useState } from "react"; +import React, { useEffect, useReducer, useState } from "react"; import { BackHandler, StyleSheet, @@ -16,7 +16,6 @@ import { userGetAnimal, userUpdateAnimal } from "../../actions/Animal"; import { Announcement, ModalContent, - NotificationState, Screens, ServiceAnimal, TrainingLog, @@ -40,6 +39,49 @@ import shadowStyle from "../../utils/styles"; import { userSendEmail } from "../../actions/Email"; import DashboardModal from "../../components/DashboardModal"; +type ModalQueueState = { + birthdayQueued: boolean; + prescriptionQueued: boolean; + shotQueued: boolean; + + modals: ModalContent[]; +}; + +function modalQueueReducer( + state: ModalQueueState, + action: ModalContent | "close" +): ModalQueueState { + if (action === "close") { + return { ...state, modals: state.modals.slice(1) }; + } + + switch (action.type) { + case "birthday": + if (state.birthdayQueued) return state; + return { + ...state, + modals: [...state.modals, action], + birthdayQueued: true, + }; + case "prescription": + if (state.prescriptionQueued) return state; + return { + ...state, + modals: [...state.modals, action], + prescriptionQueued: true, + }; + case "shot": + if (state.shotQueued) return state; + return { + ...state, + modals: [...state.modals, action], + shotQueued: true, + }; + default: + return state; + } +} + export default function UserDashboardScreen(props: any) { const [hoursCompleted, setHoursCompleted] = useState(0); const [userInfo, setUserInfo] = useState(null); @@ -49,30 +91,20 @@ export default function UserDashboardScreen(props: any) { const [announcements, setAnnouncements] = useState([]); const [error, setError] = useState(""); const [calculatedShotDate, setCalculatedShotDate] = useState(); - const [modalQueue, setModalQueue] = useState([]); - const [notificationsShown, setNotificationsShown] = - useState({ - birthday: false, - prescription: false, - shot: false, - }); - const addToModalQueue = ( - type: ModalContent["type"], - content: string, - additionalContent?: string - ) => { - if (!notificationsShown[type]) { - setModalQueue((prev) => [...prev, { type, content, additionalContent }]); - setNotificationsShown((prev) => ({ ...prev, [type]: true })); - } - }; + const [modalQueue, modalQueueDispatch] = useReducer(modalQueueReducer, { + modals: [], + + birthdayQueued: false, + prescriptionQueued: false, + shotQueued: false, + }); const checkPrescriptionReminder = async ( userInformation: User, animalInformation: ServiceAnimal ) => { - if (notificationsShown.prescription) return; + if (modalQueue.prescriptionQueued) return; if (!userInformation) { userInformation = (await ErrorWrapper({ @@ -113,10 +145,10 @@ export default function UserDashboardScreen(props: any) { } if (today >= new Date(userInformation?.nextPrescriptionReminder)) { - addToModalQueue( - "prescription", - `This is a reminder to fill your prescription for ${animalInformation.name}'s heartworm preventative pill.` - ); + modalQueueDispatch({ + type: "prescription", + content: `This is a reminder to fill your prescription for ${animalInformation.name}'s heartworm preventative pill.`, + }); await userUpdateUser( userInformation.roles, @@ -137,7 +169,7 @@ export default function UserDashboardScreen(props: any) { animalInformation: ServiceAnimal, userInformation: User ) => { - if (notificationsShown.shot) return; + if (modalQueue.shotQueued) return; if (!animalInformation) { animalInformation = (await ErrorWrapper({ @@ -167,18 +199,18 @@ export default function UserDashboardScreen(props: any) { if (newDate > new Date()) return; - addToModalQueue( - "shot", - `${animalInformation?.name} needs their rabies shot.`, - `${animalInformation?.name} was due on ${newDate.toLocaleDateString( + modalQueueDispatch({ + type: "shot", + content: `${animalInformation?.name} needs their rabies shot.`, + additionalContent: `${animalInformation?.name} was due on ${newDate.toLocaleDateString( "en-US", { year: "numeric", month: "long", day: "numeric", } - )}` - ); + )}`, + }); const newAnimal = await userUpdateAnimal( animalInformation?.name, @@ -222,22 +254,22 @@ export default function UserDashboardScreen(props: any) { }; const checkBirthday = (animal: ServiceAnimal) => { - if (notificationsShown.birthday) return; + if (modalQueue.birthdayQueued) return; if ( new Date(animal?.dateOfBirth as Date).getMonth() === new Date().getMonth() && new Date(animal?.dateOfBirth as Date).getDate() === new Date().getDate() ) { - addToModalQueue( - "birthday", - `Happy birthday ${animal.name}!!! \uE312`, - `${animal.name} turned ${calculateAge( + modalQueueDispatch({ + type: "birthday", + content: `Happy birthday ${animal.name}!!! \uE312`, + additionalContent: `${animal.name} turned ${calculateAge( new Date(animal.dateOfBirth ?? "") )} year${ calculateAge(new Date(animal.dateOfBirth ?? "")) !== 1 ? "s" : "" - } old today!` - ); + } old today!`, + }); } }; @@ -287,13 +319,6 @@ export default function UserDashboardScreen(props: any) { } } - // Reset notifications shown state when component mounts - setNotificationsShown({ - birthday: false, - prescription: false, - shot: false, - }); - getUserDashboardInformation().catch(); BackHandler.addEventListener("hardwareBackPress", function () { @@ -326,9 +351,9 @@ export default function UserDashboardScreen(props: any) { {new Date().getMonth() === 1 ? : null} { - setModalQueue((prev) => prev.slice(1)); + modalQueueDispatch("close"); }} />