blob: d7893c7b9edfa3782275c0b4dd5405115d389a85 [file] [log] [blame]
Krishyaaffe8102025-06-08 00:44:46 +08001import React from 'react';
2import CommentForm from './CommentForm';
3import { GoodTwo, Comment } from '@icon-park/react';
4import './GroupDetail.css';
Krishyadbfadaa2025-06-09 20:33:15 +08005import AuthButton from '../../components/AuthButton';
Krishyaaffe8102025-06-08 00:44:46 +08006
7const GroupPosts = ({
8 posts,
9 members,
10 userId,
11 toggleLike,
12 handleSubmitComment,
13 showCommentForm,
14 setShowCommentForm,
15 isMember,
16 onShowCreatePost,
17 loginHint
18}) => {
19 return (
20 <section className="group-section">
21 <h2>讨论帖子</h2>
22
23 <div className="post-list-header">
24 {userId && isMember && (
Krishyadbfadaa2025-06-09 20:33:15 +080025 <AuthButton
26 roles={[ "chocolate", "ice-cream"]}
Krishyaaffe8102025-06-08 00:44:46 +080027 className="create-post-btn"
28 onClick={onShowCreatePost}
29 >
30 + 发布帖子
Krishyadbfadaa2025-06-09 20:33:15 +080031 </AuthButton>
Krishyaaffe8102025-06-08 00:44:46 +080032 )}
33 {(!userId || !isMember) && <p className="login-hint">{loginHint}</p>}
34 </div>
35
36 <div className="post-list">
37 {posts.length > 0 ? (
38 posts.map(post => (
39 <div key={post.group_post_id} className="post-card">
40 <div className="post-header">
41 <h3 className="post-title">{post.title}</h3>
42 <div className="post-meta">
43 <span className="post-author">
44 <img
45 src={members.find(m => m.user_id === post.user_id)?.avatar_url || 'https://picsum.photos/50/50'}
46 alt={post.username}
47 className="author-avatar"
48 />
49 {post.username}
50 </span>
51 <span className="post-time">{new Date(post.time).toLocaleString()}</span>
52 </div>
53 </div>
54
55 <div className="post-content">
56 <p>{post.content}</p>
57 </div>
58
59 <div className="post-actions">
60 <span className="like-button" onClick={() => userId ? toggleLike(post.group_post_id) : alert('请先登录')}>
61 <GoodTwo
62 theme="outline"
63 size="30"
64 fill={post.userLiked ? '#ff4d4f' : '#8c8c8c'}
65 style={{ verticalAlign: 'middle', marginRight: '4px' }}
66 />
67 <span className="like-count">{post.likes || 0}</span>
68 </span>
69
70 <button className="icon-btn" onClick={() => setShowCommentForm(post.group_post_id)}>
71 <Comment theme="outline" size="30" fill="#8c8c8c"/>
72 <span>评论</span>
73 </button>
74 </div>
75
76 {/* 评论表单 */}
77 {showCommentForm === post.group_post_id && (
78 <CommentForm
79 onSubmit={(content) => handleSubmitComment(post.group_post_id, content)}
80 onCancel={() => setShowCommentForm(null)}
81 />
82 )}
83
84 {/* 显示评论 */}
85 {post.comments && post.comments.length > 0 && (
86 <div className="comments-section">
87 <h4 className="comments-title">评论 ({post.comments.length})</h4>
88 {post.comments.map(comment => (
89 <div key={comment.id || comment.comment_id} className="comment-item">
90 <div className="comment-header">
91 <img
92 src={members.find(m => m.user_id === comment.userId)?.avatar_url || 'https://picsum.photos/40/40'}
93 alt={comment.username || '用户'}
94 className="comment-avatar"
95 />
96 <span className="comment-author">{comment.username || '用户'}</span>
97 <span className="comment-time">{new Date(comment.time).toLocaleString()}</span>
98 </div>
99 <div className="comment-content">{comment.content}</div>
100 </div>
101 ))}
102 </div>
103 )}
104 </div>
105 ))
106 ) : (
107 <p className="empty-message">暂无帖子</p>
108 )}
109 </div>
110 </section>
111 );
112};
113
114export default GroupPosts;