From 1f398af4deda8a5b0b585ed02078177ebd5bc843 Mon Sep 17 00:00:00 2001 From: Drew Del Rosario Date: Wed, 9 Aug 2023 21:05:42 -0700 Subject: [PATCH 1/2] Add ringdown state to context --- client/src/Context.js | 3 +++ client/src/ER/RingdownSection.js | 21 +++++++++++++++------ 2 files changed, 18 insertions(+), 6 deletions(-) diff --git a/client/src/Context.js b/client/src/Context.js index 14adc654..f35f92b0 100644 --- a/client/src/Context.js +++ b/client/src/Context.js @@ -10,6 +10,7 @@ function ContextProvider({ children }) { const [organization, setOrganization] = useState(); const [hospital, setHospital] = useState(); const [hospitalUser, setHospitalUser] = useState(); + const [ringdownSection, setRingdownSection] = useState({}); const value = { user, @@ -24,6 +25,8 @@ function ContextProvider({ children }) { setHospital, hospitalUser, setHospitalUser, + ringdownSection, + setRingdownSection, }; return {children}; } diff --git a/client/src/ER/RingdownSection.js b/client/src/ER/RingdownSection.js index 52ebaae8..3d0310d5 100644 --- a/client/src/ER/RingdownSection.js +++ b/client/src/ER/RingdownSection.js @@ -1,21 +1,30 @@ -import React, { useState } from 'react'; +import React, { useContext } from 'react'; import PropTypes from 'prop-types'; import Ringdown from '../Models/Ringdown'; import RingdownCard from '../Components/RingdownCard'; +import Context from '../Context'; import './RingdownSection.scss'; function RingdownSection({ title, ringdowns, onStatusChange }) { - const [isExpanded, setExpanded] = useState(true); + const { ringdownSection, setRingdownSection } = useContext(Context); + + const isMinimized = ringdownSection[title] || false; + const handleExpand = () => { + setRingdownSection({ + ...ringdownSection, + [title]: !isMinimized, + }); + }; return (
setExpanded(!isExpanded)} + onClick={handleExpand} onKeyDown={(event) => { - if (event.key === 'Enter') setExpanded(!isExpanded); + if (event.key === 'Enter') handleExpand(); }} role="button" tabIndex={0} @@ -25,10 +34,10 @@ function RingdownSection({ title, ringdowns, onStatusChange }) {
{ringdowns.length}
- {isExpanded ? : } + {!isMinimized ? : }
- {isExpanded && + {!isMinimized && ringdowns.map((r) => )} ); From 66571f5bda8826e5b64b509c05d6183b3dff3c2f Mon Sep 17 00:00:00 2001 From: Drew Del Rosario Date: Wed, 16 Aug 2023 20:14:57 -0700 Subject: [PATCH 2/2] Cleanup --- client/src/ER/RingdownSection.js | 9 +++++---- 1 file changed, 5 insertions(+), 4 deletions(-) diff --git a/client/src/ER/RingdownSection.js b/client/src/ER/RingdownSection.js index 3d0310d5..188470e1 100644 --- a/client/src/ER/RingdownSection.js +++ b/client/src/ER/RingdownSection.js @@ -10,11 +10,12 @@ import './RingdownSection.scss'; function RingdownSection({ title, ringdowns, onStatusChange }) { const { ringdownSection, setRingdownSection } = useContext(Context); - const isMinimized = ringdownSection[title] || false; + const isExpanded = !!ringdownSection[title]; + const handleExpand = () => { setRingdownSection({ ...ringdownSection, - [title]: !isMinimized, + [title]: !isExpanded, }); }; @@ -34,10 +35,10 @@ function RingdownSection({ title, ringdowns, onStatusChange }) {
{ringdowns.length}
- {!isMinimized ? : } + {isExpanded ? : }
- {!isMinimized && + {isExpanded && ringdowns.map((r) => )} );