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