import { Anchor, Avatar, Group, Paper, Stack, Text } from '@mantine/core';
import { FeedItem, Collection } from '@/api-client';
import { Fragment } from 'react';
import Link from 'next/link';
import { getRelativeTime } from '@/lib/utils/time';
import { getRecordKey } from '@/lib/utils/atproto';
import { sanitizeText } from '@/lib/utils/text';
interface Props {
user: FeedItem['user'];
collections?: FeedItem['collections'];
createdAt: Date;
}
export default function FeedActivityStatus(props: Props) {
const MAX_DISPLAYED = 2;
const time = getRelativeTime(props.createdAt.toString());
const relativeCreatedDate = time === 'just now' ? `Now` : `${time} ago`;
const renderActivityText = () => {
const collections = props.collections ?? [];
const displayedCollections = collections.slice(0, MAX_DISPLAYED);
const remainingCount = collections.length - MAX_DISPLAYED;
return (
{sanitizeText(props.user.name)}
{' '}
{collections.length === 0 ? (
'added to library'
) : (
added to{' '}
{displayedCollections.map(
(collection: Collection, index: number) => (
{collection.name}
{index < displayedCollections.length - 1 ? ', ' : ''}
),
)}
{remainingCount > 0 &&
` and ${remainingCount} other collection${remainingCount > 1 ? 's' : ''}`}
)}
{relativeCreatedDate}
);
};
return (
{renderActivityText()}
);
}