The code powering m.abunchtell.com https://m.abunchtell.com
Du kan inte välja fler än 25 ämnen Ämnen måste starta med en bokstav eller siffra, kan innehålla bindestreck ('-') och vara max 35 tecken långa.
 
 
 
 

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