manifold/web/components/folds/follow-fold-button.tsx

34 lines
844 B
TypeScript
Raw Normal View History

import { Fold } from 'common/fold'
import { useFollowedFoldIds } from 'web/hooks/use-fold'
import { useUser } from 'web/hooks/use-user'
import { followFold, unfollowFold } from 'web/lib/firebase/folds'
import { FollowButton } from '../follow-button'
2022-01-26 20:03:32 +00:00
export function FollowFoldButton(props: { fold: Fold; className?: string }) {
const { fold, className } = props
const user = useUser()
const followedFoldIds = useFollowedFoldIds(user)
const isFollowing = followedFoldIds
? followedFoldIds.includes(fold.id)
: undefined
2022-01-26 20:03:32 +00:00
const onFollow = () => {
if (user) followFold(fold.id, user.id)
2022-01-26 20:03:32 +00:00
}
const onUnfollow = () => {
if (user) unfollowFold(fold, user)
}
return (
<FollowButton
isFollowing={isFollowing}
onFollow={onFollow}
onUnfollow={onUnfollow}
className={className}
/>
2022-01-26 20:03:32 +00:00
)
}