/** * File: page.tsx * Created by: AI Assistant * Date: 2025-11-29 * Purpose: Video player page for kreatiVortex platform * Part of: kreatiVortex - Platform Pembelajaran Tari Online */ 'use client'; import { useState } from 'react'; import Link from 'next/link'; import { useParams } from 'next/navigation'; import ActionButton from '@/components/ActionButton'; import { useFetch } from '@/hooks/useFetch'; import { getYouTubeId } from '@/lib/utils'; interface VideoDetail { id: string; title: string; description: string; videoUrl: string; viewCount: number; createdAt: string; uploader: { user: { name: string; }; }; comments: Comment[]; } interface Comment { id: string; content: string; createdAt: string; author: { user: { name: string; }; }; } export default function VideoDetailPage() { const params = useParams(); const id = params?.id as string; const { data: video, loading, refetch } = useFetch(`/api/videos/${id}`); const [commentText, setCommentText] = useState(''); const [submittingComment, setSubmittingComment] = useState(false); const handleSubmitComment = async () => { if (!commentText.trim()) return; setSubmittingComment(true); try { const response = await fetch('/api/comments', { method: 'POST', headers: { 'Content-Type': 'application/json', }, body: JSON.stringify({ content: commentText, videoId: id, }), }); if (response.ok) { setCommentText(''); refetch(); // Refresh comments } else { console.error('Failed to post comment'); } } catch (error) { console.error('Error posting comment:', error); } finally { setSubmittingComment(false); } }; const youtubeId = video?.videoUrl ? getYouTubeId(video.videoUrl) : null; const embedUrl = youtubeId ? `https://www.youtube.com/embed/${youtubeId}` : video?.videoUrl; if (loading) { return
Loading...
; } if (!video) { return
Video not found
; } return (
Kembali ke Daftar Video Edit Video
{/* Video Player */}
{youtubeId ? ( ) : (
Video format not supported or invalid URL
)}
{/* Video Info */}

{video.title}

Diunggah oleh {video.uploader.user.name} {new Date(video.createdAt).toLocaleDateString()} {video.viewCount} kali ditonton
') }}>
{/* Comments Section */}

Komentar

{video.comments?.map((comment) => (
{comment.author.user.name.charAt(0)}
{comment.author.user.name} {new Date(comment.createdAt).toLocaleDateString()}

{comment.content}

))} {(!video.comments || video.comments.length === 0) && (

Belum ada komentar.

)} {/* Comment Form */}
ME
Kirim
); }