mirror of
https://github.com/bitsocialnet/5chan.git
synced 2026-08-03 07:41:04 +02:00
fix(reply modal): get mobile scroll position from hook before render
This commit is contained in:
@@ -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}>
|
||||
|
||||
Reference in New Issue
Block a user