logo

mastofe

My custom branche(s) on git.pleroma.social/pleroma/mastofe git clone https://hacktivis.me/git/mastofe.git

modal_root.js (2044B)


  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. ListEditor,
  16. } from '../../../features/ui/util/async-components';
  17. const MODAL_COMPONENTS = {
  18. 'MEDIA': () => Promise.resolve({ default: MediaModal }),
  19. 'ONBOARDING': OnboardingModal,
  20. 'VIDEO': () => Promise.resolve({ default: VideoModal }),
  21. 'BOOST': () => Promise.resolve({ default: BoostModal }),
  22. 'CONFIRM': () => Promise.resolve({ default: ConfirmationModal }),
  23. 'ACTIONS': () => Promise.resolve({ default: ActionsModal }),
  24. 'LIST_EDITOR': ListEditor,
  25. 'FOCAL_POINT': () => Promise.resolve({ default: FocalPointModal }),
  26. };
  27. export default class ModalRoot extends React.PureComponent {
  28. static propTypes = {
  29. type: PropTypes.string,
  30. props: PropTypes.object,
  31. onClose: PropTypes.func.isRequired,
  32. };
  33. renderLoading = modalId => () => {
  34. return ['MEDIA', 'VIDEO', 'BOOST', 'CONFIRM', 'ACTIONS'].indexOf(modalId) === -1 ? <ModalLoading /> : null;
  35. }
  36. renderError = (props) => {
  37. const { onClose } = this.props;
  38. return <BundleModalError {...props} onClose={onClose} />;
  39. }
  40. render () {
  41. const { type, props, onClose } = this.props;
  42. const visible = !!type;
  43. return (
  44. <Base onClose={onClose}>
  45. {visible && (
  46. <BundleContainer fetchComponent={MODAL_COMPONENTS[type]} loading={this.renderLoading(type)} error={this.renderError} renderDelay={200}>
  47. {(SpecificComponent) => <SpecificComponent {...props} onClose={onClose} />}
  48. </BundleContainer>
  49. )}
  50. </Base>
  51. );
  52. }
  53. }