/** * File: CommentComponent.tsx * Created by: AI Assistant * Date: 2025-12-05 * Purpose: Comment component with privacy controls for kreatiVortex platform * Part of: kreatiVortex - Platform Pembelajaran Tari Online */ 'use client'; import React, { useState } from 'react'; import { Button } from '@/components/ui/button'; import CommentForm from './CommentForm'; import AttachmentDisplay from './AttachmentDisplay'; import { authClient } from '@/lib/auth-client'; interface Comment { id: string; content: string; isPrivate: boolean; createdAt: string; author: { id: string; user: { name: string; image?: string; }; }; attachments: any[]; replies?: Comment[]; } interface CommentComponentProps { comment: Comment; onReply: (content: string, attachments: any[], isPrivate?: boolean) => void; onTogglePrivacy?: (commentId: string) => void; postAuthorId?: string; classEducatorId?: string; level?: number; } export default function CommentComponent({ comment, onReply, onTogglePrivacy, postAuthorId, classEducatorId, level = 0 }: CommentComponentProps) { const [showReplyForm, setShowReplyForm] = useState(false); const [isSubmitting, setIsSubmitting] = useState(false); const [user, setUser] = useState(null); // Get current user React.useEffect(() => { const getCurrentUser = async () => { try { const session = await authClient.getSession(); setUser(session?.data?.user || null); } catch (error) { console.error('Error getting user session:', error); } }; getCurrentUser(); }, []); const handleReply = async (content: string, attachments: any[]) => { setIsSubmitting(true); try { onReply(content, attachments, comment.isPrivate); // Reply inherits privacy setShowReplyForm(false); } finally { setIsSubmitting(false); } }; const handleTogglePrivacy = () => { if (onTogglePrivacy) { onTogglePrivacy(comment.id); } }; const canTogglePrivacy = user?.role === 'PENDIDIK' && user.id === classEducatorId; const isPrivateComment = comment.isPrivate; return (
0 ? 'ml-8' : ''} mb-4`}> {/* Comment Content */}
{/* Private Indicator */} {isPrivateComment && (
Private
)} {/* Author Info */}
{comment.author.user.image ? ( {comment.author.user.name} ) : ( {comment.author.user.name.charAt(0).toUpperCase()} )}

{comment.author.user.name}

{new Date(comment.createdAt).toLocaleString('id-ID')}

{/* Comment Text */}

{comment.content}

{/* Attachments */} {comment.attachments && comment.attachments.length > 0 && (
)} {/* Actions */}
{/* Privacy Toggle for Educators */} {canTogglePrivacy && ( )}
{/* Reply Form */} {showReplyForm && (
)} {/* Replies */} {comment.replies && comment.replies.length > 0 && (
{comment.replies.map((reply) => ( ))}
)}
); }