import React from 'react' import PropTypes from 'prop-types' import { useTranslation } from 'react-i18next' import { Dropdown as BS3Dropdown, MenuItem } from 'react-bootstrap' import { Dropdown, DropdownHeader, DropdownItem, DropdownMenu, DropdownToggle, } from '@/features/ui/components/bootstrap-5/dropdown-menu' import Icon from '../../../shared/components/icon' import { getHueForUserId } from '../../../shared/utils/colors' import ControlledDropdown from '../../../shared/components/controlled-dropdown' import OLTooltip from '@/features/ui/components/ol/ol-tooltip' import BootstrapVersionSwitcher from '@/features/ui/components/bootstrap-5/bootstrap-version-switcher' import MaterialIcon from '@/shared/components/material-icon' function OnlineUsersWidget({ onlineUsers, goToUser }) { const { t } = useTranslation() const shouldDisplayDropdown = onlineUsers.length >= 4 if (shouldDisplayDropdown) { return ( {t('connected_users')} {onlineUsers.map((user, index) => ( ))} } bs5={ {onlineUsers.map((user, index) => (
  • goToUser(user)} >
  • ))}
    } /> ) } else { return (
    {onlineUsers.map((user, index) => ( {/* OverlayTrigger won't fire unless UserIcon is wrapped in a span */} ))}
    ) } } OnlineUsersWidget.propTypes = { onlineUsers: PropTypes.arrayOf( PropTypes.shape({ user_id: PropTypes.string.isRequired, name: PropTypes.string.isRequired, }) ).isRequired, goToUser: PropTypes.func.isRequired, } function UserIcon({ user, showName, onClick }) { const backgroundColor = `hsl(${getHueForUserId(user.user_id)}, 70%, 50%)` function handleOnClick() { onClick?.(user) } const [character] = [...user.name] return ( // eslint-disable-next-line jsx-a11y/click-events-have-key-events, jsx-a11y/no-static-element-interactions {character} {showName && user.name} ) } UserIcon.propTypes = { user: PropTypes.shape({ user_id: PropTypes.string.isRequired, name: PropTypes.string.isRequired, }), showName: PropTypes.bool, onClick: PropTypes.func, } const DropDownToggleButton = React.forwardRef((props, ref) => { const { t } = useTranslation() return ( ) }) DropDownToggleButton.displayName = 'DropDownToggleButton' DropDownToggleButton.propTypes = { onlineUserCount: PropTypes.number.isRequired, onClick: PropTypes.func, } export default OnlineUsersWidget