fix(reply modal): get mobile scroll position from hook before render

This commit is contained in:
plebeius.eth
2024-04-30 11:08:01 +02:00
parent d797dbd0bd
commit 1e91119687
4 changed files with 17 additions and 9 deletions
+3 -3
View File
@@ -13,9 +13,10 @@ import _ from 'lodash';
interface ReplyModalProps {
closeModal: () => void;
parentCid: string;
scrollY: number;
}
const ReplyModal = ({ closeModal, parentCid }: ReplyModalProps) => {
const ReplyModal = ({ closeModal, parentCid, scrollY }: ReplyModalProps) => {
const { t } = useTranslation();
const { subplebbitAddress } = useParams() as { subplebbitAddress: string };
const { setContent, resetContent, replyIndex, publishReply } = useReply({ cid: parentCid, subplebbitAddress });
@@ -56,12 +57,11 @@ const ReplyModal = ({ closeModal, parentCid }: ReplyModalProps) => {
useEffect(() => {
if (nodeRef.current && isMobile) {
const viewportHeight = window.innerHeight;
const scrollY = window.scrollY;
const modalHeight = 150;
const centeredPosition = scrollY + viewportHeight / 2 - modalHeight / 2;
nodeRef.current.style.top = `${centeredPosition}px`;
}
}, [isMobile]);
}, [isMobile, scrollY]);
const modalContent = (
<div className={styles.container} ref={nodeRef}>