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