import React, { useEffect, useRef, useState } from 'react'; import { useLocation, useNavigate } from 'react-router-dom'; import { Helmet } from 'react-helmet'; import '../css/Media.css'; const thumbnailBase = '/api/thumbnails/'; 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, thumbnail, uploader } = video; const source = `/api/clips/${filename}`; return (
{name}

{name}

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