Skip to content

Commit

Permalink
Fixed overlay
Browse files Browse the repository at this point in the history
  • Loading branch information
MAKCKACHKA committed Jan 2, 2024
1 parent 4a5c80d commit 4b21c4a
Show file tree
Hide file tree
Showing 3 changed files with 27 additions and 9 deletions.
2 changes: 0 additions & 2 deletions src/components/Header/Header.styled.jsx
Original file line number Diff line number Diff line change
Expand Up @@ -282,7 +282,5 @@ export const OverlayContainer = styled.div`
left: 0;
width: 100%;
height: 100%;
/* background: rgba(0, 0, 0, 0.5); */
display: ${(props) => (props.visible ? 'block' : 'none')};
z-index: 1;
`;
21 changes: 17 additions & 4 deletions src/components/Header/HeaderVariables/HeaderAuth.jsx
Original file line number Diff line number Diff line change
Expand Up @@ -45,6 +45,17 @@ export const HeaderAuth = () => {
const [modalIsOpen, setIsOpen] = useState(false);

const [overlay, setOverlay] = useState(false);
const [linked, setLinked] = useState(false);

useEffect(() => {
if (modalIsOpen) {
setIsOpen(true);
setOverlay(false);
}
if (linked) {
setOverlay(false);
}
}, [modalIsOpen, overlay, linked]);

useEffect(() => {
const handleResize = () => {
Expand All @@ -65,6 +76,7 @@ export const HeaderAuth = () => {
setWeightModal(false);
setUserModal(false);
setMenuModal(false);
setOverlay(false);
}
};
window.addEventListener('keydown', handleKeyPress);
Expand Down Expand Up @@ -112,18 +124,17 @@ export const HeaderAuth = () => {

return (
<HeaderContainer2>
<LogOutModal modalIsOpen={modalIsOpen} setIsOpen={setIsOpen} />
<OverlayContainer
visible={overlay}
style={overlay ? { display: 'block' } : { display: 'none' }}
onClick={() => {
setOverlay(false);
setGoalModal(false);
setWeightModal(false);
setUserModal(false);
setMenuModal(false);
setIsOpen(false);
}}
/>
<LogOutModal modalIsOpen={modalIsOpen} setIsOpen={setIsOpen} />

<MobileLogoBtnWrap>
<LogoLink to="/main">HealthyHub</LogoLink>
Expand Down Expand Up @@ -193,6 +204,7 @@ export const HeaderAuth = () => {
</InfoContainer>
{goalModal && (
<GoalModal
setMenuModal={setMenuModal}
setGoalModal={setGoalModal}
run={run}
maintain={maintain}
Expand All @@ -204,6 +216,7 @@ export const HeaderAuth = () => {
)}
{weightModal && (
<WeightModal
setMenuModal={setMenuModal}
setWeightModal={setWeightModal}
initialValues={initialValuesW}
setWeightValue={setWeightValue}
Expand Down Expand Up @@ -236,7 +249,7 @@ export const HeaderAuth = () => {
<use href={`${icons}#icon-arrow-down`} />
</DropIcon>
{userModal && (
<UserModal setIsOpen={setIsOpen} setOverlay={setOverlay} />
<UserModal setIsOpen={setIsOpen} setLinked={setLinked} />
)}
</AvatarContainer>
{menuModal && (
Expand Down
13 changes: 10 additions & 3 deletions src/components/Header/Modals/UserModal.jsx
Original file line number Diff line number Diff line change
Expand Up @@ -2,10 +2,18 @@ import icons from '../../../assets/icons.svg';

import { UserModalBody, ModalLink, ModalButton } from './ModalStyles';

export const UserModal = ({ setIsOpen, setOverlay }) => {
export const UserModal = ({ setIsOpen, setLinked }) => {
return (
<UserModalBody>
<ModalLink to="/settings">
<ModalLink
to="/settings"
onClick={() => {
setLinked(true);
setTimeout(() => {
setLinked(false);
}, 1);
}}
>
<svg>
<use href={`${icons}#icon-setting-2`} />
</svg>
Expand All @@ -14,7 +22,6 @@ export const UserModal = ({ setIsOpen, setOverlay }) => {
<ModalButton
onClick={() => {
setIsOpen(true);
setOverlay(false);
}}
>
<svg>
Expand Down

0 comments on commit 4b21c4a

Please sign in to comment.