PageListMeta.jsx 1.3 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364
  1. import React from 'react';
  2. import PropTypes from 'prop-types';
  3. import templateChecker from '@commons/util/template-checker';
  4. export default class PageListMeta extends React.Component {
  5. isPortalPath(path) {
  6. if (path.match(/.*\/$/)) {
  7. return true;
  8. }
  9. return false;
  10. }
  11. render() {
  12. // TODO isPortal()
  13. const page = this.props.page;
  14. // portal check
  15. let portalLabel;
  16. if (this.isPortalPath(page.path)) {
  17. portalLabel = <span className="label label-info">PORTAL</span>;
  18. }
  19. // template check
  20. let templateLabel;
  21. if (templateChecker(page.path)) {
  22. templateLabel = <span className="label label-info">TMPL</span>;
  23. }
  24. let commentCount;
  25. if (page.commentCount > 0) {
  26. commentCount = <span><i className="icon-bubble" />{page.commentCount}</span>;
  27. }
  28. let likerCount;
  29. if (page.liker.length > 0) {
  30. likerCount = <span><i className="icon-like" />{page.liker.length}</span>;
  31. }
  32. let locked;
  33. if (page.grant !== 1) {
  34. locked = <span><i className="icon-lock" /></span>;
  35. }
  36. return (
  37. <span className="page-list-meta">
  38. {portalLabel}
  39. {templateLabel}
  40. {commentCount}
  41. {likerCount}
  42. {locked}
  43. </span>
  44. );
  45. }
  46. }
  47. PageListMeta.propTypes = {
  48. page: PropTypes.object.isRequired,
  49. };
  50. PageListMeta.defaultProps = {
  51. };