73 lines
1.6 KiB
TypeScript
73 lines
1.6 KiB
TypeScript
'use client';
|
|
|
|
import React, { useEffect, useState } from 'react';
|
|
import { Button } from '@/ui/Button';
|
|
import { FeedItem } from '@/ui/FeedItem';
|
|
import { Text } from '@/ui/Text';
|
|
import { Stack } from '@/ui/Stack';
|
|
import { TimeDisplay } from '@/lib/display-objects/TimeDisplay';
|
|
|
|
interface FeedItemData {
|
|
id: string;
|
|
type: string;
|
|
headline: string;
|
|
body?: string;
|
|
timestamp: string;
|
|
formattedTime: string;
|
|
ctaHref?: string;
|
|
ctaLabel?: string;
|
|
}
|
|
|
|
async function resolveActor() {
|
|
return null;
|
|
}
|
|
|
|
interface FeedItemCardProps {
|
|
item: FeedItemData;
|
|
}
|
|
|
|
export function FeedItemCard({ item }: FeedItemCardProps) {
|
|
const [actor, setActor] = useState<{ name: string; avatarUrl: string } | null>(null);
|
|
|
|
useEffect(() => {
|
|
let cancelled = false;
|
|
|
|
void (async () => {
|
|
const resolved = await resolveActor();
|
|
if (!cancelled) {
|
|
setActor(resolved);
|
|
}
|
|
})();
|
|
|
|
return () => {
|
|
cancelled = true;
|
|
};
|
|
}, [item]);
|
|
|
|
return (
|
|
<FeedItem
|
|
user={{
|
|
name: actor?.name || 'Unknown',
|
|
avatar: actor?.avatarUrl
|
|
}}
|
|
timestamp={TimeDisplay.timeAgo(item.timestamp)}
|
|
content={
|
|
<Stack gap={2}>
|
|
<Text weight="bold" variant="high">{item.headline}</Text>
|
|
{item.body && <Text variant="med">{item.body}</Text>}
|
|
</Stack>
|
|
}
|
|
actions={item.ctaHref && item.ctaLabel ? (
|
|
<Button
|
|
as="a"
|
|
href={item.ctaHref}
|
|
variant="secondary"
|
|
size="sm"
|
|
>
|
|
{item.ctaLabel}
|
|
</Button>
|
|
) : undefined}
|
|
/>
|
|
);
|
|
}
|