PageListMeta.js 1.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960
  1. import React from 'react';
  2. import PropTypes from 'prop-types';
  3. export default class PageListMeta extends React.Component {
  4. isPortalPath(path) {
  5. if (path.match(/.*\/$/)) {
  6. return true;
  7. }
  8. return false;
  9. }
  10. render() {
  11. // TODO isPortal()
  12. const page = this.props.page;
  13. const templateChecker = require('../../util/templateChecker');
  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. return (
  33. <span className="page-list-meta">
  34. {PortalLabel}
  35. {TemplateLabel}
  36. {CommentCount}
  37. {LikerCount}
  38. </span>
  39. );
  40. }
  41. }
  42. PageListMeta.propTypes = {
  43. page: PropTypes.object.isRequired,
  44. };
  45. PageListMeta.defaultProps = {
  46. page: {},
  47. };