UserPictureList.jsx 1.7 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374
  1. import React from 'react';
  2. import PropTypes from 'prop-types';
  3. import { UncontrolledTooltip } from 'reactstrap';
  4. import { createSubscribedElement } from '../UnstatedUtils';
  5. import AppContainer from '../../services/AppContainer';
  6. import UserPicture from './UserPicture';
  7. class UserPictureList extends React.Component {
  8. constructor(props) {
  9. super(props);
  10. const userIds = this.props.userIds;
  11. const users = this.props.users.concat(
  12. // FIXME: user data cache
  13. this.props.appContainer.findUserByIds(userIds),
  14. );
  15. this.state = {
  16. users,
  17. };
  18. }
  19. renderPictAndTooltip(user) {
  20. const userId = user._id;
  21. const userPictureContainerId = `userPictureContainer-${userId}`;
  22. return (
  23. <span key={userId}>
  24. <span id={userPictureContainerId}>
  25. <UserPicture user={user} size="xs" />
  26. </span>
  27. <UncontrolledTooltip
  28. key={`tooltip-${userId}`}
  29. placement="bottom"
  30. target={userPictureContainerId}
  31. >
  32. @{user.username}<br />{user.name}
  33. </UncontrolledTooltip>
  34. </span>
  35. );
  36. }
  37. render() {
  38. return this.state.users.map((user) => {
  39. return this.renderPictAndTooltip(user);
  40. });
  41. }
  42. }
  43. /**
  44. * Wrapper component for using unstated
  45. */
  46. const UserPictureListWrapper = (props) => {
  47. return createSubscribedElement(UserPictureList, props, [AppContainer]);
  48. };
  49. UserPictureList.propTypes = {
  50. appContainer: PropTypes.instanceOf(AppContainer).isRequired,
  51. userIds: PropTypes.arrayOf(PropTypes.string),
  52. users: PropTypes.arrayOf(PropTypes.object),
  53. };
  54. UserPictureList.defaultProps = {
  55. userIds: [],
  56. users: [],
  57. };
  58. export default UserPictureListWrapper;