import { CheckCircleIcon, PlusCircleIcon } from '@heroicons/react/solid' import clsx from 'clsx' import { useEffect, useRef, useState } from 'react' import { useFollows } from 'web/hooks/use-follows' import { useUser } from 'web/hooks/use-user' import { follow, unfollow } from 'web/lib/firebase/users' import { withTracking } from 'web/lib/service/analytics' export function FollowButton(props: { isFollowing: boolean | undefined onFollow: () => void onUnfollow: () => void small?: boolean className?: string }) { const { isFollowing, onFollow, onUnfollow, small, className } = props const user = useUser() const smallStyle = 'btn !btn-xs border-2 border-gray-500 bg-white normal-case text-gray-500 hover:border-gray-500 hover:bg-white hover:text-gray-500' if (!user || isFollowing === undefined) return ( ) if (isFollowing) { return ( ) } return ( ) } export function UserFollowButton(props: { userId: string; small?: boolean }) { const { userId, small } = props const user = useUser() const following = useFollows(user?.id) const isFollowing = following?.includes(userId) if (!user || user.id === userId) return null return ( follow(user.id, userId)} onUnfollow={() => unfollow(user.id, userId)} small={small} /> ) } export function MiniUserFollowButton(props: { userId: string }) { const { userId } = props const user = useUser() const following = useFollows(user?.id) const isFollowing = following?.includes(userId) const isFirstRender = useRef(true) const [justFollowed, setJustFollowed] = useState(false) useEffect(() => { if (isFirstRender.current) { if (isFollowing != undefined) { isFirstRender.current = false } return } if (isFollowing) { setJustFollowed(true) setTimeout(() => { setJustFollowed(false) }, 1000) } }, [isFollowing]) if (justFollowed) { return (