feat: collapse replies (show last 5, 继续此消息串)
When >5 replies, show the latest 5 and a '继续此消息串 (还有N条回复)' button. Click to expand all. Discourse-style folding.
This commit is contained in:
1 parent
b18cd05455
commit
a57d29ceed
3 files changed
+39
-1
No files matched your search
+12
-1
@@ -94,6 +94,12 @@ export default function ReplyList({ postId, onRefresh }) {
|
||||
// 正在回复的目标回复对象(用于显示 @用户名)
|
||||
const replyToObj = replyTo ? replies.find((x) => x.id === replyTo) : null;
|
||||
|
||||
// 回复折叠:默认只显示最近 5 条,更多则显示"继续此消息串"
|
||||
const SHOW_N = 5;
|
||||
const [showAllReplies, setShowAllReplies] = useState(false);
|
||||
const visibleReplies = showAllReplies ? replies : replies.slice(-SHOW_N);
|
||||
const hiddenCount = replies.length - visibleReplies.length;
|
||||
|
||||
return (
|
||||
<>
|
||||
<div className="post-reply-count" style={{ marginTop: 20, fontSize: 14, color: '#64748b' }}>
|
||||
@@ -103,7 +109,7 @@ export default function ReplyList({ postId, onRefresh }) {
|
||||
{replies.length === 0 ? (
|
||||
<div style={{ color: '#94a3b8', padding: '20px 0', textAlign: 'center' }}><Icon name="message" size={16} /> 还没有回复,快来发表第一条回复吧</div>
|
||||
) : (
|
||||
replies.map((r) => {
|
||||
visibleReplies.map((r) => {
|
||||
const rTime = r.created_at ? new Date(r.created_at).toLocaleString('zh-CN') : '';
|
||||
const nestDepth = Math.min(replyDepths[r.id] || 0, 5);
|
||||
return (
|
||||
@@ -143,6 +149,11 @@ export default function ReplyList({ postId, onRefresh }) {
|
||||
);
|
||||
})
|
||||
)}
|
||||
{hiddenCount > 0 && (
|
||||
<button className="reply-show-more" onClick={() => setShowAllReplies(true)}>
|
||||
<Icon name="chevronDown" size={13} /> 继续此消息串(还有 {hiddenCount} 条回复)
|
||||
</button>
|
||||
)}
|
||||
</div>
|
||||
|
||||
<div id="replyArea" ref={replyAreaRef} style={{ marginTop: 24, borderTop: '1px solid var(--border)', paddingTop: 20 }}>
|
||||
|
||||
Reference in new issue
Block a user