From f79ced1db7e08e8cecddcf77211119e02cf0e3eb Mon Sep 17 00:00:00 2001 From: "Tom (plebeius.eth)" Date: Mon, 2 Dec 2024 17:29:41 +0100 Subject: [PATCH] remove unnecessary portal --- src/components/reply/reply.module.css | 15 +------- src/components/reply/reply.tsx | 29 +++------------ src/hooks/use-element-position.ts | 52 --------------------------- 3 files changed, 5 insertions(+), 91 deletions(-) delete mode 100644 src/hooks/use-element-position.ts diff --git a/src/components/reply/reply.module.css b/src/components/reply/reply.module.css index eb1ad19c..6ab77624 100644 --- a/src/components/reply/reply.module.css +++ b/src/components/reply/reply.module.css @@ -227,6 +227,7 @@ .collapsedEntry { padding-left: 25px; + min-height: 16px; } .parent { @@ -363,20 +364,6 @@ } } -.portalLabel { - pointer-events: none; - font-size: x-small; - font-family: verdana, arial, helvetica, sans-serif; - font-size: x-small; - display: inline-block; - margin-left: 4px; -} - -.collapsedStateLabel { - display: inline-block; - margin-left: 4px; -} - .stamp { font-family: inherit; font-size: x-small; diff --git a/src/components/reply/reply.tsx b/src/components/reply/reply.tsx index 661683db..89f249d4 100644 --- a/src/components/reply/reply.tsx +++ b/src/components/reply/reply.tsx @@ -1,11 +1,10 @@ -import { Fragment, useEffect, useMemo, useState, useRef } from 'react'; +import { Fragment, useEffect, useMemo, useState } from 'react'; import { Comment, useAccountComment, useAuthorAddress, useAuthorAvatar, useBlock, useComment, useEditedComment, useSubplebbit } from '@plebbit/plebbit-react-hooks'; import { flattenCommentsPages } from '@plebbit/plebbit-react-hooks/dist/lib/utils'; import { Link, useLocation, useParams } from 'react-router-dom'; import { useTranslation } from 'react-i18next'; import styles from './reply.module.css'; import { useCommentMediaInfo } from '../../hooks/use-comment-media-info'; -import { useElementPosition } from '../../hooks/use-element-position'; import useReplies from '../../hooks/use-replies'; import { CommentMediaInfo, getHasThumbnail } from '../../lib/utils/media-utils'; import { formatLocalizedUTCTimestamp, getFormattedTimeAgo } from '../../lib/utils/time-utils'; @@ -25,7 +24,6 @@ import { isInboxView, isPostContextView, isPostView } from '../../lib/utils/view import Plebbit from '@plebbit/plebbit-js/dist/browser/index.js'; import Markdown from '../markdown'; import { getHostname } from '../../lib/utils/url-utils'; -import { createPortal } from 'react-dom'; interface ReplyAuthorProps { address: string; @@ -336,8 +334,6 @@ const Reply = ({ cidOfReplyWithContext, depth = 0, isSingleComment, isSingleRepl setCollapsed(!collapsed); }; - const taglineRef = useRef(null); - const labelPosition = useElementPosition(taglineRef, collapsed); const stateLabel = ( {state === 'failed' && {' '} {pinned && - {t('stickied_comment')}} {collapsed && ( - - {' '} - ({childrenString}){' '} - + <> + ({childrenString}) {stateLabel} {state === 'pending' && loadingString} + )} {!collapsed && stateLabel} {!collapsed && flair && ( @@ -508,22 +503,6 @@ const Reply = ({ cidOfReplyWithContext, depth = 0, isSingleComment, isSingleRepl )} - {collapsed && - labelPosition && - createPortal( -
- {stateLabel} {state === 'pending' && loadingString} -
, - document.body, - )} ); }; diff --git a/src/hooks/use-element-position.ts b/src/hooks/use-element-position.ts deleted file mode 100644 index 04000c2d..00000000 --- a/src/hooks/use-element-position.ts +++ /dev/null @@ -1,52 +0,0 @@ -import { useState, useEffect } from 'react'; - -interface Position { - top: number; - left: number; -} - -export const useElementPosition = (ref: React.RefObject, enabled: boolean | undefined) => { - const [position, setPosition] = useState(null); - - useEffect(() => { - if (!ref.current || !enabled) { - setPosition(null); - return; - } - - let rafId: number; - let lastTop: number = 0; - let lastLeft: number = 0; - - const updatePosition = () => { - if (!ref.current) return; - - const rect = ref.current.getBoundingClientRect(); - const newTop = window.scrollY + rect.top + rect.height / 2; - const newLeft = rect.right + 5; - - // Only update state if position actually changed - if (newTop !== lastTop || newLeft !== lastLeft) { - lastTop = newTop; - lastLeft = newLeft; - setPosition({ top: newTop, left: newLeft }); - } - - rafId = requestAnimationFrame(updatePosition); - }; - - // Start the animation frame loop - updatePosition(); - - // Also watch for size changes - const resizeObserver = new ResizeObserver(updatePosition); - resizeObserver.observe(ref.current); - - return () => { - cancelAnimationFrame(rafId); - resizeObserver.disconnect(); - }; - }, [ref, enabled]); - - return position; -};