StaffCredit.jsx 3.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143
  1. import React from 'react';
  2. import PropTypes from 'prop-types';
  3. import {
  4. Modal, ModalBody,
  5. } from 'reactstrap';
  6. import { apiv3Get } from '~/client/util/apiv3-client';
  7. import loggerFactory from '~/utils/logger';
  8. /**
  9. * Page staff credit component
  10. *
  11. * @export
  12. * @class StaffCredit
  13. * @extends {React.Component}
  14. */
  15. // eslint-disable-next-line no-unused-vars
  16. const logger = loggerFactory('growi:cli:StaffCredit');
  17. class StaffCredit extends React.Component {
  18. constructor(props) {
  19. super(props);
  20. this.state = {
  21. isShown: true,
  22. contributors: null,
  23. };
  24. this.deleteCredit = this.deleteCredit.bind(this);
  25. }
  26. // to delete the staffCredit and to inform that to Hotkeys.jsx
  27. deleteCredit() {
  28. if (this.state.isShown) {
  29. this.setState({ isShown: false });
  30. }
  31. }
  32. renderMembers(memberGroup, keyPrefix) {
  33. // construct members elements
  34. const members = memberGroup.members.map((member) => {
  35. return (
  36. <div className={memberGroup.additionalClass} key={`${keyPrefix}-${member.name}-container`}>
  37. <span className="dev-position" key={`${keyPrefix}-${member.name}-position`}>
  38. {/* position or '&nbsp;' */}
  39. { member.position || '\u00A0' }
  40. </span>
  41. <p className="dev-name" key={`${keyPrefix}-${member.name}`}>{member.name}</p>
  42. </div>
  43. );
  44. });
  45. return (
  46. <React.Fragment key={`${keyPrefix}-fragment`}>
  47. {members}
  48. </React.Fragment>
  49. );
  50. }
  51. renderContributors() {
  52. if (this.state.isShown) {
  53. const credit = this.state.contributors.map((contributor) => {
  54. // construct members elements
  55. const memberGroups = contributor.memberGroups.map((memberGroup, idx) => {
  56. return this.renderMembers(memberGroup, `${contributor.sectionName}-group${idx}`);
  57. });
  58. return (
  59. <React.Fragment key={`${contributor.sectionName}-fragment`}>
  60. <div className={`row ${contributor.additionalClass}`} key={`${contributor.sectionName}-row`}>
  61. <h2 className="col-md-12 dev-team staff-credit-mt-10rem staff-credit-mb-6rem" key={contributor.sectionName}>{contributor.sectionName}</h2>
  62. {memberGroups}
  63. </div>
  64. <div className="clearfix"></div>
  65. </React.Fragment>
  66. );
  67. });
  68. return (
  69. <div className="text-center staff-credit-content" onClick={this.deleteCredit}>
  70. <h1 className="staff-credit-mb-6rem">GROWI Contributors</h1>
  71. <div className="clearfix"></div>
  72. {credit}
  73. </div>
  74. );
  75. }
  76. return null;
  77. }
  78. async componentDidMount() {
  79. const res = await apiv3Get('/staffs');
  80. const contributors = res.data.contributors;
  81. this.setState({ contributors });
  82. setTimeout(() => {
  83. // px / sec
  84. const scrollSpeed = 200;
  85. const target = $('.credit-curtain');
  86. const scrollTargetHeight = target.children().innerHeight();
  87. const duration = scrollTargetHeight / scrollSpeed * 1000;
  88. target.animate({ scrollTop: scrollTargetHeight }, duration, 'linear');
  89. target.slimScroll({
  90. height: target.innerHeight(),
  91. // Able to scroll after automatic schooling is complete so set "bottom" to allow scrolling from the bottom.
  92. start: 'bottom',
  93. color: '#FFFFFF',
  94. });
  95. }, 10);
  96. }
  97. render() {
  98. const { onClosed } = this.props;
  99. if (this.state.contributors === null) {
  100. return <></>;
  101. }
  102. return (
  103. <Modal
  104. isOpen={this.state.isShown}
  105. onClosed={() => {
  106. if (onClosed != null) {
  107. onClosed();
  108. }
  109. }}
  110. toggle={this.deleteCredit}
  111. scrollable
  112. className="staff-credit"
  113. >
  114. <ModalBody className="credit-curtain">
  115. {this.renderContributors()}
  116. </ModalBody>
  117. </Modal>
  118. );
  119. }
  120. }
  121. StaffCredit.propTypes = {
  122. onClosed: PropTypes.func,
  123. };
  124. export default StaffCredit;