Skip to content

Commit 07aeb6c

Browse files
author
CodeJudge
committed
feat: 个人页排名 + 刷新按钮 + 查看题目链接 + 删除账户
1 parent 76b05c2 commit 07aeb6c

4 files changed

Lines changed: 29 additions & 7 deletions

File tree

backend/src/controllers/authController.js

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -48,8 +48,14 @@ function getProfile(req, res) {
4848

4949
const totalRow = queryOne('SELECT COUNT(*) as count FROM submissions WHERE user_id = ?', [req.user.id]);
5050
const acceptedRow = queryOne("SELECT COUNT(*) as count FROM submissions WHERE user_id = ? AND status = 'accepted'", [req.user.id]);
51+
const rankRow = queryOne(`
52+
SELECT COUNT(*) + 1 as rank FROM (
53+
SELECT user_id, COUNT(*) as accepted_count FROM submissions
54+
WHERE status = 'accepted' GROUP BY user_id
55+
) t WHERE t.accepted_count > (SELECT COUNT(*) FROM submissions WHERE user_id = ? AND status = 'accepted')
56+
`, [req.user.id]);
5157

52-
res.json({ ...user, stats: { total: totalRow.count, accepted: acceptedRow.count } });
58+
res.json({ ...user, stats: { total: totalRow.count, accepted: acceptedRow.count, rank: rankRow?.rank || 0 } });
5359
}
5460

5561
function changePassword(req, res) {

frontend/src/pages/ProblemDetail.tsx

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -475,9 +475,9 @@ export default function ProblemDetail() {
475475
key={tag}
476476
className="px-2 py-0.5 bg-dark-800 text-gray-400 text-xs rounded"
477477
>
478-
{tag}
479-
</span>
480-
))}
478+
{tag}
479+
</span>
480+
))}
481481
</div>
482482
)}
483483
</div>

frontend/src/pages/Profile.tsx

Lines changed: 9 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
import { useState, useEffect } from 'react';
22
import { Link, useNavigate } from 'react-router-dom';
3-
import { User, Mail, Shield, Award, TrendingUp, Loader2, AlertTriangle, CheckCircle2, XCircle, Clock, Zap, Lock, Key, CalendarDays, Code, PieChart, Trash2 } from 'lucide-react';
3+
import { User, Mail, Shield, Award, TrendingUp, Loader2, AlertTriangle, CheckCircle2, XCircle, Clock, Zap, Lock, Key, CalendarDays, Code, PieChart, Trash2, Trophy } from 'lucide-react';
44
import { useAuth } from '../context/AuthContext';
55
import api from '../services/api';
66
import toast from 'react-hot-toast';
@@ -198,7 +198,7 @@ export default function Profile() {
198198
</div>
199199

200200
{/* Stats cards */}
201-
<div className="grid grid-cols-2 sm:grid-cols-4 gap-4">
201+
<div className="grid grid-cols-2 sm:grid-cols-5 gap-4">
202202
<div className="card p-4 text-center">
203203
<p className="text-dark-400 text-xs uppercase tracking-wide mb-1">
204204
总提交
@@ -224,6 +224,13 @@ export default function Profile() {
224224
</p>
225225
<p className="text-2xl font-bold text-purple-400">{uniqueProblems}</p>
226226
</div>
227+
<div className="card p-4 text-center">
228+
<p className="text-dark-400 text-xs uppercase tracking-wide mb-1 flex items-center justify-center gap-1">
229+
<Trophy className="w-3 h-3" />
230+
排名
231+
</p>
232+
<p className="text-2xl font-bold text-yellow-400">#{stats.rank ?? '-'}</p>
233+
</div>
227234
</div>
228235

229236
{/* Language usage */}

frontend/src/pages/Submissions.tsx

Lines changed: 10 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -125,7 +125,16 @@ export default function Submissions() {
125125

126126
return (
127127
<div>
128-
<h1 className="text-2xl font-bold text-white mb-6">提交记录</h1>
128+
<div className="flex items-center justify-between mb-6">
129+
<h1 className="text-2xl font-bold text-white">提交记录</h1>
130+
<button
131+
onClick={fetchSubmissions}
132+
className="flex items-center gap-1.5 px-3 py-1.5 rounded-lg text-sm text-dark-400 hover:text-white hover:bg-dark-800 transition-colors"
133+
>
134+
<RefreshCw size={14} className={loading ? 'animate-spin' : ''} />
135+
刷新
136+
</button>
137+
</div>
129138

130139
{/* Status filter */}
131140
<div className="flex flex-wrap gap-1 mb-6">

0 commit comments

Comments
 (0)