feat: 个人中心展示决策次数徽章「已拯救 X 次选择困难症」

This commit is contained in:
2026-02-26 14:54:46 +08:00
parent 7aa6c7f792
commit 05e42ffe22
2 changed files with 11 additions and 1 deletions
+3
View File
@@ -13,6 +13,8 @@ export async function GET(req: NextRequest) {
return NextResponse.json(null); return NextResponse.json(null);
} }
const decisionCount = await prisma.decision.count({ where: { userId } });
return NextResponse.json({ return NextResponse.json({
id: user.id, id: user.id,
username: user.username, username: user.username,
@@ -20,6 +22,7 @@ export async function GET(req: NextRequest) {
email: user.email, email: user.email,
preferences: JSON.parse(user.preferences), preferences: JSON.parse(user.preferences),
createdAt: user.createdAt.toISOString(), createdAt: user.createdAt.toISOString(),
decisionCount,
}); });
} }
+8 -1
View File
@@ -19,6 +19,7 @@ import {
X, X,
Eye, Eye,
EyeOff, EyeOff,
Zap,
} from "lucide-react"; } from "lucide-react";
import { getUserId, getCachedProfile, setCachedProfile, setCachedPreferences, logout } from "@/lib/userId"; import { getUserId, getCachedProfile, setCachedProfile, setCachedPreferences, logout } from "@/lib/userId";
import { getAvatarBg, AVATARS } from "@/lib/avatars"; import { getAvatarBg, AVATARS } from "@/lib/avatars";
@@ -33,7 +34,7 @@ function firstImage(r: Restaurant): string {
export default function ProfilePage() { export default function ProfilePage() {
const router = useRouter(); const router = useRouter();
const [userId, setUserId] = useState(""); 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 [loading, setLoading] = useState(true);
const [history, setHistory] = useState<DecisionRecord[]>([]); const [history, setHistory] = useState<DecisionRecord[]>([]);
@@ -333,6 +334,12 @@ export default function ProfilePage() {
</div> </div>
)} )}
{usernameMsg && <p className="mt-1 text-xs text-rose-400">{usernameMsg}</p>} {usernameMsg && <p className="mt-1 text-xs text-rose-400">{usernameMsg}</p>}
{(profile.decisionCount ?? 0) > 0 && (
<p className="mt-1 flex items-center gap-1 text-xs text-muted">
<Zap size={11} className="text-amber-400" />
{profile.decisionCount}
</p>
)}
</div> </div>
</div> </div>