Fix redirecting to `/publish` when compose form is visible in web UI (#19427)

rebase/4.0.0rc1
Eugen Rochko 2022-10-23 23:37:58 +02:00 committed by GitHub
parent 3124f946ee
commit 5452af2188
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
2 changed files with 26 additions and 22 deletions

View File

@ -4,14 +4,13 @@ import NavigationContainer from './containers/navigation_container';
import PropTypes from 'prop-types'; import PropTypes from 'prop-types';
import ImmutablePropTypes from 'react-immutable-proptypes'; import ImmutablePropTypes from 'react-immutable-proptypes';
import { connect } from 'react-redux'; import { connect } from 'react-redux';
import { mountCompose, unmountCompose } from '../../actions/compose'; import { changeComposing, mountCompose, unmountCompose } from '../../actions/compose';
import { Link } from 'react-router-dom'; import { Link } from 'react-router-dom';
import { injectIntl, defineMessages } from 'react-intl'; import { injectIntl, defineMessages } from 'react-intl';
import SearchContainer from './containers/search_container'; import SearchContainer from './containers/search_container';
import Motion from '../ui/util/optional_motion'; import Motion from '../ui/util/optional_motion';
import spring from 'react-motion/lib/spring'; import spring from 'react-motion/lib/spring';
import SearchResultsContainer from './containers/search_results_container'; import SearchResultsContainer from './containers/search_results_container';
import { changeComposing } from '../../actions/compose';
import { openModal } from 'mastodon/actions/modal'; import { openModal } from 'mastodon/actions/modal';
import elephantUIPlane from '../../../images/elephant_ui_plane.svg'; import elephantUIPlane from '../../../images/elephant_ui_plane.svg';
import { mascot } from '../../initial_state'; import { mascot } from '../../initial_state';
@ -35,7 +34,7 @@ const messages = defineMessages({
const mapStateToProps = (state, ownProps) => ({ const mapStateToProps = (state, ownProps) => ({
columns: state.getIn(['settings', 'columns']), columns: state.getIn(['settings', 'columns']),
showSearch: ownProps.multiColumn ? state.getIn(['search', 'submitted']) && !state.getIn(['search', 'hidden']) : ownProps.isSearchPage, showSearch: ownProps.multiColumn ? state.getIn(['search', 'submitted']) && !state.getIn(['search', 'hidden']) : false,
}); });
export default @connect(mapStateToProps) export default @connect(mapStateToProps)
@ -47,24 +46,17 @@ class Compose extends React.PureComponent {
columns: ImmutablePropTypes.list.isRequired, columns: ImmutablePropTypes.list.isRequired,
multiColumn: PropTypes.bool, multiColumn: PropTypes.bool,
showSearch: PropTypes.bool, showSearch: PropTypes.bool,
isSearchPage: PropTypes.bool,
intl: PropTypes.object.isRequired, intl: PropTypes.object.isRequired,
}; };
componentDidMount () { componentDidMount () {
const { isSearchPage } = this.props; const { dispatch } = this.props;
dispatch(mountCompose());
if (!isSearchPage) {
this.props.dispatch(mountCompose());
}
} }
componentWillUnmount () { componentWillUnmount () {
const { isSearchPage } = this.props; const { dispatch } = this.props;
dispatch(unmountCompose());
if (!isSearchPage) {
this.props.dispatch(unmountCompose());
}
} }
handleLogoutClick = e => { handleLogoutClick = e => {
@ -92,7 +84,7 @@ class Compose extends React.PureComponent {
} }
render () { render () {
const { multiColumn, showSearch, isSearchPage, intl } = this.props; const { multiColumn, showSearch, intl } = this.props;
if (multiColumn) { if (multiColumn) {
const { columns } = this.props; const { columns } = this.props;
@ -117,10 +109,10 @@ class Compose extends React.PureComponent {
<a href='/auth/sign_out' className='drawer__tab' title={intl.formatMessage(messages.logout)} aria-label={intl.formatMessage(messages.logout)} onClick={this.handleLogoutClick}><Icon id='sign-out' fixedWidth /></a> <a href='/auth/sign_out' className='drawer__tab' title={intl.formatMessage(messages.logout)} aria-label={intl.formatMessage(messages.logout)} onClick={this.handleLogoutClick}><Icon id='sign-out' fixedWidth /></a>
</nav> </nav>
{(multiColumn || isSearchPage) && <SearchContainer /> } {multiColumn && <SearchContainer /> }
<div className='drawer__pager'> <div className='drawer__pager'>
{!isSearchPage && <div className='drawer__inner' onFocus={this.onFocus}> <div className='drawer__inner' onFocus={this.onFocus}>
<NavigationContainer onClose={this.onBlur} /> <NavigationContainer onClose={this.onBlur} />
<ComposeFormContainer /> <ComposeFormContainer />
@ -128,9 +120,9 @@ class Compose extends React.PureComponent {
<div className='drawer__inner__mastodon'> <div className='drawer__inner__mastodon'>
<img alt='' draggable='false' src={mascot || elephantUIPlane} /> <img alt='' draggable='false' src={mascot || elephantUIPlane} />
</div> </div>
</div>} </div>
<Motion defaultStyle={{ x: isSearchPage ? 0 : -100 }} style={{ x: spring(showSearch || isSearchPage ? 0 : -100, { stiffness: 210, damping: 20 }) }}> <Motion defaultStyle={{ x: -100 }} style={{ x: spring(showSearch ? 0 : -100, { stiffness: 210, damping: 20 }) }}>
{({ x }) => ( {({ x }) => (
<div className='drawer__inner darker' style={{ transform: `translateX(${x}%)`, visibility: x === -100 ? 'hidden' : 'visible' }}> <div className='drawer__inner darker' style={{ transform: `translateX(${x}%)`, visibility: x === -100 ? 'hidden' : 'visible' }}>
<SearchResultsContainer /> <SearchResultsContainer />

View File

@ -6,7 +6,7 @@ import ComposeFormContainer from 'mastodon/features/compose/containers/compose_f
import NavigationContainer from 'mastodon/features/compose/containers/navigation_container'; import NavigationContainer from 'mastodon/features/compose/containers/navigation_container';
import LinkFooter from './link_footer'; import LinkFooter from './link_footer';
import ServerBanner from 'mastodon/components/server_banner'; import ServerBanner from 'mastodon/components/server_banner';
import { changeComposing } from 'mastodon/actions/compose'; import { changeComposing, mountCompose, unmountCompose } from 'mastodon/actions/compose';
export default @connect() export default @connect()
class ComposePanel extends React.PureComponent { class ComposePanel extends React.PureComponent {
@ -20,11 +20,23 @@ class ComposePanel extends React.PureComponent {
}; };
onFocus = () => { onFocus = () => {
this.props.dispatch(changeComposing(true)); const { dispatch } = this.props;
dispatch(changeComposing(true));
} }
onBlur = () => { onBlur = () => {
this.props.dispatch(changeComposing(false)); const { dispatch } = this.props;
dispatch(changeComposing(false));
}
componentDidMount () {
const { dispatch } = this.props;
dispatch(mountCompose());
}
componentWillUnmount () {
const { dispatch } = this.props;
dispatch(unmountCompose());
} }
render() { render() {