2022-05-09 13:04:36 +00:00
|
|
|
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'
|
2022-06-03 04:52:14 +00:00
|
|
|
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()
|
2022-02-21 05:12:35 +00:00
|
|
|
|
2022-03-31 05:35:20 +00:00
|
|
|
const followedFoldIds = useFollowedFoldIds(user)
|
2022-06-03 04:52:14 +00:00
|
|
|
const isFollowing = followedFoldIds
|
2022-02-21 05:12:35 +00:00
|
|
|
? followedFoldIds.includes(fold.id)
|
|
|
|
: undefined
|
2022-01-26 20:03:32 +00:00
|
|
|
|
|
|
|
const onFollow = () => {
|
2022-02-19 23:17:36 +00:00
|
|
|
if (user) followFold(fold.id, user.id)
|
2022-01-26 20:03:32 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
const onUnfollow = () => {
|
|
|
|
if (user) unfollowFold(fold, user)
|
|
|
|
}
|
|
|
|
|
|
|
|
return (
|
2022-06-03 04:52:14 +00:00
|
|
|
<FollowButton
|
|
|
|
isFollowing={isFollowing}
|
|
|
|
onFollow={onFollow}
|
|
|
|
onUnfollow={onUnfollow}
|
|
|
|
className={className}
|
|
|
|
/>
|
2022-01-26 20:03:32 +00:00
|
|
|
)
|
|
|
|
}
|