PageListMeta.jsx 1.8 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374
  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 } = this.props;
  10. // top check
  11. let topLabel;
  12. if (isTopPage(page.path)) {
  13. topLabel = <span className="badge badge-info">TOP</span>;
  14. }
  15. // template check
  16. let templateLabel;
  17. if (checkTemplatePath(page.path)) {
  18. templateLabel = <span className="badge badge-info">TMPL</span>;
  19. }
  20. let commentCount;
  21. if (page.commentCount != null && page.commentCount > 0) {
  22. commentCount = <span><i className="icon-bubble" />{page.commentCount}</span>;
  23. }
  24. let likerCount;
  25. if (page.liker != null && page.liker.length > 0) {
  26. likerCount = <span><i className="icon-like" />{page.liker.length}</span>;
  27. }
  28. let locked;
  29. if (page.grant !== 1) {
  30. locked = <span><i className="icon-lock" /></span>;
  31. }
  32. let seenUserCount;
  33. if (page.seenUserCount > 0) {
  34. seenUserCount = (
  35. <span>
  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><i className="icon-star" />{this.props.bookmarkCount}</span>;
  44. }
  45. return (
  46. <span className="page-list-meta">
  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. };