The code powering m.abunchtell.com https://m.abunchtell.com
Non puoi selezionare più di 25 argomenti Gli argomenti devono iniziare con una lettera o un numero, possono includere trattini ('-') e possono essere lunghi fino a 35 caratteri.
 
 
 
 

84 righe
2.6 KiB

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