PageListMeta.jsx 2.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475
  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. let likerCount;
  25. if (page.liker != null && page.liker.length > 0) {
  26. likerCount = <span className={`${shouldSpaceOutIcon ? 'mr-3' : ''}`}><i className="fa fa-heart-o" />{page.liker.length}</span>;
  27. }
  28. let locked;
  29. if (page.grant !== 1) {
  30. locked = <span className={`${shouldSpaceOutIcon ? 'mr-3' : ''}`}><i className="icon-lock" /></span>;
  31. }
  32. let seenUserCount;
  33. if (page.seenUserCount > 0) {
  34. seenUserCount = (
  35. <span className={`${shouldSpaceOutIcon ? 'mr-3' : ''}`}>
  36. <i className="footstamp-icon"><FootstampIcon /></i>
  37. {page.seenUsers.length}
  38. </span>
  39. );
  40. }
  41. let bookmarkCount;
  42. if (this.props.bookmarkCount > 0) {
  43. bookmarkCount = <span className={`${shouldSpaceOutIcon ? 'mr-3' : ''}`}><i className="fa fa-bookmark-o" />{this.props.bookmarkCount}</span>;
  44. }
  45. return (
  46. <span className="page-list-meta ml-2">
  47. {topLabel}
  48. {templateLabel}
  49. {seenUserCount}
  50. {commentCount}
  51. {likerCount}
  52. {locked}
  53. {bookmarkCount}
  54. </span>
  55. );
  56. }
  57. }
  58. PageListMeta.propTypes = {
  59. page: PropTypes.object.isRequired,
  60. bookmarkCount: PropTypes.number,
  61. shouldSpaceOutIcon: PropTypes.bool,
  62. };