diff --git a/src/app/api/user/route.ts b/src/app/api/user/route.ts index 60a8725..2719750 100644 --- a/src/app/api/user/route.ts +++ b/src/app/api/user/route.ts @@ -13,6 +13,8 @@ export async function GET(req: NextRequest) { return NextResponse.json(null); } + const decisionCount = await prisma.decision.count({ where: { userId } }); + return NextResponse.json({ id: user.id, username: user.username, @@ -20,6 +22,7 @@ export async function GET(req: NextRequest) { email: user.email, preferences: JSON.parse(user.preferences), createdAt: user.createdAt.toISOString(), + decisionCount, }); } diff --git a/src/app/profile/page.tsx b/src/app/profile/page.tsx index 0debe0e..62fe551 100644 --- a/src/app/profile/page.tsx +++ b/src/app/profile/page.tsx @@ -19,6 +19,7 @@ import { X, Eye, EyeOff, + Zap, } from "lucide-react"; import { getUserId, getCachedProfile, setCachedProfile, setCachedPreferences, logout } from "@/lib/userId"; import { getAvatarBg, AVATARS } from "@/lib/avatars"; @@ -33,7 +34,7 @@ function firstImage(r: Restaurant): string { export default function ProfilePage() { const router = useRouter(); const [userId, setUserId] = useState(""); - const [profile, setProfile] = useState<(UserProfile & { email?: string; preferences?: UserPreferences }) | null>(null); + const [profile, setProfile] = useState<(UserProfile & { email?: string; preferences?: UserPreferences; decisionCount?: number }) | null>(null); const [loading, setLoading] = useState(true); const [history, setHistory] = useState([]); @@ -333,6 +334,12 @@ export default function ProfilePage() { )} {usernameMsg &&

{usernameMsg}

} + {(profile.decisionCount ?? 0) > 0 && ( +

+ + 已拯救 {profile.decisionCount} 次选择困难症 +

+ )}