feat: public user profile API + settings swipe navigation
- GET /api/users/profile/:username public endpoint (no auth) for user pages, matching upstream main; UserProfile uses it (was admin /users search) - Settings page: vertical scroll-snap panels (profile/security/recovery), swipe up/down to switch smoothly; sidebar nav scrolls to panel and active highlight follows scroll position
This commit is contained in:
1 parent
fe71b03d2e
commit
0b86c54867
4 files changed
+78
-11
No files matched your search
@@ -1,7 +1,9 @@
|
||||
'use client';
|
||||
|
||||
// 个人设置页:侧边栏布局(个人资料 / 安全设置 / 恢复码)
|
||||
import { useState } from 'react';
|
||||
// 个人设置页:侧边栏布局 + 上下滑动平滑切换
|
||||
// - 三个面板纵向排列在滚动容器里,scroll-snap 每次滑动对齐一个面板
|
||||
// - 点侧边栏导航 → 平滑滚动到对应面板;滚动结束 → 自动更新导航高亮
|
||||
import { useState, useRef, useCallback } from 'react';
|
||||
import { Icon } from './Icons';
|
||||
import SettingsProfile from './SettingsProfile';
|
||||
import AccountSecurity from './AccountSecurity';
|
||||
@@ -15,6 +17,31 @@ const NAV = [
|
||||
|
||||
export default function SettingsPage() {
|
||||
const [tab, setTab] = useState('profile');
|
||||
const scrollRef = useRef(null);
|
||||
const scrollTicking = useRef(false);
|
||||
|
||||
// 滚动结束(或对齐后)更新高亮
|
||||
const handleScroll = useCallback(() => {
|
||||
const el = scrollRef.current;
|
||||
if (!el || scrollTicking.current) return;
|
||||
scrollTicking.current = true;
|
||||
requestAnimationFrame(() => {
|
||||
scrollTicking.current = false;
|
||||
const idx = Math.round(el.scrollTop / el.clientHeight);
|
||||
const key = NAV[Math.min(Math.max(idx, 0), NAV.length - 1)]?.key;
|
||||
if (key) setTab(key);
|
||||
});
|
||||
}, []);
|
||||
|
||||
// 点击导航 → 平滑滚动到对应面板
|
||||
const goTo = (key, e) => {
|
||||
if (e) e.preventDefault();
|
||||
setTab(key);
|
||||
const el = scrollRef.current;
|
||||
if (!el) return;
|
||||
const idx = NAV.findIndex((n) => n.key === key);
|
||||
el.scrollTo({ top: idx * el.clientHeight, behavior: 'smooth' });
|
||||
};
|
||||
|
||||
return (
|
||||
<div className="page-slide active">
|
||||
@@ -30,7 +57,7 @@ export default function SettingsPage() {
|
||||
href="#"
|
||||
className={'settings-nav-item' + (tab === n.key ? ' active' : '')}
|
||||
data-settings-tab={n.key}
|
||||
onClick={(e) => { e.preventDefault(); setTab(n.key); }}
|
||||
onClick={(e) => goTo(n.key, e)}
|
||||
>
|
||||
<span className="nav-icon"><Icon name={n.icon} size={18} /></span>
|
||||
{n.label}
|
||||
@@ -38,10 +65,29 @@ export default function SettingsPage() {
|
||||
))}
|
||||
</nav>
|
||||
</aside>
|
||||
<main className="settings-content" id="settingsContent">
|
||||
{tab === 'profile' && <SettingsProfile />}
|
||||
{tab === 'security' && <AccountSecurity />}
|
||||
{tab === 'recovery' && <RecoveryCodes />}
|
||||
<main className="settings-content" id="settingsContent" style={{ overflow: 'hidden', padding: 0 }}>
|
||||
<div
|
||||
ref={scrollRef}
|
||||
onScroll={handleScroll}
|
||||
style={{
|
||||
height: '70vh',
|
||||
overflowY: 'auto',
|
||||
scrollSnapType: 'y mandatory',
|
||||
scrollBehavior: 'smooth',
|
||||
scrollbarWidth: 'none',
|
||||
msOverflowStyle: 'none',
|
||||
}}
|
||||
>
|
||||
<div style={{ scrollSnapAlign: 'start', minHeight: '100%', padding: '20px 24px' }} data-panel="profile">
|
||||
<SettingsProfile />
|
||||
</div>
|
||||
<div style={{ scrollSnapAlign: 'start', minHeight: '100%', padding: '20px 24px', borderTop: '1px solid var(--glass-border)' }} data-panel="security">
|
||||
<AccountSecurity />
|
||||
</div>
|
||||
<div style={{ scrollSnapAlign: 'start', minHeight: '100%', padding: '20px 24px', borderTop: '1px solid var(--glass-border)' }} data-panel="recovery">
|
||||
<RecoveryCodes />
|
||||
</div>
|
||||
</div>
|
||||
</main>
|
||||
</div>
|
||||
</div>
|
||||
|
||||
@@ -22,10 +22,9 @@ export default function UserProfile({ username }) {
|
||||
const load = useCallback(async () => {
|
||||
setError(null);
|
||||
try {
|
||||
const users = await API.getUsersByUsername(username);
|
||||
const u = users && users.length > 0 ? users[0] : null;
|
||||
if (!u) {
|
||||
setError('用户不存在');
|
||||
const u = await API.getUserProfile(username);
|
||||
if (u.error || !u.id) {
|
||||
setError(u.error || '用户不存在');
|
||||
return;
|
||||
}
|
||||
setUser(u);
|
||||
|
||||
Reference in new issue
Block a user