Skip to content

Commit 373adf2

Browse files
author
CodeJudge
committed
feat: 仅显示未尝试筛选
1 parent 59099a9 commit 373adf2

2 files changed

Lines changed: 22 additions & 1 deletion

File tree

backend/src/controllers/problemController.js

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
const { queryAll, queryOne, run, getSafeDb, saveDb } = require('../config/db');
22

33
function listProblems(req, res) {
4-
const { type, difficulty, search, page = 1, limit = 20, sort } = req.query;
4+
const { type, difficulty, search, page = 1, limit = 20, sort, untried } = req.query;
55
let sql = 'SELECT id, title, type, difficulty, tags, accepted_count, submission_count FROM problems WHERE 1=1';
66
let countSql = 'SELECT COUNT(*) as count FROM problems WHERE 1=1';
77
let conditions = '';
@@ -18,6 +18,10 @@ function listProblems(req, res) {
1818
}
1919
conditions += ')';
2020
}
21+
if (untried === 'true' && req.user) {
22+
conditions += ' AND id NOT IN (SELECT problem_id FROM submissions WHERE user_id = ?)';
23+
params.push(req.user.id);
24+
}
2125

2226
const total = queryOne(countSql + conditions, params).count;
2327

frontend/src/pages/Problems.tsx

Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -15,6 +15,7 @@ import {
1515
Tag,
1616
Star,
1717
ArrowUpDown,
18+
HelpCircle,
1819
} from 'lucide-react';
1920
import toast from 'react-hot-toast';
2021
import api from '../services/api';
@@ -54,6 +55,7 @@ export default function Problems() {
5455
const type = searchParams.get('type') || '';
5556
const difficulty = searchParams.get('difficulty') || '';
5657
const sort = searchParams.get('sort') || '';
58+
const untried = searchParams.get('untried') === 'true';
5759
const page = parseInt(searchParams.get('page') || '1', 10);
5860

5961
const [data, setData] = useState<PaginatedResponse<Problem> | null>(null);
@@ -115,6 +117,7 @@ export default function Problems() {
115117
if (difficulty) params.difficulty = difficulty;
116118
if (search) params.search = search;
117119
if (sort) params.sort = sort;
120+
if (untried) params.untried = 'true';
118121

119122
const res = await api.problems.list(params);
120123
setData(res);
@@ -343,6 +346,20 @@ export default function Problems() {
343346
仅显示收藏
344347
</button>
345348

349+
{user && (
350+
<button
351+
onClick={() => updateParams({ untried: untried ? '' : 'true', page: '' })}
352+
className={`inline-flex items-center gap-1.5 px-3 py-1.5 rounded-md text-sm transition-colors ${
353+
untried
354+
? 'bg-violet-600 text-white'
355+
: 'bg-dark-800 text-gray-300 hover:bg-dark-700'
356+
}`}
357+
>
358+
<HelpCircle size={14} />
359+
仅显示未尝试
360+
</button>
361+
)}
362+
346363
<div className="flex items-center gap-1.5">
347364
<ArrowUpDown size={14} className="text-gray-500" />
348365
{sortOptions.map((opt) => (

0 commit comments

Comments
 (0)