StaffCredit.jsx 4.2 KB

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