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(); }, [handleActivateLine]); useKeyPressEvent((index + 1).toString(), hotkeyActivateLine); const profilePictures = useMemo(() => { const allMembers: string[] = []; const tunedMembers: string[] = []; const broadcastMembers: string[] = []; const untunedMembers: string[] = []; // ?don't add in my image as that's useless contextually? if (user.picture) allMembers.push(user.picture); line.otherUserObjects?.forEach((otherUser) => { if (otherUser.picture) { allMembers.push(otherUser.picture); if (line.tunedInMemberIds?.includes(otherUser._id.toString())) { tunedMembers.push(otherUser.picture); return; } if (line.currentBroadcastersUserIds?.includes(otherUser._id.toString())) { broadcastMembers.push(otherUser.picture); return; } untunedMembers.push(otherUser.picture); } }); return { untunedMembers, allMembers, tunedMembers, broadcastMembers, }; }, [line, user]); const renderRightActivity = useMemo(() => { if (isSelected) { return ( ); } if (profilePictures.broadcastMembers.length > 0) return ( {profilePictures.broadcastMembers.map((pictureSrc, index) => ( ))} ); if (profilePictures.tunedMembers.length > 0) return ; // if there is new activity blocks for me if (line.currentUserMember.lastVisitDate) return ; // TODO: compare last visit date to latest content block if (line.currentUserMember) return ( {moment(line.currentUserMember.lastVisitDate).fromNow(true)} ); return ( {moment(line.currentUserMember.lastVisitDate).fromNow(true)} ); }, [line, isSelected, profilePictures]); // 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 && ( 0 ? profilePictures.tunedMembers : profilePictures.allMembers } /> )} {/* channel name */}

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

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