Improve modal flow and back button handling (#16499)
* Refactor shouldUpdateScroll passing So far, shouldUpdateScroll has been manually passed down from the very top of the React component hierarchy even though it is a static function common to all ScrollContainer instances, so replaced that with a custom class extending ScrollContainer. * Generalize “press back to close modal” to any modal and to public pages * Fix boost confirmation modal closing media modal
This commit is contained in:
		@@ -4,7 +4,6 @@ import PropTypes from 'prop-types';
 | 
			
		||||
import Audio from 'mastodon/features/audio';
 | 
			
		||||
import { connect } from 'react-redux';
 | 
			
		||||
import ImmutablePureComponent from 'react-immutable-pure-component';
 | 
			
		||||
import { previewState } from './video_modal';
 | 
			
		||||
import Footer from 'mastodon/features/picture_in_picture/components/footer';
 | 
			
		||||
 | 
			
		||||
const mapStateToProps = (state, { statusId }) => ({
 | 
			
		||||
@@ -25,32 +24,6 @@ class AudioModal extends ImmutablePureComponent {
 | 
			
		||||
    onChangeBackgroundColor: PropTypes.func.isRequired,
 | 
			
		||||
  };
 | 
			
		||||
 | 
			
		||||
  static contextTypes = {
 | 
			
		||||
    router: PropTypes.object,
 | 
			
		||||
  };
 | 
			
		||||
 | 
			
		||||
  componentDidMount () {
 | 
			
		||||
    if (this.context.router) {
 | 
			
		||||
      const history = this.context.router.history;
 | 
			
		||||
 | 
			
		||||
      history.push(history.location.pathname, previewState);
 | 
			
		||||
 | 
			
		||||
      this.unlistenHistory = history.listen(() => {
 | 
			
		||||
        this.props.onClose();
 | 
			
		||||
      });
 | 
			
		||||
    }
 | 
			
		||||
  }
 | 
			
		||||
 | 
			
		||||
  componentWillUnmount () {
 | 
			
		||||
    if (this.context.router) {
 | 
			
		||||
      this.unlistenHistory();
 | 
			
		||||
 | 
			
		||||
      if (this.context.router.history.location.state === previewState) {
 | 
			
		||||
        this.context.router.history.goBack();
 | 
			
		||||
      }
 | 
			
		||||
    }
 | 
			
		||||
  }
 | 
			
		||||
 | 
			
		||||
  render () {
 | 
			
		||||
    const { media, accountStaticAvatar, statusId, onClose } = this.props;
 | 
			
		||||
    const options = this.props.options || {};
 | 
			
		||||
 
 | 
			
		||||
		Reference in New Issue
	
	Block a user