From 6d09a002634b768bb8c2429c1d55547c185a2f7a Mon Sep 17 00:00:00 2001 From: KMY Date: Wed, 27 Mar 2024 17:53:53 +0900 Subject: [PATCH 1/2] =?UTF-8?q?Add:=20#92=20=E3=82=A2=E3=82=AB=E3=82=A6?= =?UTF-8?q?=E3=83=B3=E3=83=88=E3=81=AE=E3=81=8A=E3=81=99=E3=81=99=E3=82=81?= =?UTF-8?q?=E3=82=BF=E3=82=B0=E3=82=92=E7=9C=9F=E3=82=93=E4=B8=AD=E3=81=AE?= =?UTF-8?q?=E3=82=AB=E3=83=A9=E3=83=A0=E3=81=8B=E3=82=89=E3=82=82=E7=A2=BA?= =?UTF-8?q?=E8=AA=8D=E3=81=A7=E3=81=8D=E3=82=8B=E3=82=88=E3=81=86=E3=81=AB?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../mastodon/components/hashtag_bar.tsx | 12 +++++++-- .../features/account/components/header.jsx | 26 ++++++++++++++++++- .../account_timeline/components/header.jsx | 4 ++- .../containers/header_container.jsx | 1 + 4 files changed, 39 insertions(+), 4 deletions(-) diff --git a/app/javascript/mastodon/components/hashtag_bar.tsx b/app/javascript/mastodon/components/hashtag_bar.tsx index 91fa9221983a70..2fcbabdd6c9d41 100644 --- a/app/javascript/mastodon/components/hashtag_bar.tsx +++ b/app/javascript/mastodon/components/hashtag_bar.tsx @@ -196,9 +196,14 @@ export function getHashtagBarForStatus(status: StatusLike) { }; } +export function getFeaturedHashtagBar(acct: string, tags: string[]) { + return ; +} + const HashtagBar: React.FC<{ hashtags: string[]; -}> = ({ hashtags }) => { + acct?: string; +}> = ({ hashtags, acct }) => { const [expanded, setExpanded] = useState(false); const handleClick = useCallback(() => { setExpanded(true); @@ -215,7 +220,10 @@ const HashtagBar: React.FC<{ return (
{revealedHashtags.map((hashtag) => ( - + #{hashtag} ))} diff --git a/app/javascript/mastodon/features/account/components/header.jsx b/app/javascript/mastodon/features/account/components/header.jsx index b4c354d34aad5e..1f96a8ec40378f 100644 --- a/app/javascript/mastodon/features/account/components/header.jsx +++ b/app/javascript/mastodon/features/account/components/header.jsx @@ -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'; @@ -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, @@ -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; @@ -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); } @@ -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 = []; @@ -472,6 +490,12 @@ class Header extends ImmutablePureComponent { {account.get('note').length > 0 && account.get('note') !== '

' &&
} + {featuredTagsArr.length > 0 && ( +
+ {featuredTags} +
+ )} +
diff --git a/app/javascript/mastodon/features/account_timeline/components/header.jsx b/app/javascript/mastodon/features/account_timeline/components/header.jsx index ee46b876f62507..8a99a3991f429f 100644 --- a/app/javascript/mastodon/features/account_timeline/components/header.jsx +++ b/app/javascript/mastodon/features/account_timeline/components/header.jsx @@ -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, @@ -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; @@ -136,6 +137,7 @@ class Header extends ImmutablePureComponent { { account: getAccount(state, accountId), domain: state.getIn(['meta', 'domain']), hidden: getAccountHidden(state, accountId), + featuredTags: state.getIn(['user_lists', 'featured_tags', accountId, 'items']), }); return mapStateToProps; From 7110b922cb954633baaa69908d31cb8d8e259ae7 Mon Sep 17 00:00:00 2001 From: KMY Date: Wed, 27 Mar 2024 18:16:41 +0900 Subject: [PATCH 2/2] =?UTF-8?q?=E3=83=8F=E3=83=83=E3=82=B7=E3=83=A5?= =?UTF-8?q?=E3=82=BF=E3=82=B0=E3=82=92=E9=9A=A0=E3=81=95=E3=81=AA=E3=81=84?= =?UTF-8?q?=E3=82=88=E3=81=86=E4=BF=AE=E6=AD=A3?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- app/javascript/mastodon/components/hashtag_bar.tsx | 14 ++++++++------ 1 file changed, 8 insertions(+), 6 deletions(-) diff --git a/app/javascript/mastodon/components/hashtag_bar.tsx b/app/javascript/mastodon/components/hashtag_bar.tsx index 2fcbabdd6c9d41..e8f3126bdec4c7 100644 --- a/app/javascript/mastodon/components/hashtag_bar.tsx +++ b/app/javascript/mastodon/components/hashtag_bar.tsx @@ -197,13 +197,14 @@ export function getHashtagBarForStatus(status: StatusLike) { } export function getFeaturedHashtagBar(acct: string, tags: string[]) { - return ; + return ; } const HashtagBar: React.FC<{ hashtags: string[]; acct?: string; -}> = ({ hashtags, acct }) => { + defaultExpanded?: boolean; +}> = ({ hashtags, acct, defaultExpanded }) => { const [expanded, setExpanded] = useState(false); const handleClick = useCallback(() => { setExpanded(true); @@ -213,9 +214,10 @@ 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 (
@@ -228,7 +230,7 @@ const HashtagBar: React.FC<{ ))} - {!expanded && hashtags.length > VISIBLE_HASHTAGS && ( + {!expanded && !defaultExpanded && hashtags.length > VISIBLE_HASHTAGS && (