UserPictureList.jsx 1.1 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556
  1. import React from 'react';
  2. import PropTypes from 'prop-types';
  3. import { createSubscribedElement } from '../UnstatedUtils';
  4. import AppContainer from '../../services/AppContainer';
  5. import UserPicture from './UserPicture';
  6. class UserPictureList extends React.Component {
  7. constructor(props) {
  8. super(props);
  9. const userIds = this.props.userIds;
  10. const users = this.props.users.concat(
  11. // FIXME: user data cache
  12. this.props.appContainer.findUserByIds(userIds),
  13. );
  14. this.state = {
  15. users,
  16. };
  17. }
  18. render() {
  19. return this.state.users.map(user => (
  20. <span key={user._id}>
  21. <UserPicture user={user} size="xs" />
  22. </span>
  23. ));
  24. }
  25. }
  26. /**
  27. * Wrapper component for using unstated
  28. */
  29. const UserPictureListWrapper = (props) => {
  30. return createSubscribedElement(UserPictureList, props, [AppContainer]);
  31. };
  32. UserPictureList.propTypes = {
  33. appContainer: PropTypes.instanceOf(AppContainer).isRequired,
  34. userIds: PropTypes.arrayOf(PropTypes.string),
  35. users: PropTypes.arrayOf(PropTypes.object),
  36. };
  37. UserPictureList.defaultProps = {
  38. userIds: [],
  39. users: [],
  40. };
  41. export default UserPictureListWrapper;