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

Add: #92 アカウントのおすすめタグを真ん中のカラムからも確認できるように #678

Merged
merged 2 commits into from
Mar 27, 2024
Merged
Show file tree
Hide file tree
Changes from all 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
22 changes: 16 additions & 6 deletions app/javascript/mastodon/components/hashtag_bar.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -196,9 +196,15 @@ export function getHashtagBarForStatus(status: StatusLike) {
};
}

export function getFeaturedHashtagBar(acct: string, tags: string[]) {
return <HashtagBar acct={acct} hashtags={tags} defaultExpanded />;
}

const HashtagBar: React.FC<{
hashtags: string[];
}> = ({ hashtags }) => {
acct?: string;
defaultExpanded?: boolean;
}> = ({ hashtags, acct, defaultExpanded }) => {
const [expanded, setExpanded] = useState(false);
const handleClick = useCallback(() => {
setExpanded(true);
Expand All @@ -208,19 +214,23 @@ const HashtagBar: React.FC<{
return null;
}

const revealedHashtags = expanded
? hashtags
: hashtags.slice(0, VISIBLE_HASHTAGS);
const revealedHashtags =
expanded || defaultExpanded
? hashtags
: hashtags.slice(0, VISIBLE_HASHTAGS);

return (
<div className='hashtag-bar'>
{revealedHashtags.map((hashtag) => (
<Link key={hashtag} to={`/tags/${hashtag}`}>
<Link
key={hashtag}
to={acct ? `/@${acct}/tagged/${hashtag}` : `/tags/${hashtag}`}
>
#<span>{hashtag}</span>
</Link>
))}

{!expanded && hashtags.length > VISIBLE_HASHTAGS && (
{!expanded && !defaultExpanded && hashtags.length > VISIBLE_HASHTAGS && (
<button className='link-button' onClick={handleClick}>
<FormattedMessage
id='hashtags.and_other'
Expand Down
26 changes: 25 additions & 1 deletion app/javascript/mastodon/features/account/components/header.jsx
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,7 @@ import { Badge, AutomatedBadge, GroupBadge } from 'mastodon/components/badge';
import { Button } from 'mastodon/components/button';
import { CopyIconButton } from 'mastodon/components/copy_icon_button';
import { FollowersCounter, FollowingCounter, StatusesCounter } from 'mastodon/components/counters';
import { getFeaturedHashtagBar } from 'mastodon/components/hashtag_bar';
import { Icon } from 'mastodon/components/icon';
import { IconButton } from 'mastodon/components/icon_button';
import { LoadingIndicator } from 'mastodon/components/loading_indicator';
Expand Down Expand Up @@ -115,6 +116,7 @@ class Header extends ImmutablePureComponent {

static propTypes = {
account: ImmutablePropTypes.record,
featuredTags: PropTypes.array,
identity_props: ImmutablePropTypes.list,
onFollow: PropTypes.func.isRequired,
onBlock: PropTypes.func.isRequired,
Expand Down Expand Up @@ -215,6 +217,16 @@ class Header extends ImmutablePureComponent {
}
};

handleFeaturedHashtagClick = e => {
const { history, account } = this.props;
const value = e.currentTarget.textContent.replace(/^#/, '');

if (history && e.button === 0 && !(e.ctrlKey || e.metaKey)) {
e.preventDefault();
history.push(`/@${account.get('acct')}/tagged/${value}`);
}
};

handleMentionClick = e => {
const { history, onOpenURL } = this.props;

Expand Down Expand Up @@ -244,7 +256,11 @@ class Header extends ImmutablePureComponent {
link = links[i];

if (link.textContent[0] === '#' || (link.previousSibling && link.previousSibling.textContent && link.previousSibling.textContent[link.previousSibling.textContent.length - 1] === '#')) {
link.addEventListener('click', this.handleHashtagClick, false);
if (link.href && link.href.includes('/tagged/')) {
link.addEventListener('click', this.handleFeaturedHashtagClick, false);
} else {
link.addEventListener('click', this.handleHashtagClick, false);
}
} else if (link.classList.contains('mention')) {
link.addEventListener('click', this.handleMentionClick, false);
}
Expand Down Expand Up @@ -409,6 +425,8 @@ class Header extends ImmutablePureComponent {
const username = account.get('acct').split('@')[0];
const domain = isLocal ? localDomain : account.get('acct').split('@')[1];
const isIndexable = !account.get('noindex');
const featuredTagsArr = this.props.featuredTags?.map((tag) => tag.get('name')).toArray() || [];
const featuredTags = getFeaturedHashtagBar(account.get('acct'), featuredTagsArr);

const badges = [];

Expand Down Expand Up @@ -472,6 +490,12 @@ class Header extends ImmutablePureComponent {

{account.get('note').length > 0 && account.get('note') !== '<p></p>' && <div className='account__header__content translate' dangerouslySetInnerHTML={content} />}

{featuredTagsArr.length > 0 && (
<div className='account__header__featured-tags'>
{featuredTags}
</div>
)}

<div className='account__header__fields'>
<dl>
<dt><FormattedMessage id='account.joined_short' defaultMessage='Joined' /></dt>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@ class Header extends ImmutablePureComponent {

static propTypes = {
account: ImmutablePropTypes.record,
featuredTags: PropTypes.array,
onFollow: PropTypes.func.isRequired,
onBlock: PropTypes.func.isRequired,
onMention: PropTypes.func.isRequired,
Expand Down Expand Up @@ -123,7 +124,7 @@ class Header extends ImmutablePureComponent {
};

render () {
const { account, hidden, hideTabs } = this.props;
const { account, featuredTags, hidden, hideTabs } = this.props;

if (account === null) {
return null;
Expand All @@ -136,6 +137,7 @@ class Header extends ImmutablePureComponent {

<InnerHeader
account={account}
featuredTags={featuredTags}
onFollow={this.handleFollow}
onBlock={this.handleBlock}
onMention={this.handleMention}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -37,6 +37,7 @@ const makeMapStateToProps = () => {
account: getAccount(state, accountId),
domain: state.getIn(['meta', 'domain']),
hidden: getAccountHidden(state, accountId),
featuredTags: state.getIn(['user_lists', 'featured_tags', accountId, 'items']),
});

return mapStateToProps;
Expand Down
Loading