2019-04-19 21:14:32 +03:00
|
|
|
import PropTypes from 'prop-types';
|
2023-05-28 17:38:10 +03:00
|
|
|
import { PureComponent } from 'react';
|
|
|
|
|
2019-04-19 21:14:32 +03:00
|
|
|
import { injectIntl, defineMessages } from 'react-intl';
|
2023-05-28 17:38:10 +03:00
|
|
|
|
2018-01-08 18:40:34 +02:00
|
|
|
import classNames from 'classnames';
|
2023-05-28 17:38:10 +03:00
|
|
|
import { Helmet } from 'react-helmet';
|
|
|
|
|
|
|
|
import { connect } from 'react-redux';
|
|
|
|
|
2019-04-20 19:21:11 +03:00
|
|
|
import spring from 'react-motion/lib/spring';
|
2023-05-28 17:38:10 +03:00
|
|
|
|
|
|
|
import { mountCompose, unmountCompose, cycleElefriendCompose } from 'flavours/glitch/actions/compose';
|
|
|
|
import Column from 'flavours/glitch/components/column';
|
2023-05-07 22:43:25 +03:00
|
|
|
import { mascot } from 'flavours/glitch/initial_state';
|
2023-05-28 17:38:10 +03:00
|
|
|
|
|
|
|
import Motion from '../ui/util/optional_motion';
|
|
|
|
|
|
|
|
import ComposeFormContainer from './containers/compose_form_container';
|
2019-04-21 20:07:48 +03:00
|
|
|
import HeaderContainer from './containers/header_container';
|
2023-05-28 17:38:10 +03:00
|
|
|
import NavigationContainer from './containers/navigation_container';
|
|
|
|
import SearchContainer from './containers/search_container';
|
|
|
|
import SearchResultsContainer from './containers/search_results_container';
|
|
|
|
|
2018-08-28 13:01:04 +03:00
|
|
|
const messages = defineMessages({
|
2022-05-03 11:59:23 +03:00
|
|
|
compose: { id: 'navigation_bar.compose', defaultMessage: 'Compose new post' },
|
2018-08-28 13:01:04 +03:00
|
|
|
});
|
|
|
|
|
2019-04-20 19:21:11 +03:00
|
|
|
const mapStateToProps = (state, ownProps) => ({
|
2018-01-14 05:22:37 +02:00
|
|
|
elefriend: state.getIn(['compose', 'elefriend']),
|
2022-10-24 00:37:58 +03:00
|
|
|
showSearch: ownProps.multiColumn ? state.getIn(['search', 'submitted']) && !state.getIn(['search', 'hidden']) : false,
|
2017-12-24 08:16:45 +02:00
|
|
|
});
|
|
|
|
|
2023-05-07 22:43:25 +03:00
|
|
|
const mapDispatchToProps = (dispatch) => ({
|
2018-07-23 17:03:30 +03:00
|
|
|
onClickElefriend () {
|
|
|
|
dispatch(cycleElefriendCompose());
|
|
|
|
},
|
2019-06-14 13:59:59 +03:00
|
|
|
|
|
|
|
onMount () {
|
|
|
|
dispatch(mountCompose());
|
|
|
|
},
|
|
|
|
|
|
|
|
onUnmount () {
|
|
|
|
dispatch(unmountCompose());
|
|
|
|
},
|
2018-07-23 17:03:30 +03:00
|
|
|
});
|
2017-12-24 08:16:45 +02:00
|
|
|
|
2023-05-28 15:18:23 +03:00
|
|
|
class Compose extends PureComponent {
|
2023-02-03 21:52:07 +02:00
|
|
|
|
2019-04-19 21:14:32 +03:00
|
|
|
static propTypes = {
|
|
|
|
multiColumn: PropTypes.bool,
|
2019-04-20 19:21:11 +03:00
|
|
|
showSearch: PropTypes.bool,
|
2019-04-19 21:14:32 +03:00
|
|
|
elefriend: PropTypes.number,
|
|
|
|
onClickElefriend: PropTypes.func,
|
2019-06-14 13:59:59 +03:00
|
|
|
onMount: PropTypes.func,
|
|
|
|
onUnmount: PropTypes.func,
|
2019-04-21 20:07:48 +03:00
|
|
|
intl: PropTypes.object.isRequired,
|
2019-04-19 21:14:32 +03:00
|
|
|
};
|
2017-12-24 08:16:45 +02:00
|
|
|
|
2019-06-14 13:59:59 +03:00
|
|
|
componentDidMount () {
|
2022-10-24 00:37:58 +03:00
|
|
|
this.props.onMount();
|
2019-06-14 13:59:59 +03:00
|
|
|
}
|
|
|
|
|
|
|
|
componentWillUnmount () {
|
2022-10-24 00:37:58 +03:00
|
|
|
this.props.onUnmount();
|
2019-06-14 13:59:59 +03:00
|
|
|
}
|
|
|
|
|
2017-12-27 02:54:28 +02:00
|
|
|
render () {
|
|
|
|
const {
|
2018-01-14 05:22:37 +02:00
|
|
|
elefriend,
|
2017-12-27 02:54:28 +02:00
|
|
|
intl,
|
|
|
|
multiColumn,
|
2018-01-14 11:35:25 +02:00
|
|
|
onClickElefriend,
|
2019-04-20 19:21:11 +03:00
|
|
|
showSearch,
|
2017-12-27 02:54:28 +02:00
|
|
|
} = this.props;
|
2018-01-15 01:31:00 +02:00
|
|
|
const computedClass = classNames('drawer', `mbstobon-${elefriend}`);
|
2018-01-08 18:40:34 +02:00
|
|
|
|
2022-10-04 21:13:23 +03:00
|
|
|
if (multiColumn) {
|
|
|
|
return (
|
|
|
|
<div className={computedClass} role='region' aria-label={intl.formatMessage(messages.compose)}>
|
|
|
|
<HeaderContainer />
|
2019-04-20 22:28:03 +03:00
|
|
|
|
2022-10-24 00:37:58 +03:00
|
|
|
{multiColumn && <SearchContainer />}
|
2019-05-23 02:35:22 +03:00
|
|
|
|
2022-10-04 21:13:23 +03:00
|
|
|
<div className='drawer__pager'>
|
2022-10-24 00:37:58 +03:00
|
|
|
<div className='drawer__inner'>
|
2022-10-04 21:13:23 +03:00
|
|
|
<NavigationContainer />
|
2019-05-23 02:35:22 +03:00
|
|
|
|
2022-10-04 21:13:23 +03:00
|
|
|
<ComposeFormContainer />
|
2018-12-19 20:09:04 +02:00
|
|
|
|
2022-10-04 21:13:23 +03:00
|
|
|
<div className='drawer__inner__mastodon'>
|
|
|
|
{mascot ? <img alt='' draggable='false' src={mascot} /> : <button className='mastodon' onClick={onClickElefriend} />}
|
2019-04-20 19:21:11 +03:00
|
|
|
</div>
|
2022-10-24 00:37:58 +03:00
|
|
|
</div>
|
2022-10-04 21:13:23 +03:00
|
|
|
|
2022-10-24 00:37:58 +03:00
|
|
|
<Motion defaultStyle={{ x: -100 }} style={{ x: spring(showSearch ? 0 : -100, { stiffness: 210, damping: 20 }) }}>
|
2022-10-04 21:13:23 +03:00
|
|
|
{({ x }) => (
|
|
|
|
<div className='drawer__inner darker' style={{ transform: `translateX(${x}%)`, visibility: x === -100 ? 'hidden' : 'visible' }}>
|
|
|
|
<SearchResultsContainer />
|
|
|
|
</div>
|
|
|
|
)}
|
|
|
|
</Motion>
|
|
|
|
</div>
|
2017-12-30 00:55:06 +02:00
|
|
|
</div>
|
2022-10-04 21:13:23 +03:00
|
|
|
);
|
|
|
|
}
|
|
|
|
|
|
|
|
return (
|
|
|
|
<Column>
|
|
|
|
<NavigationContainer />
|
|
|
|
<ComposeFormContainer />
|
2022-10-20 15:35:29 +03:00
|
|
|
|
|
|
|
<Helmet>
|
|
|
|
<meta name='robots' content='noindex' />
|
|
|
|
</Helmet>
|
2022-10-04 21:13:23 +03:00
|
|
|
</Column>
|
2017-12-27 02:54:28 +02:00
|
|
|
);
|
|
|
|
}
|
2019-04-20 22:28:03 +03:00
|
|
|
|
2017-12-24 08:16:45 +02:00
|
|
|
}
|
2023-03-25 00:15:25 +02:00
|
|
|
|
|
|
|
export default connect(mapStateToProps, mapDispatchToProps)(injectIntl(Compose));
|