Skip to content

Commit feade78

Browse files
author
CodeJudge
committed
feat: 键盘左右翻页
1 parent 6b5dee1 commit feade78

1 file changed

Lines changed: 11 additions & 0 deletions

File tree

frontend/src/pages/Problems.tsx

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -73,6 +73,17 @@ export default function Problems() {
7373
const [userStats, setUserStats] = useState<{ accepted: number } | null>(null);
7474
const totalProblems = stats?.total ?? 0;
7575

76+
// Keyboard pagination
77+
useEffect(() => {
78+
const handler = (e: KeyboardEvent) => {
79+
if (['INPUT', 'TEXTAREA'].includes((e.target as HTMLElement).tagName)) return;
80+
if (e.key === 'ArrowLeft') { updateParams({ page: String(page - 1) }); }
81+
if (e.key === 'ArrowRight') { updateParams({ page: String(page + 1) }); }
82+
};
83+
window.addEventListener('keydown', handler);
84+
return () => window.removeEventListener('keydown', handler);
85+
}, [page, totalProblems, totalPages]);
86+
7687
const fetchStats = useCallback(async () => {
7788
try {
7889
const res = await api.problems.stats();

0 commit comments

Comments
 (0)