The code powering m.abunchtell.com https://m.abunchtell.com
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.6 KiB

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