Use UserFollowButton instead of FollowButton in UserPage (#742)

This commit is contained in:
Marshall Polaris 2022-08-11 12:54:09 -07:00 committed by GitHub
parent ad75ecdc87
commit b9f347b7f4
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23

View File

@ -6,12 +6,7 @@ import { LinkIcon } from '@heroicons/react/solid'
import { PencilIcon } from '@heroicons/react/outline' import { PencilIcon } from '@heroicons/react/outline'
import Confetti from 'react-confetti' import Confetti from 'react-confetti'
import { import { getPortfolioHistory, User } from 'web/lib/firebase/users'
follow,
getPortfolioHistory,
unfollow,
User,
} from 'web/lib/firebase/users'
import { CreatorContractsList } from './contract/contracts-grid' import { CreatorContractsList } from './contract/contracts-grid'
import { SEO } from './SEO' import { SEO } from './SEO'
import { Page } from './page' import { Page } from './page'
@ -31,8 +26,7 @@ import { getContractFromId, listContracts } from 'web/lib/firebase/contracts'
import { LoadingIndicator } from './loading-indicator' import { LoadingIndicator } from './loading-indicator'
import { BetsList } from './bets-list' import { BetsList } from './bets-list'
import { FollowersButton, FollowingButton } from './following-button' import { FollowersButton, FollowingButton } from './following-button'
import { useFollows } from 'web/hooks/use-follows' import { UserFollowButton } from './follow-button'
import { FollowButton } from './follow-button'
import { PortfolioMetrics } from 'common/user' import { PortfolioMetrics } from 'common/user'
import { GroupsButton } from 'web/components/groups/groups-button' import { GroupsButton } from 'web/components/groups/groups-button'
import { PortfolioValueSection } from './portfolio/portfolio-value-section' import { PortfolioValueSection } from './portfolio/portfolio-value-section'
@ -120,19 +114,8 @@ export function UserPage(props: { user: User; currentUser?: User }) {
} }
}, [userBets, usersComments]) }, [userBets, usersComments])
const yourFollows = useFollows(currentUser?.id)
const isFollowing = yourFollows?.includes(user.id)
const profit = user.profitCached.allTime const profit = user.profitCached.allTime
const onFollow = () => {
if (!currentUser) return
follow(currentUser.id, user.id)
}
const onUnfollow = () => {
if (!currentUser) return
unfollow(currentUser.id, user.id)
}
return ( return (
<Page key={user.id}> <Page key={user.id}>
<SEO <SEO
@ -167,13 +150,7 @@ export function UserPage(props: { user: User; currentUser?: User }) {
{/* Top right buttons (e.g. edit, follow) */} {/* Top right buttons (e.g. edit, follow) */}
<div className="absolute right-0 top-0 mt-4 mr-4"> <div className="absolute right-0 top-0 mt-4 mr-4">
{!isCurrentUser && ( {!isCurrentUser && <UserFollowButton userId={user.id} />}
<FollowButton
isFollowing={isFollowing}
onFollow={onFollow}
onUnfollow={onUnfollow}
/>
)}
{isCurrentUser && ( {isCurrentUser && (
<SiteLink className="btn" href="/profile"> <SiteLink className="btn" href="/profile">
<PencilIcon className="h-5 w-5" />{' '} <PencilIcon className="h-5 w-5" />{' '}