diff --git a/src/components/WebPreview/index.tsx b/src/components/WebPreview/index.tsx index ecf75b9..b798dec 100644 --- a/src/components/WebPreview/index.tsx +++ b/src/components/WebPreview/index.tsx @@ -334,7 +334,7 @@ export default function WebPreview({ url, className }: { url: string; className? } as Event }, [fetchedEvent]) - // Determine which image to use for dimension detection (for event cards) + // Determine which image to use for event cards const eventMetadata = fetchedEvent ? getLongFormArticleMetadataFromEvent(fetchedEvent) : null const eventImage = eventMetadata?.image const imetaInfos = fetchedEvent ? getImetaInfosFromEvent(fetchedEvent) : [] @@ -346,51 +346,41 @@ export default function WebPreview({ url, className }: { url: string; className? } const displayImageForDetection = eventImageThumbnail || image - // Detect image aspect ratio to determine layout - MUST be called unconditionally + // Detect image aspect ratio to determine width - MUST be called unconditionally const [imageAspectRatio, setImageAspectRatio] = useState(null) - const [isImageLoading, setIsImageLoading] = useState(true) const [ogImageAspectRatio, setOgImageAspectRatio] = useState(null) - const [isOgImageLoading, setIsOgImageLoading] = useState(true) useEffect(() => { if (!displayImageForDetection) { setImageAspectRatio(null) - setIsImageLoading(false) return } - setIsImageLoading(true) const img = new window.Image() img.onload = () => { const aspectRatio = img.width / img.height setImageAspectRatio(aspectRatio) - setIsImageLoading(false) } img.onerror = () => { setImageAspectRatio(null) - setIsImageLoading(false) } img.src = displayImageForDetection }, [displayImageForDetection]) - // Detect OG image aspect ratio for OG cards + // Detect OG image aspect ratio useEffect(() => { if (!image) { setOgImageAspectRatio(null) - setIsOgImageLoading(false) return } - setIsOgImageLoading(true) const img = new window.Image() img.onload = () => { const aspectRatio = img.width / img.height setOgImageAspectRatio(aspectRatio) - setIsOgImageLoading(false) } img.onerror = () => { setOgImageAspectRatio(null) - setIsOgImageLoading(false) } img.src = image }, [image]) @@ -418,10 +408,6 @@ export default function WebPreview({ url, className }: { url: string; className? // Fallback to OG image from website if event doesn't have an image // The OG image is already converted to absolute URL by useFetchWebMetadata const displayImage = eventImageThumbnail || image - - // Determine if image is portrait (taller than wide) or landscape (wider than tall) - const isPortrait = imageAspectRatio !== null && imageAspectRatio < 1 - const isLandscape = imageAspectRatio !== null && imageAspectRatio > 1 // Extract bookstr metadata if applicable const bookMetadata = fetchedEvent ? extractBookMetadata(fetchedEvent) : null @@ -442,111 +428,16 @@ export default function WebPreview({ url, className }: { url: string; className? const isMarkdownEvent = fetchedEvent && (fetchedEvent.kind === kinds.LongFormArticle || fetchedEvent.kind === ExtendedKind.WIKI_ARTICLE_MARKDOWN) const showContentPreview = previewEvent && previewEvent.content && (isAsciidocEvent || isMarkdownEvent) - // Render landscape image on top, portrait on left - if (isLandscape && displayImage) { - return ( -
-
- -
-
-
- {fetchedEvent ? ( - <> - - {eventAuthorProfile?.avatar && ( - { - e.currentTarget.style.display = 'none' - }} - /> - )} - - {eventTypeName} - - ) : ( - - {isFetchingEventFinal ? 'Loading event...' : 'Event'} - - )} - e.stopPropagation()} - className="ml-auto" - > - - -
- {fetchedEvent && ( - <> - {/* Always show title in card header, hide it in content preview */} - {eventTitle && ( -
{eventTitle}
- )} - {isBookstrEvent && bookMetadata && ( -
- {bookMetadata.type && Type: {bookMetadata.type}} - {bookMetadata.book && Book: {formatBookName(bookMetadata.book)}} - {bookMetadata.chapter && Chapter: {bookMetadata.chapter}} - {bookMetadata.verse && Verse: {bookMetadata.verse}} - {bookMetadata.version && Version: {bookMetadata.version.toUpperCase()}} -
- )} - {eventSummary && !showContentPreview && ( -
{eventSummary}
- )} - {showContentPreview && ( -
- {isAsciidocEvent ? ( - - ) : ( - - )} -
- )} - - )} -
- e.stopPropagation()} - className="text-xs text-muted-foreground truncate block hover:underline" - > - {truncatedUrl} - -
-
- ) - } - - // Render portrait image on left (30% bigger: w-40 * 1.3 = w-52) + // Render all images on left side, crop wider ones return (
- {displayImage && (isPortrait || isImageLoading) && ( -
+ {displayImage && ( +
1 ? "w-[416px]" : "w-52" + )}> 1 + // All OG images render on left with cropping if (isSmallScreen && image) { // Small screen: always use horizontal layout with image on left return (
-
+
1 ? "w-[320px]" : "w-40" + )}>
@@ -774,55 +666,14 @@ export default function WebPreview({ url, className }: { url: string; className? ) } - // Render OG card with portrait/landscape layout - if (isOgLandscape && image) { - return ( -
-
- -
- -
- ) - } - - // Portrait or square image: render on left + // Render all OG images on left side, crop wider ones return (
- {image && (isOgPortrait || isOgImageLoading) && ( -
+ {image && ( +
1 ? "w-[416px]" : "w-52" + )}>
)} -
+
{hostname}
- {title &&
{title}
} + {title &&
{title}
} {description && ( -
+
{description}
)} + {!title && !description && ( +
No description available
+ )}