mirror of
https://github.com/bitsocialnet/5chan.git
synced 2026-08-03 07:41:04 +02:00
improve PostOnHover positioning logic
This commit is contained in:
@@ -482,8 +482,8 @@ const Thread = () => {
|
||||
|
||||
useLayoutEffect(() => {
|
||||
if (postOnHoverRef.current) {
|
||||
const rect = postOnHoverRef.current.getBoundingClientRect();
|
||||
setPostOnHoverHeight(rect.height);
|
||||
const rect = postOnHoverRef.current.getBoundingClientRect();
|
||||
setPostOnHoverHeight(rect.height);
|
||||
}
|
||||
}, [outOfViewCid]);
|
||||
|
||||
@@ -949,10 +949,21 @@ const Thread = () => {
|
||||
handleQuoteHover(reply, null, () => {
|
||||
setOutOfViewCid(reply.cid);
|
||||
const rect = backlinkRefs.current[reply.cid].getBoundingClientRect();
|
||||
setOutOfViewPosition({
|
||||
top: rect.top + window.scrollY - rect.height / 2,
|
||||
left: rect.left + rect.width + 5,
|
||||
});
|
||||
const distanceToRight = window.innerWidth - rect.right;
|
||||
if (distanceToRight < 200) {
|
||||
setOutOfViewPosition({
|
||||
top: rect.top + window.scrollY - rect.height / 2,
|
||||
left: rect.left - rect.innerWidth - 5,
|
||||
maxWidth: rect.left
|
||||
});
|
||||
|
||||
} else {
|
||||
setOutOfViewPosition({
|
||||
top: rect.top + window.scrollY - rect.height / 2,
|
||||
left: rect.left + rect.width + 5,
|
||||
maxWidth: window.innerWidth - rect.left - rect.width
|
||||
});
|
||||
}
|
||||
});
|
||||
}}
|
||||
onMouseLeave={() => {
|
||||
@@ -1150,10 +1161,21 @@ const Thread = () => {
|
||||
handleQuoteHover(reply, null, () => {
|
||||
setOutOfViewCid(reply.cid);
|
||||
const rect = backlinkRefs.current[reply.cid].getBoundingClientRect();
|
||||
setOutOfViewPosition({
|
||||
top: rect.top + window.scrollY - rect.height / 2,
|
||||
left: rect.left + rect.width + 5,
|
||||
});
|
||||
const distanceToRight = window.innerWidth - rect.right;
|
||||
if (distanceToRight < 200) {
|
||||
setOutOfViewPosition({
|
||||
top: rect.top + window.scrollY - rect.height / 2,
|
||||
left: rect.left - rect.innerWidth - 5,
|
||||
maxWidth: rect.left
|
||||
});
|
||||
|
||||
} else {
|
||||
setOutOfViewPosition({
|
||||
top: rect.top + window.scrollY - rect.height / 2,
|
||||
left: rect.left + rect.width + 5,
|
||||
maxWidth: window.innerWidth - rect.left - rect.width
|
||||
});
|
||||
}
|
||||
});
|
||||
}}
|
||||
onMouseLeave={() => {
|
||||
@@ -1233,10 +1255,21 @@ const Thread = () => {
|
||||
} else {
|
||||
setOutOfViewCid(reply.parentCid);
|
||||
const rect = quoteRefs.current[shortParentCid].getBoundingClientRect();
|
||||
setOutOfViewPosition({
|
||||
top: rect.top + window.scrollY - rect.height / 2,
|
||||
left: rect.left + rect.width + 5,
|
||||
});
|
||||
const distanceToRight = window.innerWidth - rect.right;
|
||||
if (distanceToRight < 200) {
|
||||
setOutOfViewPosition({
|
||||
top: rect.top + window.scrollY - rect.height / 2,
|
||||
left: rect.left - rect.innerWidth - 5,
|
||||
maxWidth: rect.left
|
||||
});
|
||||
|
||||
} else {
|
||||
setOutOfViewPosition({
|
||||
top: rect.top + window.scrollY - rect.height / 2,
|
||||
left: rect.left + rect.width + 5,
|
||||
maxWidth: window.innerWidth - rect.left - rect.width
|
||||
});
|
||||
}
|
||||
}
|
||||
});
|
||||
}}
|
||||
@@ -1639,23 +1672,23 @@ const Thread = () => {
|
||||
) : (null)}
|
||||
</>
|
||||
)) : null}
|
||||
{createPortal(
|
||||
{outOfViewCid && outOfViewPosition && createPortal(
|
||||
<div
|
||||
ref={postOnHoverRef}
|
||||
ref={postOnHoverRef}
|
||||
style={{
|
||||
display: outOfViewCid ? "block" : "none",
|
||||
display: "block",
|
||||
position: "absolute",
|
||||
top: outOfViewPosition.top - postOnHoverHeight / 2 + 10,
|
||||
left: outOfViewPosition.left,
|
||||
left: outOfViewPosition.left,
|
||||
maxWidth: outOfViewPosition.maxWidth,
|
||||
}}
|
||||
>
|
||||
<PostOnHover
|
||||
cid={outOfViewCid}
|
||||
feed={comment}
|
||||
/>
|
||||
</div>
|
||||
, document.body
|
||||
)}
|
||||
>
|
||||
<PostOnHover
|
||||
cid={outOfViewCid}
|
||||
feed={comment}
|
||||
/>
|
||||
</div>
|
||||
, document.body)}
|
||||
</BoardForm>
|
||||
<Footer selectedStyle={selectedStyle}>
|
||||
<Break id="break" selectedStyle={selectedStyle} style={{
|
||||
|
||||
Reference in New Issue
Block a user