The code powering m.abunchtell.com https://m.abunchtell.com
25개 이상의 토픽을 선택하실 수 없습니다. Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
 
 
 
 

81 lines
2.4 KiB

  1. import React from 'react';
  2. import PropTypes from 'prop-types';
  3. import Base from '../../../components/modal_root';
  4. import BundleContainer from '../containers/bundle_container';
  5. import BundleModalError from './bundle_modal_error';
  6. import ModalLoading from './modal_loading';
  7. import ActionsModal from './actions_modal';
  8. import MediaModal from './media_modal';
  9. import VideoModal from './video_modal';
  10. import BoostModal from './boost_modal';
  11. import ConfirmationModal from './confirmation_modal';
  12. import FocalPointModal from './focal_point_modal';
  13. import {
  14. MuteModal,
  15. ReportModal,
  16. EmbedModal,
  17. ListEditor,
  18. ListAdder,
  19. } from '../../../features/ui/util/async-components';
  20. const MODAL_COMPONENTS = {
  21. 'MEDIA': () => Promise.resolve({ default: MediaModal }),
  22. 'VIDEO': () => Promise.resolve({ default: VideoModal }),
  23. 'BOOST': () => Promise.resolve({ default: BoostModal }),
  24. 'CONFIRM': () => Promise.resolve({ default: ConfirmationModal }),
  25. 'MUTE': MuteModal,
  26. 'REPORT': ReportModal,
  27. 'ACTIONS': () => Promise.resolve({ default: ActionsModal }),
  28. 'EMBED': EmbedModal,
  29. 'LIST_EDITOR': ListEditor,
  30. 'FOCAL_POINT': () => Promise.resolve({ default: FocalPointModal }),
  31. 'LIST_ADDER':ListAdder,
  32. };
  33. export default class ModalRoot extends React.PureComponent {
  34. static propTypes = {
  35. type: PropTypes.string,
  36. props: PropTypes.object,
  37. onClose: PropTypes.func.isRequired,
  38. };
  39. getSnapshotBeforeUpdate () {
  40. return { visible: !!this.props.type };
  41. }
  42. componentDidUpdate (prevProps, prevState, { visible }) {
  43. if (visible) {
  44. document.body.classList.add('with-modals--active');
  45. } else {
  46. document.body.classList.remove('with-modals--active');
  47. }
  48. }
  49. renderLoading = modalId => () => {
  50. return ['MEDIA', 'VIDEO', 'BOOST', 'CONFIRM', 'ACTIONS'].indexOf(modalId) === -1 ? <ModalLoading /> : null;
  51. }
  52. renderError = (props) => {
  53. const { onClose } = this.props;
  54. return <BundleModalError {...props} onClose={onClose} />;
  55. }
  56. render () {
  57. const { type, props, onClose } = this.props;
  58. const visible = !!type;
  59. return (
  60. <Base onClose={onClose}>
  61. {visible && (
  62. <BundleContainer fetchComponent={MODAL_COMPONENTS[type]} loading={this.renderLoading(type)} error={this.renderError} renderDelay={200}>
  63. {(SpecificComponent) => <SpecificComponent {...props} onClose={onClose} />}
  64. </BundleContainer>
  65. )}
  66. </Base>
  67. );
  68. }
  69. }