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.

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