Skip to content

Commit a1d13aa

Browse files
author
CodeJudge
committed
feat: 切换题目自动置顶 + 跳转题号输入框
1 parent 006e357 commit a1d13aa

2 files changed

Lines changed: 20 additions & 1 deletion

File tree

frontend/src/components/Navbar.tsx

Lines changed: 19 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
import { useEffect, useState } from 'react';
22
import { Link, useLocation, useNavigate } from 'react-router-dom';
3-
import { Code2, User, LogOut, ShieldCheck, Dices, Menu, X, Activity } from 'lucide-react';
3+
import { Code2, User, LogOut, ShieldCheck, Dices, Menu, X, Activity, Hash } from 'lucide-react';
44
import { useAuth } from '../context/AuthContext';
55

66
export default function Navbar() {
@@ -71,6 +71,24 @@ export default function Navbar() {
7171
<Dices className="w-4 h-4" />
7272
随机
7373
</button>
74+
<div className="relative">
75+
<Hash className="absolute left-2.5 top-1/2 -translate-y-1/2 w-3.5 h-3.5 text-dark-500 pointer-events-none" />
76+
<input
77+
type="number"
78+
min="1"
79+
placeholder="跳转"
80+
onKeyDown={(e) => {
81+
if (e.key === 'Enter') {
82+
const val = parseInt((e.target as HTMLInputElement).value);
83+
if (!isNaN(val) && val >= 1) {
84+
navigate(`/problems/${val}`);
85+
(e.target as HTMLInputElement).value = '';
86+
}
87+
}
88+
}}
89+
className="w-20 pl-7 pr-2 py-1.5 rounded-lg bg-dark-800 border border-dark-700 text-xs text-dark-200 placeholder-dark-500 focus:outline-none focus:border-primary-600/50 transition-colors [appearance:textfield] [&::-webkit-outer-spin-button]:appearance-none [&::-webkit-inner-spin-button]:appearance-none"
90+
/>
91+
</div>
7492
</div>
7593
</div>
7694

frontend/src/pages/ProblemDetail.tsx

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -85,6 +85,7 @@ export default function ProblemDetail() {
8585
try {
8686
const problem = await api.problems.get(Number(id));
8787
setProblem(problem);
88+
window.scrollTo(0, 0);
8889
} catch (err: any) {
8990
if (err.message?.includes('404')) {
9091
setNotFound(true);

0 commit comments

Comments
 (0)