diff --git a/components/LinkPreviewCard.tsx b/components/LinkPreviewCard.tsx index 6dc000c..7e3ae62 100644 --- a/components/LinkPreviewCard.tsx +++ b/components/LinkPreviewCard.tsx @@ -9,7 +9,7 @@ export interface PreviewData { image?: string | null; } -function truncate(desc: string, maxLength = 200) { +function truncate(desc: string, maxLength = 260) { if (desc.length <= maxLength) return desc; const cut = desc.slice(0, maxLength); const lastSpace = cut.lastIndexOf(" "); @@ -33,6 +33,7 @@ export function LinkPreviewCard({ const [pos, setPos] = useState({ top: 0, left: 0 }); const [mounted, setMounted] = useState(false); const anchorRef = useRef(null); + const cardRef = useRef(null); const hideTimeoutRef = useRef | null>(null); const fetchTimeoutRef = useRef | null>(null); @@ -100,7 +101,14 @@ export function LinkPreviewCard({ cancelHide(); const rect = anchorRef.current?.getBoundingClientRect(); if (rect) { - setPos({ top: rect.bottom + 8, left: rect.left }); + const cardWidth = 416; + let left = rect.left; + + if (left + cardWidth > window.innerWidth) { + left = window.innerWidth - cardWidth - 16; + } + + setPos({ top: rect.bottom + 8 + window.scrollY, left }); } setHovering(true); setImgError(false); @@ -121,6 +129,11 @@ export function LinkPreviewCard({ }; const hasContent = Boolean(data?.title || data?.description || data?.image); + const showImage = data?.image && !imgError; + + // Determine if the description is short or missing + const isDescriptionShort = + !data?.description || data.description.length < 100; return ( <> @@ -131,7 +144,7 @@ export function LinkPreviewCard({ rel="noopener noreferrer" onMouseEnter={handleLinkEnter} onMouseLeave={handleLinkLeave} - className="hover:underline cursor-pointer hover:opacity-80 transition-opacity" + className="hover:underline cursor-pointer hover:opacity-80 transition-opacity inline-block" style={{ color: accent.indigoLightest }} > {children} @@ -141,68 +154,62 @@ export function LinkPreviewCard({ {hovering && hasContent && (
-
- {data?.image && !imgError && ( - setImgError(true)} - className="float-right ml-3 w-[4.5rem] h-[4.5rem] object-cover shrink-0" - style={{ border: `1px solid ${indigo(0.12)}` }} - /> - )} -