PageListMeta.jsx 2.4 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485
  1. import React from 'react';
  2. import PropTypes from 'prop-types';
  3. import { templateChecker, pagePathUtils } from '@growi/core';
  4. import { FootstampIcon } from '../SearchPage/FootstampIcon';
  5. const { isTopPage } = pagePathUtils;
  6. const { checkTemplatePath } = templateChecker;
  7. export class PageListMeta extends React.Component {
  8. render() {
  9. const { page, shouldSpaceOutIcon } = this.props;
  10. // top check
  11. let topLabel;
  12. if (isTopPage(page.path)) {
  13. topLabel = <span className={`badge badge-info ${shouldSpaceOutIcon ? 'mr-3' : ''} top-label`}>TOP</span>;
  14. }
  15. // template check
  16. let templateLabel;
  17. if (checkTemplatePath(page.path)) {
  18. templateLabel = <span className={`badge badge-info ${shouldSpaceOutIcon ? 'mr-3' : ''}`}>TMPL</span>;
  19. }
  20. let commentCount;
  21. if (page.commentCount != null && page.commentCount > 0) {
  22. commentCount = <span className={`${shouldSpaceOutIcon ? 'mr-3' : ''}`}><i className="icon-bubble" />{page.commentCount}</span>;
  23. }
  24. // liker count section
  25. let likedCount;
  26. if (this.props.likerCount > 0) {
  27. likedCount = this.props.likerCount;
  28. }
  29. else if (page.liker != null && page.liker.length > 0) {
  30. likedCount = page.liker.length;
  31. }
  32. let likerCount;
  33. if (likedCount > 0) {
  34. likerCount = <span className={`${shouldSpaceOutIcon ? 'mr-3' : ''}`}><i className="fa fa-heart-o" />{likedCount}</span>;
  35. }
  36. let locked;
  37. if (page.grant !== 1) {
  38. locked = <span className={`${shouldSpaceOutIcon ? 'mr-3' : ''}`}><i className="icon-lock" /></span>;
  39. }
  40. let seenUserCount;
  41. if (page.seenUserCount > 0) {
  42. seenUserCount = (
  43. <span className={`${shouldSpaceOutIcon ? 'mr-3' : ''}`}>
  44. <i className="footstamp-icon"><FootstampIcon /></i>
  45. {page.seenUsers.length}
  46. </span>
  47. );
  48. }
  49. let bookmarkCount;
  50. if (this.props.bookmarkCount > 0) {
  51. bookmarkCount = <span className={`${shouldSpaceOutIcon ? 'mr-3' : ''}`}><i className="fa fa-bookmark-o" />{this.props.bookmarkCount}</span>;
  52. }
  53. return (
  54. <span className="page-list-meta">
  55. {topLabel}
  56. {templateLabel}
  57. {seenUserCount}
  58. {commentCount}
  59. {likerCount}
  60. {locked}
  61. {bookmarkCount}
  62. </span>
  63. );
  64. }
  65. }
  66. PageListMeta.propTypes = {
  67. page: PropTypes.object.isRequired,
  68. likerCount: PropTypes.number,
  69. bookmarkCount: PropTypes.number,
  70. shouldSpaceOutIcon: PropTypes.bool,
  71. };