Skip to content

Commit

Permalink
use useLockedBody to lock common feed and toggle scrolling for Modal
Browse files Browse the repository at this point in the history
  • Loading branch information
roienatan committed Dec 1, 2023
1 parent 7bfe24f commit dce1b9d
Show file tree
Hide file tree
Showing 3 changed files with 9 additions and 5 deletions.
1 change: 0 additions & 1 deletion src/index.scss
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,6 @@

html {
background-color: var(--primary-background);
overflow: hidden;
}

:root {
Expand Down
4 changes: 4 additions & 0 deletions src/pages/commonFeed/CommonFeedPage.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@ import { useParams } from "react-router-dom";
import { selectUser } from "@/pages/Auth/store/selectors";
import { InboxItemType } from "@/shared/constants";
import { MainRoutesProvider } from "@/shared/contexts";
import { useLockedBody } from "@/shared/hooks";
import { useLastVisitedCommon } from "@/shared/hooks/useCases";
import { MultipleSpacesLayoutPageContent } from "@/shared/layouts";
import {
Expand Down Expand Up @@ -58,6 +59,7 @@ const renderContentWrapper: RenderCommonFeedContentWrapper = ({

const CommonFeedPage: FC = () => {
const { id: commonId } = useParams<CommonFeedPageRouterParams>();
const { lockBodyScroll, unlockBodyScroll } = useLockedBody();
const dispatch = useDispatch();
const layoutMainWidth = useSelector(selectMultipleSpacesLayoutMainWidth);
const user = useSelector(selectUser());
Expand Down Expand Up @@ -97,7 +99,9 @@ const CommonFeedPage: FC = () => {
}, [commonId]);

useEffect(() => {
lockBodyScroll();
return () => {
unlockBodyScroll();
dispatch(multipleSpacesLayoutActions.clearBreadcrumbs());
};
}, []);
Expand Down
9 changes: 5 additions & 4 deletions src/shared/components/Modal/Modal.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@ import React, {
import ReactDOM from "react-dom";
import classNames from "classnames";
import { v4 as uuidv4 } from "uuid";
import { useComponentWillUnmount } from "../../hooks";
import { useComponentWillUnmount, useLockedBody } from "../../hooks";
import Close2Icon from "../../icons/close2.icon";
import LeftArrowIcon from "../../icons/leftArrow.icon";
import { ModalProps, ModalRef, ModalType } from "../../interfaces";
Expand Down Expand Up @@ -54,6 +54,7 @@ const Modal: ForwardRefRenderFunction<ModalRef, ModalProps> = (
const { sticky: isFooterSticky = false } = footerOptions;
const [showClosePrompt, setShowClosePrompt] = useState(false);
const modalId = useMemo(() => `modal-${uuidv4()}`, []);
const { lockBodyScroll, unlockBodyScroll } = useLockedBody();

const handleModalContainerClick: MouseEventHandler = (event) => {
event.stopPropagation();
Expand Down Expand Up @@ -87,7 +88,7 @@ const Modal: ForwardRefRenderFunction<ModalRef, ModalProps> = (
}

const modalRoot = document.getElementById(modalId);
document.body.style.overflow = "initial";
unlockBodyScroll();

if (modalRoot) {
document.body.removeChild(modalRoot);
Expand All @@ -97,12 +98,12 @@ const Modal: ForwardRefRenderFunction<ModalRef, ModalProps> = (
useEffect(() => {
if (!isShowing) {
const modalRoot = document.getElementById(modalId);
document.body.style.overflow = "initial";
unlockBodyScroll();
if (modalRoot) {
document.body.removeChild(modalRoot);
}
} else {
document.body.style.overflow = "hidden";
lockBodyScroll();
}
}, [isShowing, modalId]);

Expand Down

0 comments on commit dce1b9d

Please sign in to comment.