From c9a4fa867985bb7eeba8705b638f9875b0db86fb Mon Sep 17 00:00:00 2001 From: James Grugett Date: Wed, 8 Jun 2022 15:27:52 -0500 Subject: [PATCH] Add small follow button after creator name in market page --- web/components/contract/contract-details.tsx | 4 +- web/components/follow-button.tsx | 41 ++++++++++++++++++-- 2 files changed, 40 insertions(+), 5 deletions(-) diff --git a/web/components/contract/contract-details.tsx b/web/components/contract/contract-details.tsx index 438eb3ec..9f9c0936 100644 --- a/web/components/contract/contract-details.tsx +++ b/web/components/contract/contract-details.tsx @@ -23,6 +23,7 @@ import { Bet } from 'common/bet' import NewContractBadge from '../new-contract-badge' import { CATEGORY_LIST } from 'common/categories' import { TagsList } from '../tags-list' +import { UserFollowButton } from '../follow-button' export function MiscDetails(props: { contract: Contract @@ -103,7 +104,7 @@ export function ContractDetails(props: { disabled?: boolean }) { const { contract, bets, isCreator, disabled } = props - const { closeTime, creatorName, creatorUsername } = contract + const { closeTime, creatorName, creatorUsername, creatorId } = contract const { volumeLabel, resolvedDate } = contractMetrics(contract) return ( @@ -124,6 +125,7 @@ export function ContractDetails(props: { username={creatorUsername} /> )} + {!disabled && } {(!!closeTime || !!resolvedDate) && ( diff --git a/web/components/follow-button.tsx b/web/components/follow-button.tsx index f7acf7a9..a5214775 100644 --- a/web/components/follow-button.tsx +++ b/web/components/follow-button.tsx @@ -1,19 +1,27 @@ import clsx from 'clsx' +import { useFollows } from 'web/hooks/use-follows' import { useUser } from 'web/hooks/use-user' +import { follow, unfollow } from 'web/lib/firebase/users' export function FollowButton(props: { isFollowing: boolean | undefined onFollow: () => void onUnfollow: () => void + small?: boolean className?: string }) { - const { isFollowing, onFollow, onUnfollow, className } = props + const { isFollowing, onFollow, onUnfollow, small, className } = props const user = useUser() + const smallStyle = + 'btn !btn-xs border-2 border-gray-600 bg-white normal-case text-gray-600 hover:border-gray-600 hover:bg-white hover:text-gray-600' + if (!user || isFollowing === undefined) return ( - ) @@ -21,7 +29,11 @@ export function FollowButton(props: { if (isFollowing) { return ( ) } + +export function UserFollowButton(props: { userId: string; small?: boolean }) { + const { userId, small } = props + const currentUser = useUser() + const following = useFollows(currentUser?.id) + const isFollowing = following?.includes(userId) + + if (!currentUser) return null + + return ( + follow(currentUser.id, userId)} + onUnfollow={() => unfollow(currentUser.id, userId)} + small={small} + /> + ) +}