import { Post, PostMedia } from '../posts/posts.ts' import { Link } from 'react-router-dom' import { useEffect, useState } from 'react' interface PostItemProps { post: Post } export default function PostItem({ post }: PostItemProps) { const formattedDate = post.createdAt.toLocaleString('en-US', { year: 'numeric', month: 'short', day: 'numeric', hour: '2-digit', minute: '2-digit', }) const [visible, setVisible] = useState(false) useEffect(() => { const timeout = setTimeout(() => setVisible(true)) return () => { clearTimeout(timeout) } }, []) const opacity = visible ? 'opacity-100' : 'opacity-0' return (
@{post.authorName} • {formattedDate}
{post.content}
{post.media.length > 0 && (
{post.media.map((media) => ( ))}
)}
) } interface PostMediaProps { media: PostMedia } function PostMediaItem({ media }: PostMediaProps) { const url = new URL(media.url.toString()) if (location.protocol === 'https:' && url.protocol !== 'https:') { url.protocol = 'https:' } const width = media.width ?? undefined const height = media.height ?? undefined return ( todo sry :( ) }