- 新增 Follow 表和 User.bio 字段 (Prisma schema)
- 创建 follow 模块 (action-service-repository)
- 新增 FollowButton/FollowStats/UserList 组件
- 用户页面显示 bio、粉丝/关注数、关注按钮
- 新增 /users/[username]/followers 和 following 页面
- 添加 en-US/zh-CN i18n 翻译
⚠️ 需要运行: prisma migrate dev --name add_follow_and_bio
55 lines
1.4 KiB
TypeScript
55 lines
1.4 KiB
TypeScript
"use client";
|
|
|
|
import { useState } from "react";
|
|
import { FollowButton } from "./FollowButton";
|
|
|
|
interface FollowStatsProps {
|
|
userId: string;
|
|
initialFollowersCount: number;
|
|
initialFollowingCount: number;
|
|
initialIsFollowing: boolean;
|
|
currentUserId?: string;
|
|
isOwnProfile: boolean;
|
|
username: string;
|
|
}
|
|
|
|
export function FollowStats({
|
|
userId,
|
|
initialFollowersCount,
|
|
initialFollowingCount,
|
|
initialIsFollowing,
|
|
currentUserId,
|
|
isOwnProfile,
|
|
username,
|
|
}: FollowStatsProps) {
|
|
const [followersCount, setFollowersCount] = useState(initialFollowersCount);
|
|
|
|
const handleFollowChange = (isFollowing: boolean, count: number) => {
|
|
setFollowersCount(count);
|
|
};
|
|
|
|
return (
|
|
<div className="flex items-center gap-4">
|
|
<a
|
|
href={`/users/${username}/followers`}
|
|
className="text-sm text-gray-600 hover:text-primary-500 transition-colors"
|
|
>
|
|
<span className="font-semibold text-gray-900">{followersCount}</span> followers
|
|
</a>
|
|
<a
|
|
href={`/users/${username}/following`}
|
|
className="text-sm text-gray-600 hover:text-primary-500 transition-colors"
|
|
>
|
|
<span className="font-semibold text-gray-900">{initialFollowingCount}</span> following
|
|
</a>
|
|
{currentUserId && !isOwnProfile && (
|
|
<FollowButton
|
|
targetUserId={userId}
|
|
initialIsFollowing={initialIsFollowing}
|
|
onFollowChange={handleFollowChange}
|
|
/>
|
|
)}
|
|
</div>
|
|
);
|
|
}
|