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.

107 lines
3.6 KiB

  1. import React from 'react';
  2. import { defineMessages, injectIntl, FormattedMessage } from 'react-intl';
  3. import { connect } from 'react-redux';
  4. import PropTypes from 'prop-types';
  5. import Column from 'mastodon/components/column';
  6. import ColumnHeader from 'mastodon/components/column_header';
  7. import { NavLink, Switch, Route } from 'react-router-dom';
  8. import Links from './links';
  9. import Tags from './tags';
  10. import Statuses from './statuses';
  11. import Suggestions from './suggestions';
  12. import Search from 'mastodon/features/compose/containers/search_container';
  13. import SearchResults from './results';
  14. import { Helmet } from 'react-helmet';
  15. import { showTrends } from 'mastodon/initial_state';
  16. const messages = defineMessages({
  17. title: { id: 'explore.title', defaultMessage: 'Explore' },
  18. searchResults: { id: 'explore.search_results', defaultMessage: 'Search results' },
  19. });
  20. const mapStateToProps = state => ({
  21. layout: state.getIn(['meta', 'layout']),
  22. isSearching: state.getIn(['search', 'submitted']) || !showTrends,
  23. });
  24. class Explore extends React.PureComponent {
  25. static contextTypes = {
  26. router: PropTypes.object,
  27. identity: PropTypes.object,
  28. };
  29. static propTypes = {
  30. intl: PropTypes.object.isRequired,
  31. multiColumn: PropTypes.bool,
  32. isSearching: PropTypes.bool,
  33. };
  34. handleHeaderClick = () => {
  35. this.column.scrollTop();
  36. };
  37. setRef = c => {
  38. this.column = c;
  39. };
  40. render() {
  41. const { intl, multiColumn, isSearching } = this.props;
  42. const { signedIn } = this.context.identity;
  43. return (
  44. <Column bindToDocument={!multiColumn} ref={this.setRef} label={intl.formatMessage(messages.title)}>
  45. <ColumnHeader
  46. icon={isSearching ? 'search' : 'hashtag'}
  47. title={intl.formatMessage(isSearching ? messages.searchResults : messages.title)}
  48. onClick={this.handleHeaderClick}
  49. multiColumn={multiColumn}
  50. />
  51. <div className='explore__search-header'>
  52. <Search />
  53. </div>
  54. <div className='scrollable scrollable--flex'>
  55. {isSearching ? (
  56. <SearchResults />
  57. ) : (
  58. <>
  59. <div className='account__section-headline'>
  60. <NavLink exact to='/explore'>
  61. <FormattedMessage tagName='div' id='explore.trending_statuses' defaultMessage='Posts' />
  62. </NavLink>
  63. <NavLink exact to='/explore/tags'>
  64. <FormattedMessage tagName='div' id='explore.trending_tags' defaultMessage='Hashtags' />
  65. </NavLink>
  66. <NavLink exact to='/explore/links'>
  67. <FormattedMessage tagName='div' id='explore.trending_links' defaultMessage='News' />
  68. </NavLink>
  69. {signedIn && (
  70. <NavLink exact to='/explore/suggestions'>
  71. <FormattedMessage tagName='div' id='explore.suggested_follows' defaultMessage='For you' />
  72. </NavLink>
  73. )}
  74. </div>
  75. <Switch>
  76. <Route path='/explore/tags' component={Tags} />
  77. <Route path='/explore/links' component={Links} />
  78. <Route path='/explore/suggestions' component={Suggestions} />
  79. <Route exact path={['/explore', '/explore/posts', '/search']} component={Statuses} componentParams={{ multiColumn }} />
  80. </Switch>
  81. <Helmet>
  82. <title>{intl.formatMessage(messages.title)}</title>
  83. <meta name='robots' content={isSearching ? 'noindex' : 'all'} />
  84. </Helmet>
  85. </>
  86. )}
  87. </div>
  88. </Column>
  89. );
  90. }
  91. }
  92. export default connect(mapStateToProps)(injectIntl(Explore));