import { LineMemberState } from '@nirvana/core/models/line.model'; import MasterLineData from '@nirvana/core/models/masterLineData.model'; import { Avatar, Skeleton, Tooltip } from 'antd'; import React, { useCallback, useMemo, useEffect } from 'react'; import { FaPlus } from 'react-icons/fa'; import { FiActivity, FiSun } from 'react-icons/fi'; import useRealTimeRooms from '../../../../providers/RealTimeRoomProvider'; import useRooms from '../../../../providers/RoomsProvider'; import useAuth from '../../../../providers/AuthProvider'; import LineIcon from '../../../../components/lineIcon'; import moment from 'moment'; export default function SidePanel() { // using merely for loading state...better to add to realtimeroom context? const { rooms: initialRoomsFetch } = useRooms(); const { roomsMap, handleSelectLine, selectedLineId } = useRealTimeRooms(); const [toggleTunedLines, allLines] = useMemo(() => { const masterLines: MasterLineData[] = Object.values(roomsMap); const tunedLines: MasterLineData[] = []; const restLines: MasterLineData[] = []; masterLines.forEach((masterLine) => { if (masterLine.currentUserMember.state === LineMemberState.TUNED) tunedLines.push(masterLine); else restLines.push(masterLine); }); return [tunedLines, restLines]; }, [roomsMap]); return (
{/* tuned in lines block */}
{/* tuned in header + general controls */}

Tuned In

{`${toggleTunedLines?.length || 0}/3`}

{/* list of toggle tuned lines */}
{toggleTunedLines.map((masterLineData) => ( ))}
{!(allLines.length > 0) && !(toggleTunedLines.length > 0) && ( You have no lines!
Create one to connect to your team instantly.
)} {/* rest of the lines */}
{initialRoomsFetch.loading ? ( ) : ( allLines.map((masterLineData) => ( )) )}
); } const LineRow = React.memo(LineRowTest); function LineRowTest({ line, handleSelectLine, isSelected, }: { line: MasterLineData; handleSelectLine: (newLineId: string) => void; isSelected: boolean; }) { const { user } = useAuth(); const isUserTunedIn = useMemo( () => line.tunedInMemberIds?.includes(user._id.toString()), [line.tunedInMemberIds, user], ); const renderRightActivity = useMemo(() => { // 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 ; 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]); 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]); return (
handleSelectLine(line.lineDetails._id.toString())} role={'presentation'} className={`flex flex-row items-center justify-start gap-2 px-4 py-6 hover:bg-gray-200 cursor-pointer transition-all last:border-b-0 border-b border-b-gray-200 relative z-50 rounded ${ isSelected && 'bg-gray-200 scale-110 shadow-2xl translate-x-3' }`} > {/* status dot */} {profilePictures && }

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

{renderRightActivity}
); }