Files
forumlify/components/ImageViewer.js
lezi-fun 2a508d1b21 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)
2026-08-10 14:18:29 +08:00

36 lines
1.0 KiB
JavaScript

'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 (
<div
className="modal active"
style={{
position: 'fixed', inset: 0, background: 'rgba(0,0,0,0.85)', zIndex: 9999,
display: 'flex', alignItems: 'center', justifyContent: 'center',
cursor: 'pointer', animation: 'fadeIn 0.2s ease-out',
}}
onClick={onClose}
>
<img
src={src}
alt=""
style={{
maxWidth: '90vw', maxHeight: '90vh', objectFit: 'contain',
borderRadius: 8, boxShadow: '0 8px 32px rgba(0,0,0,0.5)',
cursor: 'default', userSelect: 'none',
}}
onClick={(e) => e.stopPropagation()}
/>
</div>
);
}