The code powering m.abunchtell.com https://m.abunchtell.com
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
 
 
 
 

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