2017-12-24 15:16:45 +09:00
|
|
|
// Package imports.
|
|
|
|
import React from 'react';
|
2019-04-20 03:14:32 +09:00
|
|
|
import { connect } from 'react-redux';
|
|
|
|
import PropTypes from 'prop-types';
|
2017-12-24 15:16:45 +09:00
|
|
|
import ImmutablePropTypes from 'react-immutable-proptypes';
|
2019-04-20 03:14:32 +09:00
|
|
|
import { injectIntl, defineMessages } from 'react-intl';
|
2018-01-09 01:40:34 +09:00
|
|
|
import classNames from 'classnames';
|
2017-12-24 15:16:45 +09:00
|
|
|
|
|
|
|
// Actions.
|
|
|
|
import { openModal } from 'flavours/glitch/actions/modal';
|
2018-01-14 18:35:25 +09:00
|
|
|
import { cycleElefriendCompose } from 'flavours/glitch/actions/compose';
|
2017-12-24 15:16:45 +09:00
|
|
|
|
|
|
|
// Components.
|
2017-12-30 07:55:06 +09:00
|
|
|
import Composer from 'flavours/glitch/features/composer';
|
2017-12-27 09:54:28 +09:00
|
|
|
import DrawerHeader from './header';
|
2019-04-21 00:50:12 +09:00
|
|
|
import SearchContainer from './containers/search_container';
|
2019-04-21 02:18:26 +09:00
|
|
|
import SearchResultsContainer from './containers/search_results_container';
|
2019-04-21 03:32:16 +09:00
|
|
|
import NavigationContainer from './containers/navigation_container';
|
2019-04-21 01:21:11 +09:00
|
|
|
import spring from 'react-motion/lib/spring';
|
2017-12-24 15:16:45 +09:00
|
|
|
|
|
|
|
// Utils.
|
2018-12-20 04:23:16 +09:00
|
|
|
import { me, mascot } from 'flavours/glitch/util/initial_state';
|
2019-04-21 01:21:11 +09:00
|
|
|
import Motion from 'flavours/glitch/util/optional_motion';
|
2017-12-24 15:16:45 +09:00
|
|
|
|
2018-08-28 19:01:04 +09:00
|
|
|
// Messages.
|
|
|
|
const messages = defineMessages({
|
|
|
|
compose: { id: 'navigation_bar.compose', defaultMessage: 'Compose new toot' },
|
|
|
|
});
|
|
|
|
|
2017-12-24 15:16:45 +09:00
|
|
|
// State mapping.
|
2019-04-21 01:21:11 +09:00
|
|
|
const mapStateToProps = (state, ownProps) => ({
|
2017-12-24 15:16:45 +09:00
|
|
|
columns: state.getIn(['settings', 'columns']),
|
2018-01-14 12:22:37 +09:00
|
|
|
elefriend: state.getIn(['compose', 'elefriend']),
|
2019-04-21 01:21:11 +09:00
|
|
|
showSearch: ownProps.multiColumn ? state.getIn(['search', 'submitted']) && !state.getIn(['search', 'hidden']) : ownProps.isSearchPage,
|
2018-09-07 02:17:14 +09:00
|
|
|
unreadNotifications: state.getIn(['notifications', 'unread']),
|
2018-09-07 03:55:11 +09:00
|
|
|
showNotificationsBadge: state.getIn(['local_settings', 'notifications', 'tab_badge']),
|
2017-12-24 15:16:45 +09:00
|
|
|
});
|
|
|
|
|
|
|
|
// Dispatch mapping.
|
2018-07-23 23:03:30 +09:00
|
|
|
const mapDispatchToProps = (dispatch, { intl }) => ({
|
|
|
|
onClickElefriend () {
|
|
|
|
dispatch(cycleElefriendCompose());
|
|
|
|
},
|
|
|
|
onOpenSettings (e) {
|
|
|
|
e.preventDefault();
|
|
|
|
e.stopPropagation();
|
|
|
|
dispatch(openModal('SETTINGS', {}));
|
|
|
|
},
|
|
|
|
});
|
2017-12-24 15:16:45 +09:00
|
|
|
|
|
|
|
// The component.
|
2019-04-20 03:14:32 +09:00
|
|
|
export default @connect(mapStateToProps, mapDispatchToProps)
|
|
|
|
@injectIntl
|
|
|
|
class Compose extends React.PureComponent {
|
|
|
|
static propTypes = {
|
|
|
|
intl: PropTypes.object.isRequired,
|
|
|
|
isSearchPage: PropTypes.bool,
|
|
|
|
multiColumn: PropTypes.bool,
|
2019-04-21 01:21:11 +09:00
|
|
|
showSearch: PropTypes.bool,
|
2019-04-20 03:14:32 +09:00
|
|
|
|
|
|
|
// State props.
|
|
|
|
columns: ImmutablePropTypes.list,
|
|
|
|
elefriend: PropTypes.number,
|
|
|
|
unreadNotifications: PropTypes.number,
|
|
|
|
showNotificationsBadge: PropTypes.bool,
|
|
|
|
|
|
|
|
// Dispatch props.
|
|
|
|
onClickElefriend: PropTypes.func,
|
|
|
|
onOpenSettings: PropTypes.func,
|
|
|
|
};
|
2017-12-24 15:16:45 +09:00
|
|
|
|
2017-12-27 09:54:28 +09:00
|
|
|
// Rendering.
|
|
|
|
render () {
|
|
|
|
const {
|
2018-01-04 05:36:21 +09:00
|
|
|
columns,
|
2018-01-14 12:22:37 +09:00
|
|
|
elefriend,
|
2017-12-27 09:54:28 +09:00
|
|
|
intl,
|
|
|
|
multiColumn,
|
2018-01-14 18:35:25 +09:00
|
|
|
onClickElefriend,
|
2018-01-04 05:36:21 +09:00
|
|
|
onOpenSettings,
|
2018-08-31 20:54:25 +09:00
|
|
|
isSearchPage,
|
2018-09-07 02:17:14 +09:00
|
|
|
unreadNotifications,
|
2018-09-07 03:55:11 +09:00
|
|
|
showNotificationsBadge,
|
2019-04-21 01:21:11 +09:00
|
|
|
showSearch,
|
2017-12-27 09:54:28 +09:00
|
|
|
} = this.props;
|
2018-01-15 08:31:00 +09:00
|
|
|
const computedClass = classNames('drawer', `mbstobon-${elefriend}`);
|
2018-01-09 01:40:34 +09:00
|
|
|
|
2017-12-27 09:54:28 +09:00
|
|
|
// The result.
|
|
|
|
return (
|
2018-08-28 19:01:04 +09:00
|
|
|
<div className={computedClass} role='region' aria-label={intl.formatMessage(messages.compose)}>
|
2019-04-20 03:14:32 +09:00
|
|
|
{multiColumn && (
|
2017-12-27 09:54:28 +09:00
|
|
|
<DrawerHeader
|
|
|
|
columns={columns}
|
2018-09-07 02:17:14 +09:00
|
|
|
unreadNotifications={unreadNotifications}
|
2018-09-07 03:55:11 +09:00
|
|
|
showNotificationsBadge={showNotificationsBadge}
|
2017-12-27 09:54:28 +09:00
|
|
|
intl={intl}
|
2018-01-04 05:36:21 +09:00
|
|
|
onSettingsClick={onOpenSettings}
|
2017-12-27 09:54:28 +09:00
|
|
|
/>
|
2019-04-20 03:14:32 +09:00
|
|
|
)}
|
2019-04-21 00:50:12 +09:00
|
|
|
{(multiColumn || isSearchPage) && <SearchContainer /> }
|
2018-12-20 03:09:04 +09:00
|
|
|
<div className='drawer__pager'>
|
|
|
|
{!isSearchPage && <div className='drawer__inner'>
|
2019-04-21 03:32:16 +09:00
|
|
|
<NavigationContainer />
|
2018-12-20 03:09:04 +09:00
|
|
|
<Composer />
|
|
|
|
{multiColumn && (
|
|
|
|
<div className='drawer__inner__mastodon'>
|
2018-12-20 04:23:16 +09:00
|
|
|
{mascot ? <img alt='' draggable='false' src={mascot} /> : <button className='mastodon' onClick={onClickElefriend} />}
|
2018-12-20 03:09:04 +09:00
|
|
|
</div>
|
|
|
|
)}
|
|
|
|
</div>}
|
|
|
|
|
2019-04-21 01:21:11 +09: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-21 02:18:26 +09:00
|
|
|
<SearchResultsContainer />
|
2019-04-21 01:21:11 +09:00
|
|
|
</div>
|
|
|
|
)}
|
|
|
|
</Motion>
|
2017-12-30 07:55:06 +09:00
|
|
|
</div>
|
2017-12-24 15:16:45 +09:00
|
|
|
</div>
|
2017-12-27 09:54:28 +09:00
|
|
|
);
|
|
|
|
}
|
2017-12-24 15:16:45 +09:00
|
|
|
}
|