Skip to content

Commit 006e357

Browse files
author
CodeJudge
committed
feat: 上下题导航
1 parent 9e18d24 commit 006e357

1 file changed

Lines changed: 32 additions & 8 deletions

File tree

frontend/src/pages/ProblemDetail.tsx

Lines changed: 32 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
import { useState, useEffect, useCallback } from 'react';
2-
import { useParams, Link } from 'react-router-dom';
2+
import { useParams, useNavigate, Link } from 'react-router-dom';
33
import {
44
ArrowLeft,
55
Play,
@@ -12,6 +12,8 @@ import {
1212
Lightbulb,
1313
ChevronDown,
1414
ChevronUp,
15+
ChevronLeft,
16+
ChevronRight,
1517
} from 'lucide-react';
1618
import toast from 'react-hot-toast';
1719
import api from '../services/api';
@@ -44,8 +46,13 @@ const TYPE_LABELS: Record<string, string> = {
4446

4547
export default function ProblemDetail() {
4648
const { id } = useParams<{ id: string }>();
49+
const navigate = useNavigate();
4750
const { isBookmarked, toggleBookmark } = useBookmarks();
4851

52+
const navigateToProblem = useCallback((newId: number) => {
53+
if (newId >= 1) navigate(`/problems/${newId}`);
54+
}, [navigate]);
55+
4956
const [problem, setProblem] = useState<Problem | null>(null);
5057
const [loading, setLoading] = useState(true);
5158
const [notFound, setNotFound] = useState(false);
@@ -350,13 +357,30 @@ export default function ProblemDetail() {
350357

351358
return (
352359
<div>
353-
<Link
354-
to="/problems"
355-
className="inline-flex items-center gap-1 text-gray-400 hover:text-white transition-colors mb-6"
356-
>
357-
<ArrowLeft size={18} />
358-
返回题库
359-
</Link>
360+
<div className="flex items-center gap-3 mb-6">
361+
<Link to="/problems" className="inline-flex items-center gap-1 text-gray-400 hover:text-white transition-colors">
362+
<ArrowLeft size={18} />
363+
返回题库
364+
</Link>
365+
<div className="flex items-center gap-1 ml-auto">
366+
<button
367+
onClick={() => navigateToProblem(Number(id) - 1)}
368+
disabled={!id || Number(id) <= 1}
369+
className="p-1.5 rounded-md text-dark-400 hover:text-white hover:bg-dark-800 disabled:opacity-30 disabled:cursor-not-allowed transition-colors"
370+
title="上一题"
371+
>
372+
<ChevronLeft size={18} />
373+
</button>
374+
<button
375+
onClick={() => navigateToProblem(Number(id) + 1)}
376+
disabled={!id}
377+
className="p-1.5 rounded-md text-dark-400 hover:text-white hover:bg-dark-800 transition-colors"
378+
title="下一题"
379+
>
380+
<ChevronRight size={18} />
381+
</button>
382+
</div>
383+
</div>
360384

361385
{loading ? (
362386
<div className="card p-8 animate-pulse space-y-4">

0 commit comments

Comments
 (0)