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
48372aa14f
commit
89987c430c
5 files changed
+89
-16
No files matched your search
@@ -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 }) {
|
||||
</div>
|
||||
{post.images && post.images.length > 0 && (
|
||||
<div className="post-images">
|
||||
{post.images.map((img, i) => <img key={i} src={img} className="post-image" alt="" />)}
|
||||
{post.images.map((img, i) => (
|
||||
<img key={i} src={img} className="post-image" alt="" style={{ cursor: 'pointer' }} onClick={() => setViewerSrc(img)} />
|
||||
))}
|
||||
</div>
|
||||
)}
|
||||
</div>
|
||||
@@ -165,6 +168,9 @@ export default function PostDetail({ postId }) {
|
||||
</div>
|
||||
</div>
|
||||
)}
|
||||
|
||||
{/* 图片查看器 */}
|
||||
{viewerSrc && <ImageViewer src={viewerSrc} onClose={() => setViewerSrc(null)} />}
|
||||
</div>
|
||||
);
|
||||
}
|
||||
Reference in new issue
Block a user