fix: post detail client error (hooks order), image viewer, messages vs DM split
- Fix critical bug: useState declared after conditional return in PostDetail
caused 'Rendered more hooks than during previous render' client error
- Add image viewer (click post image to zoom, matching upstream openImageViewer)
- CSS upload warning confirm modal (matching upstream)
- Fix: navbar 消息 menu item now opens notifications page (messages), not DM
list — DM stays on the ✉️ nav button (matches upstream structure)
This commit is contained in:
1 parent
4ee38f6486
commit
2a508d1b21
5 files changed
+89
-16
No files matched your search
@@ -7,6 +7,7 @@ import { API } from '@/lib/api';
|
||||
export default function AdminCustomCss() {
|
||||
const [status, setStatus] = useState(null);
|
||||
const [dragOver, setDragOver] = useState(false);
|
||||
const [pendingFile, setPendingFile] = useState(null); // 待确认的 CSS 文件
|
||||
const fileInputRef = useRef(null);
|
||||
|
||||
const handleFile = async (file) => {
|
||||
@@ -19,14 +20,20 @@ export default function AdminCustomCss() {
|
||||
setStatus({ ok: false, msg: '❌ CSS 文件不能超过 1MB' });
|
||||
return;
|
||||
}
|
||||
// 上传前警告确认(与原版一致)
|
||||
setPendingFile(file);
|
||||
};
|
||||
|
||||
const doUpload = async () => {
|
||||
try {
|
||||
await API.uploadCustomCss(file);
|
||||
await API.uploadCustomCss(pendingFile);
|
||||
setStatus({ ok: true, msg: '✅ 自定义 CSS 已生效(刷新页面后应用)' });
|
||||
// 强制刷新样式
|
||||
const link = document.getElementById('custom-css-link');
|
||||
if (link) link.href = '/api/custom-css?t=' + Date.now();
|
||||
} catch (err) {
|
||||
setStatus({ ok: false, msg: '❌ ' + err.message });
|
||||
} finally {
|
||||
setPendingFile(null);
|
||||
}
|
||||
};
|
||||
|
||||
@@ -77,6 +84,25 @@ export default function AdminCustomCss() {
|
||||
<button className="btn-primary" style={{ padding: '8px 20px' }} onClick={() => fileInputRef.current?.click()}>💾 保存 CSS</button>
|
||||
<button className="btn-secondary" style={{ padding: '8px 20px', border: '1px solid var(--border)', borderRadius: 4, background: 'var(--surface)', cursor: 'pointer', color: 'var(--text)' }} onClick={handleDelete}>🗑️ 删除自定义 CSS</button>
|
||||
</div>
|
||||
|
||||
{/* 上传前警告确认 */}
|
||||
{pendingFile && (
|
||||
<div className="modal active" style={{ display: 'flex' }} onClick={() => setPendingFile(null)}>
|
||||
<div className="modal-content" style={{ maxWidth: 420 }} onClick={(e) => e.stopPropagation()}>
|
||||
<h2 style={{ marginBottom: 12 }}>⚠️ 警告</h2>
|
||||
<p style={{ fontSize: 14, color: 'var(--text-secondary)', marginBottom: 16 }}>
|
||||
若上传的 <strong>style.css</strong> 存在问题,将导致整个论坛界面样式错乱,甚至无法正常使用。
|
||||
</p>
|
||||
<p style={{ fontSize: 13, color: 'var(--text-light)', marginBottom: 20 }}>
|
||||
请确保 CSS 文件是完整的、经过测试的版本。如出现问题,可点击「删除自定义 CSS」恢复默认样式。
|
||||
</p>
|
||||
<div style={{ display: 'flex', gap: 8 }}>
|
||||
<button className="btn-primary" style={{ padding: '8px 24px' }} onClick={doUpload}>我了解,继续上传</button>
|
||||
<button className="btn-secondary" style={{ padding: '8px 24px', border: '1px solid var(--border)', borderRadius: 4, background: 'var(--surface)', cursor: 'pointer', color: 'var(--text)' }} onClick={() => setPendingFile(null)}>取消</button>
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
)}
|
||||
</>
|
||||
);
|
||||
}
|
||||
Reference in new issue
Block a user