0
0
Fork 0

Add autosuggestions for hashtags (#11422)

This commit is contained in:
Eugen Rochko 2019-07-28 14:37:52 +02:00 committed by GitHub
parent 15de24a425
commit cfb2ed7823
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
6 changed files with 107 additions and 27 deletions

View file

@ -0,0 +1,28 @@
import React from 'react';
import PropTypes from 'prop-types';
import { shortNumberFormat } from 'mastodon/utils/numbers';
import { FormattedMessage } from 'react-intl';
export default class AutosuggestHashtag extends React.PureComponent {
static propTypes = {
tag: PropTypes.shape({
name: PropTypes.string.isRequired,
url: PropTypes.string,
history: PropTypes.array.isRequired,
}).isRequired,
};
render () {
const { tag } = this.props;
const weeklyUses = shortNumberFormat(tag.history.reduce((total, day) => total + (day.uses * 1), 0));
return (
<div className='autosuggest-hashtag'>
<div className='autosuggest-hashtag__name'>#<strong>{tag.name}</strong></div>
<div className='autosuggest-hashtag__uses'><FormattedMessage id='autosuggest_hashtag.per_week' defaultMessage='{count} per week' values={{ count: weeklyUses }} /></div>
</div>
);
}
}

View file

@ -1,6 +1,7 @@
import React from 'react';
import AutosuggestAccountContainer from '../features/compose/containers/autosuggest_account_container';
import AutosuggestEmoji from './autosuggest_emoji';
import AutosuggestHashtag from './autosuggest_hashtag';
import ImmutablePropTypes from 'react-immutable-proptypes';
import PropTypes from 'prop-types';
import { isRtl } from '../rtl';
@ -167,12 +168,12 @@ export default class AutosuggestInput extends ImmutablePureComponent {
const { selectedSuggestion } = this.state;
let inner, key;
if (typeof suggestion === 'object') {
if (typeof suggestion === 'object' && suggestion.shortcode) {
inner = <AutosuggestEmoji emoji={suggestion} />;
key = suggestion.id;
} else if (suggestion[0] === '#') {
inner = suggestion;
key = suggestion;
} else if (typeof suggestion === 'object' && suggestion.name) {
inner = <AutosuggestHashtag tag={suggestion} />;
key = suggestion.name;
} else {
inner = <AutosuggestAccountContainer id={suggestion} />;
key = suggestion;

View file

@ -1,6 +1,7 @@
import React from 'react';
import AutosuggestAccountContainer from '../features/compose/containers/autosuggest_account_container';
import AutosuggestEmoji from './autosuggest_emoji';
import AutosuggestHashtag from './autosuggest_hashtag';
import ImmutablePropTypes from 'react-immutable-proptypes';
import PropTypes from 'prop-types';
import { isRtl } from '../rtl';
@ -173,12 +174,12 @@ export default class AutosuggestTextarea extends ImmutablePureComponent {
const { selectedSuggestion } = this.state;
let inner, key;
if (typeof suggestion === 'object') {
if (typeof suggestion === 'object' && suggestion.shortcode) {
inner = <AutosuggestEmoji emoji={suggestion} />;
key = suggestion.id;
} else if (suggestion[0] === '#') {
inner = suggestion;
key = suggestion;
} else if (typeof suggestion === 'object' && suggestion.name) {
inner = <AutosuggestHashtag tag={suggestion} />;
key = suggestion.name;
} else {
inner = <AutosuggestAccountContainer id={suggestion} />;
key = suggestion;