From ef8278ae300740e459a485ebb452e763f2498957 Mon Sep 17 00:00:00 2001 From: AkiraFukushima Date: Mon, 2 Sep 2024 22:00:18 +0900 Subject: [PATCH] refs #4754 Add follow/unfollow tag button --- locales/en/translation.json | 4 ++- renderer/components/detail/Detail.tsx | 52 ++++++++++++++++++++++++++- 2 files changed, 54 insertions(+), 2 deletions(-) diff --git a/locales/en/translation.json b/locales/en/translation.json index c3f4e282..0e73783e 100644 --- a/locales/en/translation.json +++ b/locales/en/translation.json @@ -150,7 +150,9 @@ }, "detail": { "back": "Back", - "close": "Close" + "close": "Close", + "follow_tag": "Follow hashtag", + "unfollow_tag": "Unfollow hashtag" }, "profile": { "follow": "Follow", diff --git a/renderer/components/detail/Detail.tsx b/renderer/components/detail/Detail.tsx index e2cf593f..a6ac8eeb 100644 --- a/renderer/components/detail/Detail.tsx +++ b/renderer/components/detail/Detail.tsx @@ -1,6 +1,6 @@ import { useRouter } from 'next/router' import { HTMLAttributes, useEffect, useState } from 'react' -import { FaChevronLeft, FaX } from 'react-icons/fa6' +import { FaChevronLeft, FaUserPlus, FaUserXmark, FaX } from 'react-icons/fa6' import Thread from './Thread' import { Entity, MegalodonInterface } from 'megalodon' import Reply from './Reply' @@ -19,6 +19,7 @@ export default function Detail(props: Props) { const [target, setTarget] = useState<'status' | 'reply' | 'profile' | 'tag' | null>(null) const router = useRouter() const { formatMessage } = useIntl() + const [tagFollowing, setTagFollowing] = useState(false) useEffect(() => { if (router.query.status_id) { @@ -34,6 +35,23 @@ export default function Detail(props: Props) { } }, [router.query]) + useEffect(() => { + if (router.query.tag) { + refreshFollowing(router.query.tag as string) + } else { + setTagFollowing(false) + } + }, [router.query.tag]) + + const refreshFollowing = async (tag: string) => { + const res = await props.client.getTag(tag) + if (res.data.following) { + setTagFollowing(true) + } else { + setTagFollowing(false) + } + } + const back = () => { router.back() } @@ -42,6 +60,16 @@ export default function Detail(props: Props) { router.push({ query: { id: router.query.id, timeline: router.query.timeline } }) } + const followTag = async (tag: string) => { + await props.client.followTag(tag) + await refreshFollowing(tag) + } + + const unfollowTag = async (tag: string) => { + await props.client.unfollowTag(tag) + await refreshFollowing(tag) + } + return ( <> {target && ( @@ -54,6 +82,28 @@ export default function Detail(props: Props) { {target === 'tag' && `#${router.query.tag}`}
+ {target === 'tag' && ( + <> + {tagFollowing ? ( + + ) : ( + + )} + + )} +