import { PostComment, PostReaction } from '../posts/posts.ts'
import { Temporal } from '@js-temporal/polyfill'
interface PostTimelineProps {
reactions: PostReaction[]
comments: PostComment[]
}
export function PostTimeline({ reactions, comments }: PostTimelineProps) {
const items = [
...reactions.map((reaction) => ({
timestamp: reaction.reactedOn,
component: (
),
})),
...comments.map((comment) => ({
timestamp: comment.postedOn,
component: (
),
})),
].toSorted((a, b) => Temporal.Instant.compare(a.timestamp, b.timestamp))
return (
{items.map((item) => item.component)}
)
}
function ReactionItem({ reaction }: { reaction: PostReaction }) {
return (
{formatItemDate(reaction.reactedOn)}
@{reaction.authorName}
clicked
{reaction.emoji}
)
}
function CommentItem({ comment }: { comment: PostComment }) {
return (
{formatItemDate(comment.postedOn)}
@{comment.author}
{comment.content}
)
}
function formatItemDate(date: Temporal.Instant) {
return date.toLocaleString('en-AU', {
year: 'numeric',
month: 'numeric',
day: 'numeric',
})
}