You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

128 lines
5.7 KiB

7 years ago
7 years ago
7 years ago
7 years ago
7 years ago
7 years ago
7 years ago
7 years ago
7 years ago
7 years ago
7 years ago
7 years ago
7 years ago
7 years ago
7 years ago
  1. import React from 'react';
  2. import ComposeFormContainer from './containers/compose_form_container';
  3. import NavigationContainer from './containers/navigation_container';
  4. import PropTypes from 'prop-types';
  5. import ImmutablePropTypes from 'react-immutable-proptypes';
  6. import { connect } from 'react-redux';
  7. import { mountCompose, unmountCompose } from '../../actions/compose';
  8. import { Link } from 'react-router-dom';
  9. import { injectIntl, defineMessages } from 'react-intl';
  10. import SearchContainer from './containers/search_container';
  11. import Motion from '../ui/util/optional_motion';
  12. import spring from 'react-motion/lib/spring';
  13. import SearchResultsContainer from './containers/search_results_container';
  14. import { changeComposing } from '../../actions/compose';
  15. import elephantUIPlane from '../../../images/elephant_ui_plane.svg';
  16. import { mascot } from '../../initial_state';
  17. const messages = defineMessages({
  18. start: { id: 'getting_started.heading', defaultMessage: 'Getting started' },
  19. home_timeline: { id: 'tabs_bar.home', defaultMessage: 'Home' },
  20. notifications: { id: 'tabs_bar.notifications', defaultMessage: 'Notifications' },
  21. public: { id: 'navigation_bar.public_timeline', defaultMessage: 'Federated timeline' },
  22. community: { id: 'navigation_bar.community_timeline', defaultMessage: 'Local timeline' },
  23. preferences: { id: 'navigation_bar.preferences', defaultMessage: 'Preferences' },
  24. logout: { id: 'navigation_bar.logout', defaultMessage: 'Logout' },
  25. compose: { id: 'navigation_bar.compose', defaultMessage: 'Compose new toot' },
  26. });
  27. const mapStateToProps = (state, ownProps) => ({
  28. columns: state.getIn(['settings', 'columns']),
  29. showSearch: ownProps.multiColumn ? state.getIn(['search', 'submitted']) && !state.getIn(['search', 'hidden']) : ownProps.isSearchPage,
  30. });
  31. export default @connect(mapStateToProps)
  32. @injectIntl
  33. class Compose extends React.PureComponent {
  34. static propTypes = {
  35. dispatch: PropTypes.func.isRequired,
  36. columns: ImmutablePropTypes.list.isRequired,
  37. multiColumn: PropTypes.bool,
  38. showSearch: PropTypes.bool,
  39. isSearchPage: PropTypes.bool,
  40. intl: PropTypes.object.isRequired,
  41. };
  42. componentDidMount () {
  43. const { isSearchPage } = this.props;
  44. if (!isSearchPage) {
  45. this.props.dispatch(mountCompose());
  46. }
  47. }
  48. componentWillUnmount () {
  49. const { isSearchPage } = this.props;
  50. if (!isSearchPage) {
  51. this.props.dispatch(unmountCompose());
  52. }
  53. }
  54. onFocus = () => {
  55. this.props.dispatch(changeComposing(true));
  56. }
  57. onBlur = () => {
  58. this.props.dispatch(changeComposing(false));
  59. }
  60. render () {
  61. const { multiColumn, showSearch, isSearchPage, intl } = this.props;
  62. let header = '';
  63. if (multiColumn) {
  64. const { columns } = this.props;
  65. header = (
  66. <nav className='drawer__header'>
  67. <Link to='/getting-started' className='drawer__tab' title={intl.formatMessage(messages.start)} aria-label={intl.formatMessage(messages.start)}><i role='img' className='fa fa-fw fa-bars' /></Link>
  68. {!columns.some(column => column.get('id') === 'HOME') && (
  69. <Link to='/timelines/home' className='drawer__tab' title={intl.formatMessage(messages.home_timeline)} aria-label={intl.formatMessage(messages.home_timeline)}><i role='img' className='fa fa-fw fa-home' /></Link>
  70. )}
  71. {!columns.some(column => column.get('id') === 'NOTIFICATIONS') && (
  72. <Link to='/notifications' className='drawer__tab' title={intl.formatMessage(messages.notifications)} aria-label={intl.formatMessage(messages.notifications)}><i role='img' className='fa fa-fw fa-bell' /></Link>
  73. )}
  74. {!columns.some(column => column.get('id') === 'COMMUNITY') && (
  75. <Link to='/timelines/public/local' className='drawer__tab' title={intl.formatMessage(messages.community)} aria-label={intl.formatMessage(messages.community)}><i role='img' className='fa fa-fw fa-users' /></Link>
  76. )}
  77. {!columns.some(column => column.get('id') === 'PUBLIC') && (
  78. <Link to='/timelines/public' className='drawer__tab' title={intl.formatMessage(messages.public)} aria-label={intl.formatMessage(messages.public)}><i role='img' className='fa fa-fw fa-globe' /></Link>
  79. )}
  80. <a href='/settings/preferences' className='drawer__tab' title={intl.formatMessage(messages.preferences)} aria-label={intl.formatMessage(messages.preferences)}><i role='img' className='fa fa-fw fa-cog' /></a>
  81. <a href='/auth/sign_out' className='drawer__tab' data-method='delete' title={intl.formatMessage(messages.logout)} aria-label={intl.formatMessage(messages.logout)}><i role='img' className='fa fa-fw fa-sign-out' /></a>
  82. </nav>
  83. );
  84. }
  85. return (
  86. <div className='drawer' role='region' aria-label={intl.formatMessage(messages.compose)}>
  87. {header}
  88. {(multiColumn || isSearchPage) && <SearchContainer /> }
  89. <div className='drawer__pager'>
  90. {!isSearchPage && <div className='drawer__inner' onFocus={this.onFocus}>
  91. <NavigationContainer onClose={this.onBlur} />
  92. <ComposeFormContainer />
  93. {multiColumn && (
  94. <div className='drawer__inner__mastodon'>
  95. <img alt='' draggable='false' src={mascot || elephantUIPlane} />
  96. </div>
  97. )}
  98. </div>}
  99. <Motion defaultStyle={{ x: isSearchPage ? 0 : -100 }} style={{ x: spring(showSearch || isSearchPage ? 0 : -100, { stiffness: 210, damping: 20 }) }}>
  100. {({ x }) => (
  101. <div className='drawer__inner darker' style={{ transform: `translateX(${x}%)`, visibility: x === -100 ? 'hidden' : 'visible' }}>
  102. <SearchResultsContainer />
  103. </div>
  104. )}
  105. </Motion>
  106. </div>
  107. </div>
  108. );
  109. }
  110. }