import MasterLineData from '@nirvana/core/models/masterLineData.model'; import React, { useMemo, useCallback } from 'react'; import { Avatar, Tooltip } from 'antd'; import { FiActivity, FiSun, FiX } from 'react-icons/fi'; import useAuth from '../../../../providers/AuthProvider'; import LineIcon from '../../../../components/lineIcon'; import moment from 'moment'; import { useKeyPressEvent } from 'react-use'; import toast from 'react-hot-toast'; import { LineMemberState } from '@nirvana/core/models/line.model'; import useElectron from '../../../../providers/ElectronProvider'; export default React.memo(function LineRow({ index, line, handleSelectLine, isSelected, }: { index: number; // the order of this one in the list (for this view to know the shortcut to register) line: MasterLineData; handleSelectLine: (newLineId: string) => void; isSelected: boolean; }) { const { user } = useAuth(); const { desktopMode, isWindowFocused } = useElectron(); const isUserTunedIn = useMemo( () => line.tunedInMemberIds?.includes(user._id.toString()), [line.tunedInMemberIds, user], ); const isUserToggleTuned = useMemo( () => line?.currentUserMember?.state === LineMemberState.TUNED, [line], ); const handleActivateLine = useCallback(() => { handleSelectLine(line.lineDetails._id.toString()); }, [handleSelectLine, line.lineDetails, index]); const hotkeyActivateLine = useCallback(() => { // TODO: disable for higher numbers? ehh maybe hidden easter egg to select more? // if (isUserToggleTuned) handleActivateLine(); handleActivateLine(); }, [isUserToggleTuned, handleActivateLine]); useKeyPressEvent((index + 1).toString(), hotkeyActivateLine); const renderRightActivity = useMemo(() => { if (isSelected) { return ( ); } // TODO: get the profile pictures of the broadcasters if (line.currentBroadcastersUserIds?.length > 0) return ( {line.otherUserObjects?.map((otherUser, index) => ( ))} ); // if there is someone or me broadcasting here if (line.currentBroadcastersUserIds?.length > 0) return ; if (isUserTunedIn) return ; // if there is new activity blocks for me if (line.currentUserMember.lastVisitDate) return ; // if there is new activity/black dot, then show relative time as little bolder? or too much? // TODO: compare last visit date to latest audio block if (line.currentUserMember) return ( {moment(line.currentUserMember.lastVisitDate).fromNow(true)} ); return ( {moment(line.currentUserMember.lastVisitDate).fromNow(true)} ); }, [line, isSelected]); const profilePictures = useMemo(() => { const pictureSources: string[] = []; // ?don't add in my image as that's useless contextually? // if (userData?.user?.picture) pictureSources.push(userData.user.picture); line.otherUserObjects?.forEach((otherUser) => { if (otherUser.picture) pictureSources.push(otherUser.picture); }); return pictureSources; }, [line, user]); // TODO: low priority: scale the whole thing and make it pop out nad translate... // doesn't work right now because no workaround for overflow scroll for y and visible for x return (
{/* channel picture */} {profilePictures && ( )} {/* channel name */}

{line.lineDetails.name || line.otherUserObjects[0].givenName}

{isUserToggleTuned && isWindowFocused && ( {`${index + 1}`} )}
{renderRightActivity}
); });