diff --git a/src/app/[handle]/page.tsx b/src/app/[handle]/page.tsx index 63934e8..3676a50 100644 --- a/src/app/[handle]/page.tsx +++ b/src/app/[handle]/page.tsx @@ -154,14 +154,12 @@ export default function ProfilePage() { const method = isFollowing ? 'DELETE' : 'POST'; const res = await fetch(`/api/users/${handle}/follow`, { method }); - if (res.ok) { + if (res.ok && user) { setIsFollowing(!isFollowing); - if (user) { - setUser({ - ...user, - followersCount: isFollowing ? user.followersCount - 1 : user.followersCount + 1, - }); - } + setUser({ + ...user, + followersCount: isFollowing ? (user.followersCount || 0) - 1 : (user.followersCount || 0) + 1, + }); } }; @@ -352,7 +350,7 @@ export default function ProfilePage() { fontSize: '14px', }}> - Joined {formatDate(user.createdAt)} + Joined {formatDate(user.createdAt || new Date().toISOString())}
diff --git a/src/app/api/posts/[id]/repost/route.ts b/src/app/api/posts/[id]/repost/route.ts index efa6e7f..3486b9c 100644 --- a/src/app/api/posts/[id]/repost/route.ts +++ b/src/app/api/posts/[id]/repost/route.ts @@ -1,7 +1,7 @@ import { NextResponse } from 'next/server'; import { db, posts, users, notifications } from '@/db'; import { requireAuth } from '@/lib/auth'; -import { eq } from 'drizzle-orm'; +import { eq, and } from 'drizzle-orm'; type RouteContext = { params: Promise<{ id: string }> }; diff --git a/src/app/api/posts/[id]/route.ts b/src/app/api/posts/[id]/route.ts index b213ae0..b3ca352 100644 --- a/src/app/api/posts/[id]/route.ts +++ b/src/app/api/posts/[id]/route.ts @@ -70,13 +70,13 @@ export async function GET( ...post, isLiked: likedPostIds.has(post.id), isReposted: repostedPostIds.has(post.id), - }; + } as any; replyPosts = replies.map(r => ({ ...r, isLiked: likedPostIds.has(r.id), isReposted: repostedPostIds.has(r.id), - })); + })) as any; } } catch { // Not authenticated or other error, skip flags diff --git a/src/app/api/posts/route.ts b/src/app/api/posts/route.ts index 57564e8..16263e0 100644 --- a/src/app/api/posts/route.ts +++ b/src/app/api/posts/route.ts @@ -328,7 +328,7 @@ export async function GET(request: Request) { ...p, isLiked: likedPostIds.has(p.id), isReposted: repostedPostIds.has(p.id), - })); + })) as any; } } } catch (error) { diff --git a/src/components/PostCard.tsx b/src/components/PostCard.tsx index 798a3fa..1aec5be 100644 --- a/src/components/PostCard.tsx +++ b/src/components/PostCard.tsx @@ -1,14 +1,14 @@ 'use client'; -import { useState } from 'react'; +import { useState, useEffect } from 'react'; import Link from 'next/link'; import { HeartIcon, RepeatIcon, MessageIcon, FlagIcon } from '@/components/Icons'; import { Post } from '@/lib/types'; interface PostCardProps { post: Post; - onLike?: (id: string) => void; - onRepost?: (id: string) => void; + onLike?: (id: string, currentLiked: boolean) => void; + onRepost?: (id: string, currentReposted: boolean) => void; onComment?: (post: Post) => void; isDetail?: boolean; }