diff --git a/src/components/views/AllCatalog.jsx b/src/components/views/AllCatalog.jsx index da8a0bf6..71ac7a58 100755 --- a/src/components/views/AllCatalog.jsx +++ b/src/components/views/AllCatalog.jsx @@ -78,10 +78,21 @@ const CatalogPost = ({post}) => { const postMenuCatalogRef = useRef(null); const popupRef = useRef(null); const threadRefs = useRef([]); + const textRef = useRef(null); + const imageRef = useRef(null); const [isEnoughSpaceOnRight, setIsEnoughSpaceOnRight] = useState(null); const [isEnoughSpaceOnLeft,setIsEnoughSpaceOnLeft] = useState(null); const [isCalculationDone,setIsCalculationDone] = useState(false); const [hoverTimeoutId, setHoverTimeoutId] = useState(null); + const textRect = textRef.current?.getBoundingClientRect(); + const imageRect = imageRef.current?.getBoundingClientRect(); + const isMediaShowed = (thread.link && commentMediaInfo && ( + commentMediaInfo.type === 'image' || + commentMediaInfo.type === 'video' || + (commentMediaInfo.type === 'webpage' && + commentMediaInfo.thumbnail) || + (commentMediaInfo.type === 'iframe' && + commentMediaInfo.thumbnail))) ? true : false; useLayoutEffect(() => { @@ -337,8 +348,17 @@ const CatalogPost = ({post}) => { style={{ opacity: isCalculationDone && isEnoughSpaceOnRight !== null ? 1 : 0, visibility: isCalculationDone && isEnoughSpaceOnRight !== null ? 'visible' : 'hidden', - left: isCalculationDone && isEnoughSpaceOnRight !== null && isEnoughSpaceOnRight ? '100%' : 'auto', - right: isCalculationDone && isEnoughSpaceOnRight !== null && !isEnoughSpaceOnRight ? '100%' : 'auto',}} + left: isCalculationDone && isEnoughSpaceOnRight !== null && isEnoughSpaceOnRight + ? isMediaShowed + ? `calc(50% + ${imageRect.width}px / 2 + 5px)` + : `calc(50% + ${textRect.width}px / 2 + 5px)` + : 'auto', + right: isCalculationDone && isEnoughSpaceOnRight !== null && !isEnoughSpaceOnRight + ? isMediaShowed + ? `calc(50% + ${imageRect.width}px / 2 + 5px)` + : `calc(50% + ${textRect.width}px / 2 + 5px)` + : 'auto', + }} className="thread_popup">

{ {commentMediaInfo?.type === "webpage" ? ( thread.thumbnailUrl ? ( - {commentMediaInfo.type} { e.target.src = fallbackImgUrl @@ -380,7 +400,7 @@ const CatalogPost = ({post}) => { ) : null} {commentMediaInfo?.type === "image" ? ( - {commentMediaInfo.type} { e.target.src = fallbackImgUrl @@ -389,14 +409,14 @@ const CatalogPost = ({post}) => { ) : null} {commentMediaInfo?.type === "video" ? ( - ) : null} {commentMediaInfo?.type === "audio" ? ( -

(threadRefs.current[thread.cid] = el)}> - {thread.title ? `${thread.title}` : null} - {thread.content ? `: ${thread.content}` : null} + + {thread.title ? `${thread.title}` : null} + {thread.content ? `: ${thread.content}` : null} +
diff --git a/src/components/views/Catalog.jsx b/src/components/views/Catalog.jsx index 52d718a4..4c20bb25 100755 --- a/src/components/views/Catalog.jsx +++ b/src/components/views/Catalog.jsx @@ -76,6 +76,7 @@ const CatalogPost = ({post}) => { const threadMenuRefs = useRef({}); const postMenuRef = useRef(null); const postMenuCatalogRef = useRef(null); + const textRef = useRef(null); const { subplebbitAddress } = useParams(); const [, setNewErrorMessage] = useError(); @@ -86,12 +87,21 @@ const CatalogPost = ({post}) => { const account = useAccount(); const popupRef = useRef(null); const threadRefs = useRef([]); + const imageRef = useRef(null); const [isEnoughSpaceOnRight, setIsEnoughSpaceOnRight] = useState(null); const [isEnoughSpaceOnLeft,setIsEnoughSpaceOnLeft] = useState(null); const [isCalculationDone,setIsCalculationDone] = useState(false); const [hoverTimeoutId, setHoverTimeoutId] = useState(null); const [isHoveringForMenu, setIsHoveringForMenu] = useState(false); - + const textRect = textRef.current?.getBoundingClientRect(); + const imageRect = imageRef.current?.getBoundingClientRect(); + const isMediaShowed = (thread.link && commentMediaInfo && ( + commentMediaInfo.type === 'image' || + commentMediaInfo.type === 'video' || + (commentMediaInfo.type === 'webpage' && + commentMediaInfo.thumbnail) || + (commentMediaInfo.type === 'iframe' && + commentMediaInfo.thumbnail))) ? true : false; useLayoutEffect(() => { const executeLayoutEffectLogic = () => { @@ -588,8 +598,17 @@ const CatalogPost = ({post}) => { style={{ opacity: isCalculationDone && isEnoughSpaceOnRight !== null ? 1 : 0, visibility: isCalculationDone && isEnoughSpaceOnRight !== null ? 'visible' : 'hidden', - left: isCalculationDone && isEnoughSpaceOnRight !== null && isEnoughSpaceOnRight ? '100%' : 'auto', - right: isCalculationDone && isEnoughSpaceOnRight !== null && !isEnoughSpaceOnRight ? '100%' : 'auto',}} + left: isCalculationDone && isEnoughSpaceOnRight !== null && isEnoughSpaceOnRight + ? isMediaShowed + ? `calc(50% + ${imageRect.width}px / 2 + 5px)` + : `calc(50% + ${textRect.width}px / 2 + 5px)` + : 'auto', + right: isCalculationDone && isEnoughSpaceOnRight !== null && !isEnoughSpaceOnRight + ? isMediaShowed + ? `calc(50% + ${imageRect.width}px / 2 + 5px)` + : `calc(50% + ${textRect.width}px / 2 + 5px)` + : 'auto', + }} className="thread_popup">

{ {commentMediaInfo?.type === "webpage" ? ( thread.thumbnailUrl ? ( - {commentMediaInfo.type} { e.target.src = fallbackImgUrl @@ -631,7 +650,7 @@ const CatalogPost = ({post}) => { ) : null} {commentMediaInfo?.type === "image" ? ( - {commentMediaInfo.type} { e.target.src = fallbackImgUrl @@ -640,14 +659,14 @@ const CatalogPost = ({post}) => { ) : null} {commentMediaInfo?.type === "video" ? ( - ) : null} {commentMediaInfo?.type === "audio" ? ( -

(threadRefs.current[thread.cid] = el)}> - {thread.title ? `${thread.title}` : null} - {thread.content ? `: ${thread.content}` : null} + + {thread.title ? `${thread.title}` : null} + {thread.content ? `: ${thread.content}` : null} +
diff --git a/src/components/views/SubscriptionsCatalog.jsx b/src/components/views/SubscriptionsCatalog.jsx index 9d65490a..6648ca5b 100755 --- a/src/components/views/SubscriptionsCatalog.jsx +++ b/src/components/views/SubscriptionsCatalog.jsx @@ -78,10 +78,21 @@ const CatalogPost = ({post}) => { const postMenuCatalogRef = useRef(null); const popupRef = useRef(null); const threadRefs = useRef([]); + const textRef = useRef(null); + const imageRef = useRef(null); const [isEnoughSpaceOnRight, setIsEnoughSpaceOnRight] = useState(null); const [isEnoughSpaceOnLeft,setIsEnoughSpaceOnLeft] = useState(null); const [isCalculationDone,setIsCalculationDone] = useState(false); const [hoverTimeoutId, setHoverTimeoutId] = useState(null); + const textRect = textRef.current?.getBoundingClientRect(); + const imageRect = imageRef.current?.getBoundingClientRect(); + const isMediaShowed = (thread.link && commentMediaInfo && ( + commentMediaInfo.type === 'image' || + commentMediaInfo.type === 'video' || + (commentMediaInfo.type === 'webpage' && + commentMediaInfo.thumbnail) || + (commentMediaInfo.type === 'iframe' && + commentMediaInfo.thumbnail))) ? true : false; useLayoutEffect(() => { @@ -337,8 +348,17 @@ const CatalogPost = ({post}) => { style={{ opacity: isCalculationDone && isEnoughSpaceOnRight !== null ? 1 : 0, visibility: isCalculationDone && isEnoughSpaceOnRight !== null ? 'visible' : 'hidden', - left: isCalculationDone && isEnoughSpaceOnRight !== null && isEnoughSpaceOnRight ? '100%' : 'auto', - right: isCalculationDone && isEnoughSpaceOnRight !== null && !isEnoughSpaceOnRight ? '100%' : 'auto',}} + left: isCalculationDone && isEnoughSpaceOnRight !== null && isEnoughSpaceOnRight + ? isMediaShowed + ? `calc(50% + ${imageRect.width}px / 2 + 5px)` + : `calc(50% + ${textRect.width}px / 2 + 5px)` + : 'auto', + right: isCalculationDone && isEnoughSpaceOnRight !== null && !isEnoughSpaceOnRight + ? isMediaShowed + ? `calc(50% + ${imageRect.width}px / 2 + 5px)` + : `calc(50% + ${textRect.width}px / 2 + 5px)` + : 'auto', + }} className="thread_popup">

{ {commentMediaInfo?.type === "webpage" ? ( thread.thumbnailUrl ? ( - {commentMediaInfo.type} { e.target.src = fallbackImgUrl @@ -380,7 +400,7 @@ const CatalogPost = ({post}) => { ) : null} {commentMediaInfo?.type === "image" ? ( - {commentMediaInfo.type} { e.target.src = fallbackImgUrl @@ -389,14 +409,14 @@ const CatalogPost = ({post}) => { ) : null} {commentMediaInfo?.type === "video" ? ( - ) : null} {commentMediaInfo?.type === "audio" ? ( -

(threadRefs.current[thread.cid] = el)}> + {thread.title ? `${thread.title}` : null} {thread.content ? `: ${thread.content}` : null} +