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

48 lines
1.0 KiB
TypeScript
Raw Normal View History

2022-01-26 20:03:32 +00:00
import clsx from 'clsx'
import { Fold } from '../../common/fold'
import { useFollowingFold } from '../hooks/use-fold'
import { useUser } from '../hooks/use-user'
import { followFold, unfollowFold } from '../lib/firebase/folds'
export function FollowFoldButton(props: { fold: Fold; className?: string }) {
const { fold, className } = props
const user = useUser()
const following = useFollowingFold(fold, user)
const onFollow = () => {
if (user) followFold(fold, user)
}
const onUnfollow = () => {
if (user) unfollowFold(fold, user)
}
if (!user || following === undefined)
return (
<button className={clsx('btn btn-sm invisible', className)}>
Follow
</button>
)
if (following) {
return (
<button
2022-01-27 06:38:22 +00:00
className={clsx('btn btn-outline btn-sm', className)}
2022-01-26 20:03:32 +00:00
onClick={onUnfollow}
>
Following
</button>
)
}
return (
<button
className={clsx('btn btn-secondary bg-indigo-500 btn-sm', className)}
onClick={onFollow}
>
Follow
</button>
)
}