From 2a508d1b2169097517d0baedee2f812be571ad7e Mon Sep 17 00:00:00 2001
From: lezi-fun <177434121+lezi-fun@users.noreply.github.com>
Date: Mon, 10 Aug 2026 14:18:29 +0800
Subject: [PATCH] fix: post detail client error (hooks order), image viewer,
messages vs DM split
MIME-Version: 1.0
Content-Type: text/plain; charset=UTF-8
Content-Transfer-Encoding: 8bit
- 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)
---
components/Feed.js | 20 +++++++++++------
components/ImageViewer.js | 35 ++++++++++++++++++++++++++++++
components/Navbar.js | 4 ++--
components/PostDetail.js | 16 +++++++++-----
components/admin/AdminCustomCss.js | 30 +++++++++++++++++++++++--
5 files changed, 89 insertions(+), 16 deletions(-)
create mode 100644 components/ImageViewer.js
diff --git a/components/Feed.js b/components/Feed.js
index 88a3375..351e7c4 100644
--- a/components/Feed.js
+++ b/components/Feed.js
@@ -5,6 +5,7 @@ import { useEffect, useState, useCallback } from 'react';
import { API } from '@/lib/api';
import { useApp } from './AppProvider';
import { Icon } from './Icons';
+import ImageViewer from './ImageViewer';
function avatar(username) {
return 'https://ui-avatars.com/api/?name=' + encodeURIComponent(username || '匿名用户') +
@@ -15,8 +16,10 @@ export default function Feed({ onOpenModal, onReport }) {
const { currentUser, sort, setSort, openPost, openUser, navigate, refreshKey } = useApp();
const [posts, setPosts] = useState(null);
const [error, setError] = useState(null);
+ const [loading, setLoading] = useState(true);
const [page, setPage] = useState(1);
const [totalPages, setTotalPages] = useState(1);
+ const [viewerSrc, setViewerSrc] = useState(null);
const PAGE_SIZE = 20;
const load = useCallback(async (targetPage) => {
@@ -99,7 +102,9 @@ export default function Feed({ onOpenModal, onReport }) {
{(p.content || '').split('\n').map((l, i) => {l}
)}
{p.images && p.images.length > 0 && (
- {p.images.map((img, i) =>

)}
+ {p.images.map((img, i) => (
+

{ e.stopPropagation(); setViewerSrc(img); }} />
+ ))}
)}
@@ -161,9 +166,10 @@ export default function Feed({ onOpenModal, onReport }) {
style={{ padding: '6px 12px', border: '1px solid var(--border)', borderRadius: 4, background: 'var(--surface)', color: 'var(--text)', cursor: page >= totalPages ? 'not-allowed' : 'pointer', fontSize: 13, opacity: page >= totalPages ? 0.4 : 1 }}
>
»
-
-
- )}
-
- );
-}
+
+
+ )}
+ {viewerSrc && setViewerSrc(null)} />}
+
+ );
+ }
diff --git a/components/ImageViewer.js b/components/ImageViewer.js
new file mode 100644
index 0000000..2444bec
--- /dev/null
+++ b/components/ImageViewer.js
@@ -0,0 +1,35 @@
+'use client';
+
+// 图片查看器(点击帖子图片放大)
+import { useEffect } from 'react';
+
+export default function ImageViewer({ src, onClose }) {
+ useEffect(() => {
+ const onKey = (e) => { if (e.key === 'Escape') onClose(); };
+ document.addEventListener('keydown', onKey);
+ return () => document.removeEventListener('keydown', onKey);
+ }, [onClose]);
+
+ return (
+
+

e.stopPropagation()}
+ />
+
+ );
+}
diff --git a/components/Navbar.js b/components/Navbar.js
index 07e61d9..6cb5e65 100644
--- a/components/Navbar.js
+++ b/components/Navbar.js
@@ -39,8 +39,8 @@ export default function Navbar({ onOpenModal }) {
const openMessages = (e) => {
e.preventDefault();
setMenuOpen(false);
- // 打开私信列表(ChatManager 监听)
- window.dispatchEvent(new CustomEvent('forumlify-open-messages'));
+ // 消息页 = 通知列表(与原版一致),私信走导航栏 ✉️ 按钮
+ navigate('messages');
};
return (
diff --git a/components/PostDetail.js b/components/PostDetail.js
index 93265c3..e0644f4 100644
--- a/components/PostDetail.js
+++ b/components/PostDetail.js
@@ -6,6 +6,7 @@ import { API } from '@/lib/api';
import { useApp } from './AppProvider';
import ReplyList from './ReplyList';
import { Icon } from './Icons';
+import ImageViewer from './ImageViewer';
function avatar(username) {
return 'https://ui-avatars.com/api/?name=' + encodeURIComponent(username || '匿名用户') +
@@ -16,6 +17,10 @@ export default function PostDetail({ postId }) {
const { currentUser, navigate, openUser, refreshKey } = useApp();
const [post, setPost] = useState(null);
const [error, setError] = useState(null);
+ const [viewerSrc, setViewerSrc] = useState(null);
+ const [editing, setEditing] = useState(false);
+ const [editTitle, setEditTitle] = useState('');
+ const [editContent, setEditContent] = useState('');
const load = useCallback(async () => {
setError(null);
@@ -65,10 +70,6 @@ export default function PostDetail({ postId }) {
}
};
- const [editing, setEditing] = useState(false);
- const [editTitle, setEditTitle] = useState('');
- const [editContent, setEditContent] = useState('');
-
const handleEdit = () => {
setEditTitle(post.title || '');
setEditContent(post.content || '');
@@ -134,7 +135,9 @@ export default function PostDetail({ postId }) {
{post.images && post.images.length > 0 && (
- {post.images.map((img, i) =>

)}
+ {post.images.map((img, i) => (
+

setViewerSrc(img)} />
+ ))}
)}
@@ -165,6 +168,9 @@ export default function PostDetail({ postId }) {
)}
+
+ {/* 图片查看器 */}
+ {viewerSrc && setViewerSrc(null)} />}
);
}
diff --git a/components/admin/AdminCustomCss.js b/components/admin/AdminCustomCss.js
index d92ba55..22dbeb9 100644
--- a/components/admin/AdminCustomCss.js
+++ b/components/admin/AdminCustomCss.js
@@ -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() {
+
+ {/* 上传前警告确认 */}
+ {pendingFile && (
+ setPendingFile(null)}>
+
e.stopPropagation()}>
+
⚠️ 警告
+
+ 若上传的 style.css 存在问题,将导致整个论坛界面样式错乱,甚至无法正常使用。
+
+
+ 请确保 CSS 文件是完整的、经过测试的版本。如出现问题,可点击「删除自定义 CSS」恢复默认样式。
+
+
+
+
+
+
+
+ )}
>
);
}