SeenUserList.js 1.1 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253
  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. // FIXME: Consider another way to bind values.
  26. const $seenUserList = $("#seen-user-list");
  27. if ($seenUserList.length > 0) {
  28. const seenUsers = $seenUserList.data('seen-users');
  29. if (seenUsers) {
  30. return seenUsers.split(',');
  31. }
  32. }
  33. return [];
  34. }
  35. render() {
  36. return (
  37. <p className="seen-user-list">
  38. <p className="seen-user-count">
  39. {this.state.seenUsers.length}
  40. </p>
  41. <UserList users={this.state.seenUsers} />
  42. </p>
  43. );
  44. }
  45. }