Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Proposal: Add tags in status' mention placeholder #227

Open
wants to merge 8 commits into
base: imastodon
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from 4 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
19 changes: 14 additions & 5 deletions app/javascript/mastodon/components/status_content.js
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@ import { isRtl } from '../rtl';
import { FormattedMessage } from 'react-intl';
import Permalink from './permalink';
import classnames from 'classnames';
import 'core-js/fn/array/flat-map';

const MAX_HEIGHT = 642; // 20px * 32 (+ 2px padding at the top)

Expand Down Expand Up @@ -165,29 +166,37 @@ export default class StatusContent extends React.PureComponent {
);

if (status.get('spoiler_text').length > 0) {
let mentionsPlaceholder = '';
let placeholder = '';

const mentionLinks = status.get('mentions').map(item => (
<Permalink to={`/accounts/${item.get('id')}`} href={item.get('url')} key={item.get('id')} className='mention'>
@<span>{item.get('username')}</span>
</Permalink>
)).reduce((aggregate, item) => [...aggregate, item, ' '], []);
));

const tagLinks = status.get('tags').map(item => (
<Permalink to={`/tags/${item.get('name')}`} href={item.get('url')} key={item.get('name')} className='tag'>
#<span>{item.get('name')}</span>
</Permalink>
));

const links = [mentionLinks, tagLinks].flatMap(item => item.toArray()).flatMap(item => [item, ' ']);

const toggleText = hidden ? <FormattedMessage id='status.show_more' defaultMessage='Show more' /> : <FormattedMessage id='status.show_less' defaultMessage='Show less' />;

if (hidden) {
mentionsPlaceholder = <div>{mentionLinks}</div>;
placeholder = <div>{links}</div>;
}

return (
<div className={classNames} ref={this.setRef} tabIndex='0' style={directionStyle} onMouseDown={this.handleMouseDown} onMouseUp={this.handleMouseUp}>
<p style={{ marginBottom: hidden && status.get('mentions').isEmpty() ? '0px' : null }}>
<p style={{ marginBottom: hidden && !links.length ? '0px' : null }}>
<span dangerouslySetInnerHTML={spoilerContent} />
{' '}
<button tabIndex='0' className={`status__content__spoiler-link ${hidden ? 'status__content__spoiler-link--show-more' : 'status__content__spoiler-link--show-less'}`} onClick={this.handleSpoilerClick}>{toggleText}</button>
</p>

{mentionsPlaceholder}
{placeholder}

<div tabIndex={!hidden ? 0 : null} className={`status__content__text ${!hidden ? 'status__content__text--visible' : ''}`} style={directionStyle} dangerouslySetInnerHTML={content} />
</div>
Expand Down
3 changes: 2 additions & 1 deletion app/javascript/styles/mastodon/components.scss
Original file line number Diff line number Diff line change
Expand Up @@ -680,7 +680,8 @@
}
}

&.mention {
&.mention,
&.tag {
&:hover {
text-decoration: none;

Expand Down