2022-02-25 08:34:33 +09:00
|
|
|
import React from 'react';
|
|
|
|
import { defineMessages, injectIntl, FormattedMessage } from 'react-intl';
|
|
|
|
import { connect } from 'react-redux';
|
|
|
|
import PropTypes from 'prop-types';
|
|
|
|
import Column from 'flavours/glitch/components/column';
|
|
|
|
import ColumnHeader from 'flavours/glitch/components/column_header';
|
|
|
|
import { NavLink, Switch, Route } from 'react-router-dom';
|
|
|
|
import Links from './links';
|
|
|
|
import Tags from './tags';
|
|
|
|
import Statuses from './statuses';
|
|
|
|
import Suggestions from './suggestions';
|
|
|
|
import Search from 'flavours/glitch/features/compose/containers/search_container';
|
|
|
|
import SearchResults from './results';
|
2022-10-11 17:17:04 +09:00
|
|
|
import { showTrends } from 'flavours/glitch/initial_state';
|
2022-09-29 11:39:33 +09:00
|
|
|
import { Helmet } from 'react-helmet';
|
2022-02-25 08:34:33 +09:00
|
|
|
|
|
|
|
const messages = defineMessages({
|
|
|
|
title: { id: 'explore.title', defaultMessage: 'Explore' },
|
|
|
|
searchResults: { id: 'explore.search_results', defaultMessage: 'Search results' },
|
|
|
|
});
|
|
|
|
|
|
|
|
const mapStateToProps = state => ({
|
|
|
|
layout: state.getIn(['meta', 'layout']),
|
2022-10-09 01:50:46 +09:00
|
|
|
isSearching: state.getIn(['search', 'submitted']) || !showTrends,
|
2022-02-25 08:34:33 +09:00
|
|
|
});
|
|
|
|
|
2022-11-17 16:54:43 +09:00
|
|
|
// Fix strange bug on Safari where <span> (rendered by FormattedMessage) disappears
|
|
|
|
// after clicking around Explore top bar (issue #20885).
|
|
|
|
// Removing width=100% from <a> also fixes it, as well as replacing <span> with <div>
|
|
|
|
// We're choosing to wrap span with div to keep the changes local only to this tool bar.
|
|
|
|
const WrapFormattedMessage = ({ children, ...props }) => <div><FormattedMessage {...props}>{children}</FormattedMessage></div>;
|
|
|
|
WrapFormattedMessage.propTypes = {
|
|
|
|
children: PropTypes.any,
|
|
|
|
};
|
|
|
|
|
|
|
|
|
2022-02-25 08:34:33 +09:00
|
|
|
export default @connect(mapStateToProps)
|
|
|
|
@injectIntl
|
|
|
|
class Explore extends React.PureComponent {
|
|
|
|
|
|
|
|
static contextTypes = {
|
|
|
|
router: PropTypes.object,
|
2022-10-05 03:13:23 +09:00
|
|
|
identity: PropTypes.object,
|
2022-02-25 08:34:33 +09:00
|
|
|
};
|
|
|
|
|
|
|
|
static propTypes = {
|
|
|
|
intl: PropTypes.object.isRequired,
|
|
|
|
multiColumn: PropTypes.bool,
|
|
|
|
isSearching: PropTypes.bool,
|
|
|
|
};
|
|
|
|
|
|
|
|
handleHeaderClick = () => {
|
|
|
|
this.column.scrollTop();
|
|
|
|
}
|
|
|
|
|
|
|
|
setRef = c => {
|
|
|
|
this.column = c;
|
|
|
|
}
|
|
|
|
|
2022-11-17 16:54:43 +09:00
|
|
|
render() {
|
2022-10-05 03:13:23 +09:00
|
|
|
const { intl, multiColumn, isSearching } = this.props;
|
|
|
|
const { signedIn } = this.context.identity;
|
2022-02-25 08:34:33 +09:00
|
|
|
|
|
|
|
return (
|
|
|
|
<Column bindToDocument={!multiColumn} ref={this.setRef} label={intl.formatMessage(messages.title)}>
|
2022-10-05 03:13:23 +09:00
|
|
|
<ColumnHeader
|
|
|
|
icon={isSearching ? 'search' : 'hashtag'}
|
|
|
|
title={intl.formatMessage(isSearching ? messages.searchResults : messages.title)}
|
|
|
|
onClick={this.handleHeaderClick}
|
|
|
|
multiColumn={multiColumn}
|
|
|
|
/>
|
|
|
|
|
|
|
|
<div className='explore__search-header'>
|
|
|
|
<Search />
|
|
|
|
</div>
|
2022-02-25 08:34:33 +09:00
|
|
|
|
|
|
|
<div className='scrollable scrollable--flex'>
|
|
|
|
{isSearching ? (
|
|
|
|
<SearchResults />
|
|
|
|
) : (
|
|
|
|
<React.Fragment>
|
|
|
|
<div className='account__section-headline'>
|
2022-11-17 16:54:43 +09:00
|
|
|
<NavLink exact to='/explore'><WrapFormattedMessage id='explore.trending_statuses' defaultMessage='Posts' /></NavLink>
|
|
|
|
<NavLink exact to='/explore/tags'><WrapFormattedMessage id='explore.trending_tags' defaultMessage='Hashtags' /></NavLink>
|
|
|
|
<NavLink exact to='/explore/links'><WrapFormattedMessage id='explore.trending_links' defaultMessage='News' /></NavLink>
|
|
|
|
{signedIn && <NavLink exact to='/explore/suggestions'><WrapFormattedMessage id='explore.suggested_follows' defaultMessage='For you' /></NavLink>}
|
2022-02-25 08:34:33 +09:00
|
|
|
</div>
|
|
|
|
|
|
|
|
<Switch>
|
|
|
|
<Route path='/explore/tags' component={Tags} />
|
|
|
|
<Route path='/explore/links' component={Links} />
|
|
|
|
<Route path='/explore/suggestions' component={Suggestions} />
|
|
|
|
<Route exact path={['/explore', '/explore/posts', '/search']} component={Statuses} componentParams={{ multiColumn }} />
|
|
|
|
</Switch>
|
2022-09-29 11:39:33 +09:00
|
|
|
|
|
|
|
<Helmet>
|
2022-10-09 13:08:37 +09:00
|
|
|
<title>{intl.formatMessage(messages.title)}</title>
|
2022-10-20 21:35:29 +09:00
|
|
|
<meta name='robots' content={isSearching ? 'noindex' : 'all'} />
|
2022-09-29 11:39:33 +09:00
|
|
|
</Helmet>
|
2022-02-25 08:34:33 +09:00
|
|
|
</React.Fragment>
|
|
|
|
)}
|
|
|
|
</div>
|
|
|
|
</Column>
|
|
|
|
);
|
|
|
|
}
|
|
|
|
|
|
|
|
}
|