feat: 个人中心展示决策次数徽章「已拯救 X 次选择困难症」
This commit is contained in:
@@ -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,
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@@ -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>
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user