feat: Discourse-style reply-to indicator (↩ @username)

- replies table: add reply_to_username column
- POST /api/replies: accept reply_to_username param
- GET /api/replies: LEFT JOIN users to return reply_to_username
- ReplyList: submit replyTo as reply_to_username on create
- UI: each reply shows '↩ 正在回复 @username' indicator (clickable,
  scrolls to target reply)
- data-username attribute on .reply-item for scroll targeting
This commit is contained in:
lezi-fun committed 2026-08-11 21:18:18 +08:00
1 parent 7bf9e37036
commit 4d0d5edec3
5 files changed
+56 -20

No files matched your search

+13 -2
View File
@@ -51,7 +51,7 @@ export default function ReplyList({ postId, onRefresh }) {
if (!captcha || !captchaInput.trim()) { toast('请填写验证码', 'warning'); return; }
try {
// 答案由服务端 HMAC 校验
await API.createReply(postId, content.trim(), { id: captcha.id, answer: captchaInput.trim(), sig: captcha.sig });
await API.createReply(postId, content.trim(), { id: captcha.id, answer: captchaInput.trim(), sig: captcha.sig }, replyTo);
API.logEvent('create_reply').catch(() => {});
setContent('');
setCaptchaInput('');
@@ -88,7 +88,7 @@ export default function ReplyList({ postId, onRefresh }) {
replies.map((r) => {
const rTime = r.created_at ? new Date(r.created_at).toLocaleString('zh-CN') : '';
return (
<div key={r.id} className="reply-item">
<div key={r.id} className="reply-item" data-username={r.username}>
<div className="reply-header">
<img src={r.avatar_url || avatar(r.username)} className="reply-avatar" alt="" />
<span
@@ -109,6 +109,17 @@ export default function ReplyList({ postId, onRefresh }) {
)}
</div>
<div className="reply-content" dangerouslySetInnerHTML={{ __html: renderMarkdown(r.content) }} />
{r.reply_to_username && (
<div
className="reply-to-indicator"
onClick={() => {
const target = document.querySelector(`.reply-item[data-username="${r.reply_to_username}"]`);
if (target) target.scrollIntoView({ behavior: 'smooth', block: 'center' });
}}
>
<Icon name="reply" size={11} /> 正在回复 <strong>@{r.reply_to_username}</strong>
</div>
)}
</div>
);
})