diff --git a/src/app/explore/page.tsx b/src/app/explore/page.tsx index 59ca59e..00725a0 100644 --- a/src/app/explore/page.tsx +++ b/src/app/explore/page.tsx @@ -2,7 +2,9 @@ import { useState, useEffect } from 'react'; import Link from 'next/link'; -import { SearchIcon, TrendingIcon, UsersIcon, HeartIcon, RepeatIcon, MessageIcon } from '@/components/Icons'; +import { SearchIcon, TrendingIcon, UsersIcon } from '@/components/Icons'; +import { PostCard } from '@/components/PostCard'; +import { Post } from '@/lib/types'; interface User { id: string; @@ -14,99 +16,6 @@ interface User { isRemote?: boolean; } -interface MediaItem { - id: string; - url: string; - altText?: string | null; -} - -interface Post { - id: string; - content: string; - createdAt: string; - likesCount: number; - repostsCount: number; - repliesCount: number; - author: User; - media?: MediaItem[]; -} - - - -function PostCard({ post }: { post: Post }) { - const [liked, setLiked] = useState(false); - const [reposted, setReposted] = useState(false); - - const formatTime = (dateStr: string) => { - const date = new Date(dateStr); - const now = new Date(); - const diff = now.getTime() - date.getTime(); - const minutes = Math.floor(diff / 60000); - const hours = Math.floor(minutes / 60); - const days = Math.floor(hours / 24); - - if (minutes < 1) return 'now'; - if (minutes < 60) return `${minutes}m`; - if (hours < 24) return `${hours}h`; - if (days < 7) return `${days}d`; - return date.toLocaleDateString(); - }; - - const handleLike = async () => { - setLiked(!liked); - await fetch(`/api/posts/${post.id}/like`, { method: 'POST' }); - }; - - const handleRepost = async () => { - setReposted(!reposted); - await fetch(`/api/posts/${post.id}/repost`, { method: 'POST' }); - }; - - return ( -
-
-
- {post.author.avatarUrl ? ( - {post.author.displayName} - ) : ( - post.author.displayName?.charAt(0).toUpperCase() || post.author.handle.charAt(0).toUpperCase() - )} -
-
- - {post.author.displayName || post.author.handle} - - @{post.author.handle} ยท {formatTime(post.createdAt)} -
-
-
{post.content}
- {post.media && post.media.length > 0 && ( -
- {post.media.map((item) => ( -
- {item.altText -
- ))} -
- )} -
- - - -
-
- ); -} - function UserCard({ user }: { user: User }) { return ( @@ -193,6 +102,16 @@ export default function ExplorePage() { } }; + const handleLike = async (postId: string, currentLiked: boolean) => { + const method = currentLiked ? 'DELETE' : 'POST'; + await fetch(`/api/posts/${postId}/like`, { method }); + }; + + const handleRepost = async (postId: string, currentReposted: boolean) => { + const method = currentReposted ? 'DELETE' : 'POST'; + await fetch(`/api/posts/${postId}/repost`, { method }); + }; + return (
@@ -246,7 +165,7 @@ export default function ExplorePage() { ) : (
{trendingPosts.map((post) => ( - + ))}
) @@ -289,7 +208,7 @@ export default function ExplorePage() {

Posts

{searchResults.posts.map((post) => ( - + ))}