import React, { useEffect, useRef, useState } from 'react'; import '../css/Media.css'; const ClipEntry = ({ name, filename, uploader, thumbnail, duration, clickHandler }) => { const _uploader = `${ uploader.tag } (${ uploader.id })`; return (

Title: {name}

Uploader: {_uploader }

Filename: {filename}

Length: {duration}

Thumbnail
); }; const VideoPlayer = ({ refF, video }) => { const { filename, name } = video; const source = `/api/clips/${filename}`; return (

{name}

); }; const Media = () => { const [index, updateIndex] = useState([]); const [video, setVideo] = useState(); const ref = useRef(null); document.addEventListener('mousedown', (event) => { if(ref.current && !ref.current.contains(event.target)) setVideo(null); }); useEffect(() => { (async () => { const response = await fetch(`/api/clips`); if (response.status !== 200) return console.error('Failed to get clip index'); updateIndex(await response.json()); })(); }, []); let i = 0; return (
{index.map(entry => setVideo(entry)} key={i++} {...entry} />)} {video ? :''}
); }; export default Media;