Files
forumlify/components/SettingsPage.js
T
lezi-fun 70a198ae32 fix: restore original Feather icons across UI
- Add components/Icons.js with SVG paths extracted verbatim from the original index.html (14 unique icons)
- Restore icons on navbar menu, sidebar, feed actions, post/reply, modals, admin tabs and settings
- Replaces emoji placeholders from the initial migration
2026-08-09 18:12:46 +08:00

52 lines
1.9 KiB
JavaScript

'use client';
// 个人设置页
import { useState } from 'react';
import { API } from '@/lib/api';
import { useApp } from './AppProvider';
import { Icon } from './Icons';
export default function SettingsPage() {
const { currentUser, setCurrentUser } = useApp();
const [username, setUsername] = useState(currentUser?.username || '');
const [bio, setBio] = useState(currentUser?.bio || '');
const handleSave = async () => {
if (!currentUser) { alert('请先登录'); return; }
if (!username.trim()) { alert('用户名不能为空'); return; }
try {
const data = await API.updateProfile(currentUser.id, username.trim(), bio.trim());
if (data.error) throw new Error(data.error);
setCurrentUser({ ...currentUser, username: username.trim(), bio: bio.trim() });
alert('保存成功!');
} catch (err) {
alert('保存失败:' + err.message);
}
};
return (
<div className="page-slide active">
<div className="page-header" style={{ maxWidth: 400, margin: '0 auto', width: '100%' }}>
<h2><Icon name="settings" size={20} /> 设置</h2>
</div>
<div style={{ maxWidth: 400, margin: '0 auto', width: '100%' }}>
<label style={{ fontWeight: 600, fontSize: 14 }}>用户名</label>
<input
type="text"
style={{ width: '100%', padding: '8px 12px', border: '1px solid #e2e8f0', borderRadius: 4, margin: '6px 0 12px' }}
value={username}
onChange={(e) => setUsername(e.target.value)}
/>
<label style={{ fontWeight: 600, fontSize: 14 }}>个人简介</label>
<textarea
rows={3}
style={{ width: '100%', padding: '8px 12px', border: '1px solid #e2e8f0', borderRadius: 4, margin: '6px 0 12px' }}
value={bio}
onChange={(e) => setBio(e.target.value)}
/>
<button className="btn-primary" onClick={handleSave}>保存设置</button>
</div>
</div>
);
}