diff --git a/app/globals.css b/app/globals.css index 33a04cf..03aa06a 100644 --- a/app/globals.css +++ b/app/globals.css @@ -3073,3 +3073,17 @@ a.btn-secondary { white-space: nowrap; } } + +/* ===== 回复操作按钮:悬停显示 ===== */ +.reply-btn { + opacity: 0; + transition: opacity 0.15s ease; +} +.reply-item:hover .reply-btn, +.reply-item:focus-within .reply-btn { + opacity: 1; +} +/* 触屏设备(无 hover):始终显示 */ +@media (hover: none) { + .reply-btn { opacity: 1; } +} diff --git a/components/Icons.js b/components/Icons.js index 6fdaf47..c3950a1 100644 --- a/components/Icons.js +++ b/components/Icons.js @@ -17,6 +17,11 @@ const PATHS = { ), + reply: ( + <> + + + ), settings: ( <> diff --git a/components/ReplyList.js b/components/ReplyList.js index 1954b13..682e47b 100644 --- a/components/ReplyList.js +++ b/components/ReplyList.js @@ -1,7 +1,7 @@ 'use client'; // 回复列表 + 发表回复表单 -import { useEffect, useState, useCallback } from 'react'; +import { useEffect, useState, useCallback, useRef } from 'react'; import { API } from '@/lib/api'; import { useApp } from './AppProvider'; import { Icon } from './Icons'; @@ -21,6 +21,19 @@ export default function ReplyList({ postId, onRefresh }) { const [content, setContent] = useState(''); const [captcha, setCaptcha] = useState(null); const [captchaInput, setCaptchaInput] = useState(''); + // 正在回复的用户(hover 回复按钮 → 回填到回复框) + const [replyTo, setReplyTo] = useState(null); + const replyAreaRef = useRef(null); + const replyInputRef = useRef(null); + + // 点击"回复":记录目标用户,滚动到回复框并聚焦 + const startReply = (username) => { + setReplyTo(username); + setTimeout(() => { + replyAreaRef.current?.scrollIntoView({ behavior: 'smooth', block: 'center' }); + replyInputRef.current?.focus(); + }, 120); + }; const load = useCallback(async () => { try { @@ -42,6 +55,7 @@ export default function ReplyList({ postId, onRefresh }) { API.logEvent('create_reply').catch(() => {}); setContent(''); setCaptchaInput(''); + setReplyTo(null); API.getCaptcha().then((c) => setCaptcha(c)).catch(() => {}); load(); onRefresh(); @@ -85,6 +99,9 @@ export default function ReplyList({ postId, onRefresh }) { {r.username || '匿名用户'} {rTime} + {currentUser && (currentUser.id === r.user_id || currentUser.role === 'admin') && ( + + )}