PostItem.tsx46 lines, 1.5 KB
| 1 | import { Heart } from 'lucide-react' |
| 2 | import { Link } from 'react-router' |
| 3 | import { Avatar } from '../../components/ui/Avatar' |
| 4 | import type { Post } from '../../lib/api' |
| 5 | import { ago } from '../../lib/time' |
| 6 | import { useLike } from './posts' |
| 7 | |
| 8 | export function PostItem({ post }: { post: Post }) { |
| 9 | const like = useLike() |
| 10 | return ( |
| 11 | <article className="flex gap-3 px-4 pt-3.5 pb-2"> |
| 12 | <Avatar handle={post.handle} /> |
| 13 | <div className="min-w-0 flex-1"> |
| 14 | <p className="flex gap-2 text-sm"> |
| 15 | <Link |
| 16 | to={`/u/${post.handle}`} |
| 17 | className="truncate font-medium hover:underline" |
| 18 | > |
| 19 | @{post.handle} |
| 20 | </Link> |
| 21 | <time dateTime={post.created_at} className="text-mute"> |
| 22 | {ago(post.created_at)} |
| 23 | </time> |
| 24 | </p> |
| 25 | <p className="mt-0.5 whitespace-pre-wrap wrap-anywhere"> |
| 26 | {post.body} |
| 27 | </p> |
| 28 | <button |
| 29 | onClick={() => like.mutate(post)} |
| 30 | aria-pressed={post.liked} |
| 31 | aria-label={`Like, ${post.likes} so far`} |
| 32 | className={`-ml-2 flex items-center gap-1.5 rounded-full |
| 33 | px-2 py-1 text-sm tabular-nums hover:bg-hover |
| 34 | ${post.liked ? 'text-accent-ink' : 'text-mute'}`} |
| 35 | > |
| 36 | <Heart |
| 37 | size={16} |
| 38 | fill={post.liked ? 'currentColor' : 'none'} |
| 39 | className={post.liked ? 'motion-safe:animate-pop' : ''} |
| 40 | /> |
| 41 | {post.likes} |
| 42 | </button> |
| 43 | </div> |
| 44 | </article> |
| 45 | ) |
| 46 | } |