|
1 | | -import { useState, useEffect } from 'react'; |
| 1 | +import { useState, useEffect, useRef } from 'react'; |
2 | 2 | import { useTranslation } from 'react-i18next'; |
3 | 3 | import { TagInput, UserCard, SubmissionList, SubmissionFilterPanel, LanguageSwitcher, ThemeSwitcher, ErrorMessage, DateRangePicker } from './components'; |
4 | 4 | import { useUserQuery, useTheme, useSearchHistory } from './hooks'; |
@@ -68,13 +68,34 @@ interface UserTabsProps { |
68 | 68 | } |
69 | 69 |
|
70 | 70 | function UserTabs({ users, activeIndex, onSelect }: UserTabsProps) { |
| 71 | + const containerRef = useRef<HTMLDivElement>(null); |
| 72 | + |
| 73 | + // 当 activeIndex 变化时,滚动到可见区域 |
| 74 | + useEffect(() => { |
| 75 | + if (containerRef.current) { |
| 76 | + const buttons = containerRef.current.querySelectorAll('button'); |
| 77 | + const activeButton = buttons[activeIndex]; |
| 78 | + if (activeButton) { |
| 79 | + activeButton.scrollIntoView({ |
| 80 | + behavior: 'smooth', |
| 81 | + block: 'nearest', |
| 82 | + inline: 'center', |
| 83 | + }); |
| 84 | + } |
| 85 | + } |
| 86 | + }, [activeIndex]); |
| 87 | + |
71 | 88 | return ( |
72 | | - <div className="flex gap-1 p-1 bg-gray-100 dark:bg-gray-800 rounded-xl overflow-x-auto scrollbar-hide"> |
| 89 | + <div |
| 90 | + ref={containerRef} |
| 91 | + className="flex gap-1 p-1 bg-gray-100 dark:bg-gray-800 rounded-xl overflow-x-auto scrollbar-hide" |
| 92 | + style={{ WebkitOverflowScrolling: 'touch' }} |
| 93 | + > |
73 | 94 | {users.map((user, index) => ( |
74 | 95 | <button |
75 | 96 | key={user.handle} |
76 | 97 | onClick={() => onSelect(index)} |
77 | | - className={`flex items-center gap-2 px-3 sm:px-4 py-2 rounded-lg text-sm font-medium whitespace-nowrap transition-all min-w-0 |
| 98 | + className={`flex items-center gap-2 px-3 sm:px-4 py-2 rounded-lg text-sm font-medium whitespace-nowrap transition-all flex-shrink-0 |
78 | 99 | ${activeIndex === index |
79 | 100 | ? 'bg-white dark:bg-gray-700 text-blue-600 dark:text-blue-400 shadow-sm' |
80 | 101 | : 'text-gray-600 dark:text-gray-400 hover:text-gray-900 dark:hover:text-gray-200 hover:bg-gray-200/50 dark:hover:bg-gray-700/50' |
@@ -242,7 +263,7 @@ function getRatingColor(rating: number): string { |
242 | 263 | } |
243 | 264 |
|
244 | 265 | // 应用版本号(与 package.json 保持一致) |
245 | | -const APP_VERSION = '1.0.5'; |
| 266 | +const APP_VERSION = '1.0.6'; |
246 | 267 |
|
247 | 268 | /** |
248 | 269 | * 主应用组件 |
|
0 commit comments