SeenUserList.js 1.1 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152
  1. import React from 'react';
  2. import PropTypes from 'prop-types';
  3. import UserList from './SeenUserList/UserList';
  4. export default class SeenUserList extends React.Component {
  5. constructor(props) {
  6. super(props);
  7. this.state = {
  8. seenUsers: [],
  9. };
  10. }
  11. componentDidMount() {
  12. const seenUserIds = this.getSeenUserIds();
  13. if (seenUserIds.length > 0) {
  14. // FIXME: user data cache
  15. this.setState({seenUsers: this.props.crowi.findUserByIds(seenUserIds)});
  16. }
  17. }
  18. getSeenUserIds() {
  19. // FIXME: Consider another way to bind values.
  20. const $seenUserList = $('#seen-user-list');
  21. if ($seenUserList.length > 0) {
  22. const seenUsers = $seenUserList.data('seen-users');
  23. if (seenUsers) {
  24. return seenUsers.split(',');
  25. }
  26. }
  27. return [];
  28. }
  29. render() {
  30. return (
  31. <div className="seen-user-list">
  32. <p className="seen-user-count">
  33. {this.state.seenUsers.length}
  34. </p>
  35. <UserList users={this.state.seenUsers} />
  36. </div>
  37. );
  38. }
  39. }
  40. SeenUserList.propTypes = {
  41. crowi: PropTypes.object.isRequired,
  42. };