import {StarIcon} from '@heroicons/react/24/outline' import clsx from 'clsx' import {Profile} from 'common/profiles/profile' import {useEffect, useState} from 'react' import {buttonClass} from 'web/components/buttons/button' import {Tooltip} from 'web/components/widgets/tooltip' import {api} from 'web/lib/api' import {useT} from 'web/lib/locale' import {track} from 'web/lib/service/analytics' export const StarButton = (props: { targetProfile: Profile isStarred: boolean refresh: () => Promise hideTooltip?: boolean className?: string }) => { const {targetProfile, refresh, hideTooltip, className} = props const targetId = targetProfile.user_id const [isStarred, setIsStarred] = useState(props.isStarred) const t = useT() useEffect(() => { setIsStarred(props.isStarred) }, [props.isStarred]) const star = async () => { setIsStarred(!isStarred) await api('star-profile', { targetUserId: targetId, remove: isStarred, }).catch(() => { setIsStarred(isStarred) }) track('star profile', { targetId, remove: isStarred, }) await refresh() } const button = ( ) if (hideTooltip) return button return ( {button} ) }