import clsx from 'clsx' import { Avatar } from './avatar' import { Col } from './layout/col' import { Row } from './layout/row' import { UserLink } from './user-page' import { User } from 'common/user' import { UserCircleIcon } from '@heroicons/react/solid' import { useUsers } from 'web/hooks/use-users' import { partition } from 'lodash' const isOnline = (user?: User) => user && user.lastPingTime && user.lastPingTime > Date.now() - 5 * 60 * 1000 export function OnlineUserList(props: { users: User[] }) { let { users } = props const liveUsers = useUsers().filter((user) => users.map((u) => u.id).includes(user.id) ) if (liveUsers) users = liveUsers const [onlineUsers, offlineUsers] = partition(users, (user) => isOnline(user)) return ( {onlineUsers .concat(offlineUsers) .slice(0, 15) .map((user) => ( ))} ) } export function OnlineUserAvatar(props: { user?: User; className?: string }) { const { user, className } = props return ( {user && } {isOnline(user) && (
)}
) }