feat: align with upstream — pin posts, edit marker, custom CSS, UX fixes

- Pin/unpin posts (PUT /api/posts/:id/pin, admin) with notification to author
- is_pinned/pinned_at in schema; 📌 badge on feed + detail; admin pin button
- Edited marker (已编辑) on feed + detail; edit button + modal for authors
- Custom CSS: upload/delete API + admin tab + global loader (style.css override)
- Fix: duplicate post title on detail page (remove card title, keep header)
- Fix: forum name flicker on load (localStorage cache before fetch)
- Fix: dropdown menu closes on outside click (document listener)
- Fix: document.title + <title> sync on forum rename
This commit is contained in:
lezi-fun committed 2026-08-10 12:32:06 +08:00
1 parent 7ce81969ac
commit 4ee38f6486
14 files changed
+371 -10

No files matched your search

+81 -7
View File
@@ -42,6 +42,7 @@ export default function PostDetail({ postId }) {
const time = post.created_at ? new Date(post.created_at).toLocaleString('zh-CN') : '';
const canDelete = currentUser && currentUser.id === post.user_id;
const canEdit = currentUser && currentUser.id === post.user_id;
const handleDelete = async () => {
if (!confirm('确定要删除这条帖子吗?')) return;
@@ -54,6 +55,37 @@ export default function PostDetail({ postId }) {
}
};
const handleTogglePin = async () => {
if (!confirm('确定要' + (post.is_pinned ? '取消' : '') + '置顶吗?')) return;
try {
await API.togglePinPost(postId);
load();
} catch (err) {
alert('操作失败:' + err.message);
}
};
const [editing, setEditing] = useState(false);
const [editTitle, setEditTitle] = useState('');
const [editContent, setEditContent] = useState('');
const handleEdit = () => {
setEditTitle(post.title || '');
setEditContent(post.content || '');
setEditing(true);
};
const handleSaveEdit = async () => {
if (!editContent.trim()) { alert('请填写内容'); return; }
try {
await API.updatePost(postId, editTitle.trim() || '无标题', editContent.trim());
setEditing(false);
load();
} catch (err) {
alert('编辑失败:' + err.message);
}
};
return (
<div className="page-slide active">
<div className="page-header" style={{ maxWidth: 700, margin: '0 auto', width: '100%' }}>
@@ -71,14 +103,31 @@ export default function PostDetail({ postId }) {
{post.username || '匿名用户'}
</span>
<span className="post-time">{time}</span>
{canDelete && (
<button className="btn-sm btn-danger" onClick={handleDelete}>
<Icon name="trash" size={14} /> 删除
</button>
{post.edited_at && (
<span style={{ fontSize: 12, color: 'var(--text-light)', marginLeft: 8 }}>
(已编辑 {new Date(post.edited_at).toLocaleString('zh-CN')})
</span>
)}
</div>
<div className="post-title" style={{ fontSize: 20, fontWeight: 700, margin: '8px 0 12px' }}>
{post.title || '无标题'}
{post.is_pinned && (
<span style={{ fontSize: 12, color: 'var(--primary)', marginLeft: 8 }}>📌 置顶</span>
)}
<div style={{ display: 'flex', gap: 4, marginLeft: 'auto' }}>
{currentUser && currentUser.role === 'admin' && (
<button className="btn-sm btn-secondary" style={{ padding: '4px 10px' }} onClick={handleTogglePin}>
{post.is_pinned ? '📌 取消置顶' : '📌 置顶'}
</button>
)}
{canDelete && (
<button className="btn-sm btn-secondary" style={{ padding: '4px 10px' }} onClick={handleEdit}>
✏️ 编辑
</button>
)}
{canDelete && (
<button className="btn-sm btn-danger" style={{ padding: '4px 10px' }} onClick={handleDelete}>
<Icon name="trash" size={14} /> 删除
</button>
)}
</div>
</div>
<div className="post-content" style={{ fontSize: 16, lineHeight: 1.8 }}>
{(post.content || '').split('\n').map((l, i) => <span key={i}>{l}<br /></span>)}
@@ -91,6 +140,31 @@ export default function PostDetail({ postId }) {
</div>
<ReplyList postId={postId} onRefresh={load} />
</div>
{/* 编辑帖子 modal */}
{editing && (
<div className="modal active" style={{ display: 'flex' }} onClick={(e) => { if (e.target === e.currentTarget) setEditing(false); }}>
<div className="modal-content" style={{ maxWidth: 600, position: 'relative' }}>
<span className="close" style={{ position: 'absolute', top: 12, right: 16, fontSize: 24, cursor: 'pointer', color: 'var(--text-light)' }} onClick={() => setEditing(false)}>&times;</span>
<h2 style={{ marginBottom: 16 }}>✏️ 编辑帖子</h2>
<input
type="text"
placeholder="标题"
value={editTitle}
onChange={(e) => setEditTitle(e.target.value)}
style={{ width: '100%', padding: '10px 14px', border: '1px solid var(--border)', borderRadius: 6, fontSize: 15, fontWeight: 600, marginBottom: 12, background: 'var(--bg)', color: 'var(--text)' }}
/>
<textarea
rows={6}
placeholder="说点什么..."
value={editContent}
onChange={(e) => setEditContent(e.target.value)}
style={{ width: '100%', padding: 12, border: '1px solid var(--border)', borderRadius: 6, fontSize: 15, fontFamily: 'inherit', resize: 'vertical', background: 'var(--bg)', color: 'var(--text)' }}
/>
<button className="btn-primary" style={{ padding: '10px 32px', fontSize: 15, marginTop: 8 }} onClick={handleSaveEdit}>保存</button>
</div>
</div>
)}
</div>
);
}