import React, { useRef, useEffect } from 'react' import { ListItemSelectPlayers, ListItemSelectPlaylists } from '../../components/ListItemSelects' import { toTime, toDuration } from '../utils/time' import { useMedia } from '../../library/utils/context/MediaContext' import PlaylistIcon from '../../images/playlist-icon.png' import styles from './listItem.module.scss' type ListItemType = { item: IMedia onClick: (event: React.MouseEvent, id: string) => void isOpen: boolean setCurrentPlayer: (value: string) => void setCurrentPlaylist: (value: string) => void } export const ListItem: React.FC = ({ item, onClick, isOpen, setCurrentPlayer, setCurrentPlaylist, }: ListItemType) => { const { payload_id: id, image, duration, updated_at = null, items = '', title, type: playlistType = '' } = item const itemRef = useRef(null) const { typeIs } = useMedia() const numVideos = items ? `${items} videos` : '' const info = [toTime(updated_at), numVideos, playlistType].filter((el) => el).join(' | ') useEffect(() => { if (itemRef && itemRef.current && isOpen) { itemRef.current.scrollIntoView({ behavior: 'smooth', block: 'nearest', }) } }, [isOpen]) return (
  • onClick(e, id)} >
    video
    {toDuration(duration)}

    {title}

    {info}

    Media ID: {id}

    {typeIs !== 'playlist' && ( )}
  • ) }