import { FC, useEffect, useRef, useState } from "react" import { UserState } from "../../lib/types" import { secondsToTime } from "../../lib/utils" import IconPause from "../icon/IconPause" import IconPlay from "../icon/IconPlay" import classNames from "classnames" import IconOwner from "../icon/IconOwner" import InputText from "../input/InputText" import Image from "next/image" interface Props { user: UserState ownerId: string socketId: string updateName: (name: string) => void } const UserItem: FC = ({ user, ownerId, socketId, updateName }) => { const [edit, setEdit] = useState(false) const [name, _setName] = useState(user.name || "") const nameRef = useRef(name) const setName = (newName: string) => { _setName(newName) nameRef.current = newName } useEffect(() => { setName(user.name || "") }, [user.name]) return (
{ownerId == user.uid && (
)}
{ if (user.uid === socketId) { setEdit(true) } }} onMouseLeave={() => { if (user.uid === socketId) { setEdit(false) } }} > {edit ? ( ) : ( <>
{user.name}
{user.player.paused ? ( ) : ( )} {secondsToTime(user.player.progress)}
)}
) } export default UserItem