manifold/web/components/folds/follow-fold-button.tsx
Marshall Polaris acc9c84e2e
More absolute imports (#156)
* Configure functions module to allow absolute imports

* Convert common imports in functions to be absolute

* Convert common imports in web to be absolute

* Convert lib imports in web to be absolute

* Convert hooks imports in web to be absolute

* Convert components imports in web to be absolute
2022-05-09 09:04:36 -04:00

49 lines
1.1 KiB
TypeScript

import clsx from 'clsx'
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'
export function FollowFoldButton(props: { fold: Fold; className?: string }) {
const { fold, className } = props
const user = useUser()
const followedFoldIds = useFollowedFoldIds(user)
const following = followedFoldIds
? followedFoldIds.includes(fold.id)
: undefined
const onFollow = () => {
if (user) followFold(fold.id, user.id)
}
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
className={clsx('btn btn-outline btn-sm', className)}
onClick={onUnfollow}
>
Following
</button>
)
}
return (
<button className={clsx('btn btn-sm', className)} onClick={onFollow}>
Follow
</button>
)
}