SeenUserList.js 1.1 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152
  1. import React from 'react';
  2. import UserList from './SeenUserList/UserList';
  3. export default class SeenUserList extends React.Component {
  4. constructor(props) {
  5. super(props);
  6. this.crowi = window.crowi; // FIXME
  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.crowi.apiGet('/users.list', {user_ids: seenUserIds.join(',')})
  16. .then(res => {
  17. this.setState({seenUsers: res.users});
  18. }).catch(err => {
  19. // do nothing
  20. });
  21. }
  22. }
  23. getSeenUserIds() {
  24. // FIXME: Consider another way to bind values.
  25. const $seenUserList = $("#seen-user-list");
  26. if ($seenUserList.length > 0) {
  27. const seenUsers = $seenUserList.data('seen-users');
  28. if (seenUsers) {
  29. return seenUsers.split(',');
  30. }
  31. }
  32. return [];
  33. }
  34. render() {
  35. return (
  36. <p className="seen-user-list">
  37. <p className="seen-user-count">
  38. {this.state.seenUsers.length}
  39. </p>
  40. <UserList users={this.state.seenUsers} />
  41. </p>
  42. );
  43. }
  44. }