Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add ringdown state to context #312

Open
wants to merge 3 commits into
base: dev
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 3 additions & 0 deletions client/src/Context.js
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand All @@ -24,6 +25,8 @@ function ContextProvider({ children }) {
setHospital,
hospitalUser,
setHospitalUser,
ringdownSection,
setRingdownSection,
};
return <Context.Provider value={value}>{children}</Context.Provider>;
}
Expand Down
18 changes: 14 additions & 4 deletions client/src/ER/RingdownSection.js
Original file line number Diff line number Diff line change
@@ -1,21 +1,31 @@
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 isExpanded = !!ringdownSection[title];

const handleExpand = () => {
setRingdownSection({
...ringdownSection,
[title]: !isExpanded,
});
};

return (
<div className="ringdown-section">
<div
className="usa-accordion__heading ringdown-section__header"
onClick={() => setExpanded(!isExpanded)}
onClick={handleExpand}
onKeyDown={(event) => {
if (event.key === 'Enter') setExpanded(!isExpanded);
if (event.key === 'Enter') handleExpand();
}}
role="button"
tabIndex={0}
Expand Down