From 2bb1f4227ee1289cab5bb680aa1d77a8e6b38638 Mon Sep 17 00:00:00 2001 From: lezi-fun <177434121+lezi-fun@users.noreply.github.com> Date: Tue, 11 Aug 2026 20:57:48 +0800 Subject: [PATCH] =?UTF-8?q?feat:=20hover=20reply=20button=20=E2=86=92=20qu?= =?UTF-8?q?ote=20+=20scroll=20to=20reply=20box?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit - Each reply shows a 回复 button on hover (always visible on touch) - Click: sets '正在回复 @user' banner, smooth-scrolls to reply box, focuses textarea; 取消 clears it - New reply icon (corner-up-left); clear replyTo after submit - Reply markdown already rendered via renderMarkdown (sanitized) --- app/globals.css | 14 ++++++++++++++ components/Icons.js | 5 +++++ components/ReplyList.js | 33 +++++++++++++++++++++++++++++++-- 3 files changed, 50 insertions(+), 2 deletions(-) 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') && ( + + )}