SeenUserList.js 1.1 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152
  1. import React from 'react';
  2. import UserList from './UserList';
  3. import $ from 'jquery';
  4. export default class SeenUserList extends React.Component {
  5. constructor(props) {
  6. super(props);
  7. this.crowi = window.crowi; // FIXME
  8. this.state = {
  9. seenUsers: [],
  10. };
  11. }
  12. componentDidMount() {
  13. const seenUserIds = this.getSeenUserIds();
  14. if (seenUserIds.length > 0) {
  15. // FIXME: user data cache
  16. this.crowi.apiGet('/users.list', {user_ids: seenUserIds.join(',')})
  17. .then(res => {
  18. this.setState({seenUsers: res.users});
  19. }).catch(err => {
  20. // do nothing
  21. });
  22. }
  23. }
  24. getSeenUserIds() {
  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. }