diff --git a/apps/admin-x-activitypub/src/components/feed/FeedItem.tsx b/apps/admin-x-activitypub/src/components/feed/FeedItem.tsx index 452cd79eb0..7fbde98764 100644 --- a/apps/admin-x-activitypub/src/components/feed/FeedItem.tsx +++ b/apps/admin-x-activitypub/src/components/feed/FeedItem.tsx @@ -9,7 +9,7 @@ import getUsername from '../../utils/get-username'; import {type Activity} from '../activities/ActivityItem'; import {useLikeMutationForUser, useUnlikeMutationForUser} from '../../hooks/useActivityPubQueries'; -export function renderFeedAttachment(object: ObjectProperties, layout: string) { +function getAttachment(object: ObjectProperties) { let attachment; if (object.image) { attachment = object.image; @@ -23,6 +23,25 @@ export function renderFeedAttachment(object: ObjectProperties, layout: string) { return null; } + if (Array.isArray(attachment)) { + if (attachment.length === 0) { + return null; + } + if (attachment.length === 1) { + return attachment[0]; + } + } + + return attachment; +} + +export function renderFeedAttachment(object: ObjectProperties, layout: string) { + const attachment = getAttachment(object); + + if (!attachment) { + return null; + } + if (Array.isArray(attachment)) { const attachmentCount = attachment.length; @@ -66,14 +85,7 @@ export function renderFeedAttachment(object: ObjectProperties, layout: string) { } function renderInboxAttachment(object: ObjectProperties) { - let attachment; - if (object.image) { - attachment = object.image; - } - - if (object.type === 'Note' && !attachment) { - attachment = object.attachment; - } + const attachment = getAttachment(object); if (!attachment) { return null; @@ -81,18 +93,13 @@ function renderInboxAttachment(object: ObjectProperties) { if (Array.isArray(attachment)) { const attachmentCount = attachment.length; - // let gridClass = ''; - // if (attachmentCount === 2) { - // gridClass = 'grid-cols-2 auto-rows-[150px]'; // Two images, side by side - // } else if (attachmentCount === 3 || attachmentCount === 4) { - // gridClass = 'grid-cols-2 auto-rows-[150px]'; // Three or four images, two per row - // } + return (
- {attachment[0] &&
+
+ {attachmentCount - 1}
-
} +
); } @@ -103,7 +110,7 @@ function renderInboxAttachment(object: ObjectProperties) { case 'image/gif': return (
- {attachment && } +
); case 'video/mp4':