gab-social/app/javascript/gabsocial/features/compose/components/search_results/search_results.js

97 lines
3.4 KiB
JavaScript
Raw Normal View History

2019-07-02 08:10:25 +01:00
import ImmutablePropTypes from 'react-immutable-proptypes';
import ImmutablePureComponent from 'react-immutable-pure-component';
2020-01-29 20:08:56 +00:00
import { FormattedMessage } from 'react-intl';
2020-02-21 00:57:29 +00:00
import TrendingItem from '../../../../components/trends_panel_item';
2020-01-29 16:45:17 +00:00
import Icon from '../../../../components/icon';
import { WhoToFollowPanel } from '../../../../components/panel';
2019-07-05 14:24:16 +01:00
// import TrendsPanel from '../../ui/components/trends_panel';
2020-01-29 16:45:17 +00:00
import GroupListItem from '../../../../components/group_list_item';
2019-07-02 08:10:25 +01:00
2020-01-29 20:08:56 +00:00
export default class SearchResults extends ImmutablePureComponent {
2019-07-02 08:10:25 +01:00
static propTypes = {
results: ImmutablePropTypes.map.isRequired,
location: PropTypes.object,
2019-07-02 08:10:25 +01:00
};
state = {
isSmallScreen: (window.innerWidth <= 895),
}
render () {
const { results, location } = this.props;
2019-07-02 08:10:25 +01:00
const { isSmallScreen } = this.state;
if (results.isEmpty() && isSmallScreen) {
return (
<div className='search-results'>
<WhoToFollowPanel />
</div>
);
}
const pathname = location.pathname || '';
const showPeople = pathname === '/search/people';
const showHashtags = pathname === '/search/hashtags';
const showGroups = pathname === '/search/groups';
const isTop = !showPeople && !showHashtags && !showGroups;
let accounts, statuses, hashtags, groups;
2019-07-02 08:10:25 +01:00
let count = 0;
if (results.get('accounts') && results.get('accounts').size > 0 && (isTop || showPeople)) {
const size = isTop ? Math.min(results.get('accounts').size, 5) : results.get('accounts').size;
count += size;
2019-07-02 08:10:25 +01:00
accounts = (
<div className='search-results__section'>
<h5><Icon id='user' fixedWidth /><FormattedMessage id='search_results.accounts' defaultMessage='People' /></h5>
{results.get('accounts').slice(0, size).map(accountId => <AccountContainer key={accountId} id={accountId} />)}
2019-07-02 08:10:25 +01:00
</div>
);
}
if (results.get('groups') && results.get('groups').size > 0 && (isTop || showGroups)) {
const size = isTop ? Math.min(results.get('groups').size, 5) : results.get('groups').size;
count += size;
groups = (
2019-07-02 08:10:25 +01:00
<div className='search-results__section'>
<h5><Icon id='users' fixedWidth /><FormattedMessage id='search_results.groups' defaultMessage='Groups' /></h5>
{results.get('groups').slice(0, size).map(group => <GroupListItem key={`search-${group.get('name')}`} group={group} />)}
2019-07-02 08:10:25 +01:00
</div>
);
}
if (results.get('hashtags') && results.get('hashtags').size > 0 && (isTop || showHashtags)) {
const size = isTop ? Math.min(results.get('hashtags').size, 5) : results.get('hashtags').size;
count += size;
2019-07-02 08:10:25 +01:00
hashtags = (
<div className='search-results__section'>
<h5><Icon id='hashtag' fixedWidth /><FormattedMessage id='search_results.hashtags' defaultMessage='Hashtags' /></h5>
2020-01-29 16:45:17 +00:00
{results.get('hashtags').slice(0, size).map(hashtag => <TrendingItem key={hashtag.get('name')} hashtag={hashtag} />)}
2019-07-02 08:10:25 +01:00
</div>
);
}
return (
<div className='search-results'>
<div className='search-results__header'>
<Icon id='search' fixedWidth />
<FormattedMessage
id='search_results.total'
defaultMessage='{count, number} {count, plural, one {result} other {results}}'
values={{
count
}}
/>
2019-07-02 08:10:25 +01:00
</div>
{accounts}
{groups}
2019-07-02 08:10:25 +01:00
{statuses}
{hashtags}
</div>
);
}
}