diff options
author | Eugen Rochko <eugen@zeonfederated.com> | 2019-07-28 14:37:52 +0200 |
---|---|---|
committer | ThibG <thib@sitedethib.com> | 2019-09-02 10:57:44 +0200 |
commit | 3380e964497945a5e81012eee3ec65917ac0ade0 (patch) | |
tree | 3ecd7c8d1a8e71779cc0f26815425c61fe8a2ff3 /app/javascript/flavours/glitch/components/autosuggest_hashtag.js | |
parent | 147e90f35d9aadfbe15d044f3ce48be77e26968a (diff) |
[Glitch] Add autosuggestions for hashtags
Port cfb2ed78231758a79af038a964ab7f7b7b35274e to glitch-soc Signed-off-by: Thibaut Girka <thib@sitedethib.com>
Diffstat (limited to 'app/javascript/flavours/glitch/components/autosuggest_hashtag.js')
-rw-r--r-- | app/javascript/flavours/glitch/components/autosuggest_hashtag.js | 28 |
1 files changed, 28 insertions, 0 deletions
diff --git a/app/javascript/flavours/glitch/components/autosuggest_hashtag.js b/app/javascript/flavours/glitch/components/autosuggest_hashtag.js new file mode 100644 index 000000000..93dd70383 --- /dev/null +++ b/app/javascript/flavours/glitch/components/autosuggest_hashtag.js @@ -0,0 +1,28 @@ +import React from 'react'; +import PropTypes from 'prop-types'; +import { shortNumberFormat } from 'flavours/glitch/util/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> + ); + } + +} |