2017-12-24 01:16:45 -05:00
|
|
|
// Package imports.
|
|
|
|
import React from 'react';
|
2019-04-19 14:14:32 -04:00
|
|
|
import { connect } from 'react-redux';
|
|
|
|
import PropTypes from 'prop-types';
|
2017-12-24 01:16:45 -05:00
|
|
|
import ImmutablePropTypes from 'react-immutable-proptypes';
|
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';
|
2017-12-24 01:16:45 -05:00
|
|
|
|
|
|
|
// Actions.
|
|
|
|
import { openModal } from 'flavours/glitch/actions/modal';
|
2018-01-14 04:35:25 -05:00
|
|
|
import { cycleElefriendCompose } from 'flavours/glitch/actions/compose';
|
2017-12-24 01:16:45 -05:00
|
|
|
|
|
|
|
// Components.
|
2017-12-29 17:55:06 -05:00
|
|
|
import Composer from 'flavours/glitch/features/composer';
|
|
|
|
import DrawerAccount from './account';
|
2017-12-26 19:54:28 -05:00
|
|
|
import DrawerHeader from './header';
|
|
|
|
import DrawerResults from './results';
|
2019-04-20 11:50:12 -04:00
|
|
|
import SearchContainer from './containers/search_container';
|
2017-12-24 01:16:45 -05:00
|
|
|
|
|
|
|
// Utils.
|
2018-12-19 14:23:16 -05:00
|
|
|
import { me, mascot } from 'flavours/glitch/util/initial_state';
|
2017-12-26 19:54:28 -05:00
|
|
|
import { wrap } from 'flavours/glitch/util/redux_helpers';
|
2017-12-24 01:16:45 -05:00
|
|
|
|
2018-08-28 06:01:04 -04:00
|
|
|
// Messages.
|
|
|
|
const messages = defineMessages({
|
|
|
|
compose: { id: 'navigation_bar.compose', defaultMessage: 'Compose new toot' },
|
|
|
|
});
|
|
|
|
|
2017-12-24 01:16:45 -05:00
|
|
|
// State mapping.
|
|
|
|
const mapStateToProps = state => ({
|
2017-12-26 19:54:28 -05:00
|
|
|
account: state.getIn(['accounts', me]),
|
2017-12-24 01:16:45 -05:00
|
|
|
columns: state.getIn(['settings', 'columns']),
|
2018-01-13 22:22:37 -05:00
|
|
|
elefriend: state.getIn(['compose', 'elefriend']),
|
2017-12-26 19:54:28 -05:00
|
|
|
results: state.getIn(['search', 'results']),
|
|
|
|
searchHidden: state.getIn(['search', 'hidden']),
|
|
|
|
submitted: state.getIn(['search', 'submitted']),
|
2018-09-06 13:17:14 -04:00
|
|
|
unreadNotifications: state.getIn(['notifications', 'unread']),
|
2018-09-06 14:55:11 -04:00
|
|
|
showNotificationsBadge: state.getIn(['local_settings', 'notifications', 'tab_badge']),
|
2017-12-24 01:16:45 -05:00
|
|
|
});
|
|
|
|
|
|
|
|
// Dispatch mapping.
|
2018-07-23 10:03:30 -04:00
|
|
|
const mapDispatchToProps = (dispatch, { intl }) => ({
|
|
|
|
onClickElefriend () {
|
|
|
|
dispatch(cycleElefriendCompose());
|
|
|
|
},
|
|
|
|
onOpenSettings (e) {
|
|
|
|
e.preventDefault();
|
|
|
|
e.stopPropagation();
|
|
|
|
dispatch(openModal('SETTINGS', {}));
|
|
|
|
},
|
|
|
|
});
|
2017-12-24 01:16:45 -05:00
|
|
|
|
|
|
|
// The component.
|
2019-04-19 14:14:32 -04:00
|
|
|
export default @connect(mapStateToProps, mapDispatchToProps)
|
|
|
|
@injectIntl
|
|
|
|
class Compose extends React.PureComponent {
|
|
|
|
static propTypes = {
|
|
|
|
intl: PropTypes.object.isRequired,
|
|
|
|
isSearchPage: PropTypes.bool,
|
|
|
|
multiColumn: PropTypes.bool,
|
|
|
|
|
|
|
|
// State props.
|
|
|
|
account: ImmutablePropTypes.map,
|
|
|
|
columns: ImmutablePropTypes.list,
|
|
|
|
results: ImmutablePropTypes.map,
|
|
|
|
elefriend: PropTypes.number,
|
|
|
|
searchHidden: PropTypes.bool,
|
|
|
|
submitted: PropTypes.bool,
|
|
|
|
unreadNotifications: PropTypes.number,
|
|
|
|
showNotificationsBadge: PropTypes.bool,
|
|
|
|
|
|
|
|
// Dispatch props.
|
|
|
|
onClickElefriend: PropTypes.func,
|
|
|
|
onOpenSettings: PropTypes.func,
|
|
|
|
};
|
2017-12-24 01:16:45 -05:00
|
|
|
|
2017-12-26 19:54:28 -05:00
|
|
|
// Rendering.
|
|
|
|
render () {
|
|
|
|
const {
|
2018-01-03 15:36:21 -05:00
|
|
|
account,
|
|
|
|
columns,
|
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-01-03 15:36:21 -05:00
|
|
|
onOpenSettings,
|
|
|
|
results,
|
|
|
|
searchHidden,
|
|
|
|
submitted,
|
2018-08-31 07:54:25 -04:00
|
|
|
isSearchPage,
|
2018-09-06 13:17:14 -04:00
|
|
|
unreadNotifications,
|
2018-09-06 14:55:11 -04:00
|
|
|
showNotificationsBadge,
|
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
|
|
|
// The result.
|
|
|
|
return (
|
2018-08-28 06:01:04 -04:00
|
|
|
<div className={computedClass} role='region' aria-label={intl.formatMessage(messages.compose)}>
|
2019-04-19 14:14:32 -04:00
|
|
|
{multiColumn && (
|
2017-12-26 19:54:28 -05:00
|
|
|
<DrawerHeader
|
|
|
|
columns={columns}
|
2018-09-06 13:17:14 -04:00
|
|
|
unreadNotifications={unreadNotifications}
|
2018-09-06 14:55:11 -04:00
|
|
|
showNotificationsBadge={showNotificationsBadge}
|
2017-12-26 19:54:28 -05:00
|
|
|
intl={intl}
|
2018-01-03 15:36:21 -05:00
|
|
|
onSettingsClick={onOpenSettings}
|
2017-12-26 19:54:28 -05:00
|
|
|
/>
|
2019-04-19 14:14:32 -04:00
|
|
|
)}
|
2019-04-20 11:50:12 -04:00
|
|
|
{(multiColumn || isSearchPage) && <SearchContainer /> }
|
2018-12-19 13:09:04 -05:00
|
|
|
<div className='drawer__pager'>
|
|
|
|
{!isSearchPage && <div className='drawer__inner'>
|
|
|
|
<DrawerAccount account={account} />
|
|
|
|
<Composer />
|
|
|
|
{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>}
|
|
|
|
|
2018-08-31 08:18:33 -04:00
|
|
|
{(multiColumn || isSearchPage) &&
|
|
|
|
<DrawerResults
|
|
|
|
results={results}
|
|
|
|
visible={submitted && !searchHidden}
|
|
|
|
/>}
|
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
|
|
|
);
|
|
|
|
}
|
2017-12-24 01:16:45 -05:00
|
|
|
}
|