PageListMeta.js 1.3 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667
  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. isTemplatePath(path) {
  11. if (path.match(/.*\/_{1,2}template$/)) {
  12. return true;
  13. }
  14. return false;
  15. }
  16. render() {
  17. // TODO isPortal()
  18. const page = this.props.page;
  19. // portal check
  20. let PortalLabel;
  21. if (this.isPortalPath(page.path)) {
  22. PortalLabel = <span className="label label-info">PORTAL</span>;
  23. }
  24. // template check
  25. let TemplateLabel;
  26. if (this.isPortalPath(page.path)) {
  27. TemplateLabel = <span className="label label-info">TMPLT</span>;
  28. }
  29. let CommentCount;
  30. if (page.commentCount > 0) {
  31. CommentCount = <span><i className="icon-bubble" />{page.commentCount}</span>;
  32. }
  33. let LikerCount;
  34. if (page.liker.length > 0) {
  35. LikerCount = <span><i className="icon-like" />{page.liker.length}</span>;
  36. }
  37. return (
  38. <span className="page-list-meta">
  39. {PortalLabel}
  40. {TemplateLabel}
  41. {CommentCount}
  42. {LikerCount}
  43. </span>
  44. );
  45. }
  46. }
  47. PageListMeta.propTypes = {
  48. page: PropTypes.object.isRequired,
  49. };
  50. PageListMeta.defaultProps = {
  51. page: {},
  52. };