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.

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