2022-08-24 16:49:53 +00:00
|
|
|
import { Button } from 'web/components/button'
|
|
|
|
import {
|
|
|
|
Contract,
|
|
|
|
followContract,
|
|
|
|
unFollowContract,
|
|
|
|
} from 'web/lib/firebase/contracts'
|
|
|
|
import toast from 'react-hot-toast'
|
2022-08-24 21:09:28 +00:00
|
|
|
import { CheckIcon, EyeIcon, EyeOffIcon } from '@heroicons/react/outline'
|
2022-08-24 16:49:53 +00:00
|
|
|
import clsx from 'clsx'
|
|
|
|
import { User } from 'common/user'
|
|
|
|
import { useContractFollows } from 'web/hooks/use-follows'
|
|
|
|
import { firebaseLogin, updateUser } from 'web/lib/firebase/users'
|
|
|
|
import { track } from 'web/lib/service/analytics'
|
2022-09-12 16:34:56 +00:00
|
|
|
import { WatchMarketModal } from 'web/components/contract/watch-market-modal'
|
2022-08-24 16:49:53 +00:00
|
|
|
import { useState } from 'react'
|
2022-08-30 23:13:25 +00:00
|
|
|
import { Col } from 'web/components/layout/col'
|
2022-09-22 15:53:55 +00:00
|
|
|
import { Tooltip } from './tooltip'
|
2022-08-24 16:49:53 +00:00
|
|
|
|
|
|
|
export const FollowMarketButton = (props: {
|
|
|
|
contract: Contract
|
|
|
|
user: User | undefined | null
|
|
|
|
}) => {
|
|
|
|
const { contract, user } = props
|
|
|
|
const followers = useContractFollows(contract.id)
|
|
|
|
const [open, setOpen] = useState(false)
|
|
|
|
|
2022-09-22 15:53:55 +00:00
|
|
|
const watching = followers?.includes(user?.id ?? 'nope')
|
|
|
|
|
2022-08-24 16:49:53 +00:00
|
|
|
return (
|
2022-09-22 15:53:55 +00:00
|
|
|
<Tooltip
|
|
|
|
text={watching ? 'Unfollow' : 'Follow'}
|
|
|
|
placement="bottom"
|
|
|
|
noTap
|
|
|
|
noFade
|
2022-08-24 16:49:53 +00:00
|
|
|
>
|
2022-09-22 15:53:55 +00:00
|
|
|
<Button
|
|
|
|
size={'sm'}
|
|
|
|
color={'gray-white'}
|
|
|
|
onClick={async () => {
|
|
|
|
if (!user) return firebaseLogin()
|
|
|
|
if (followers?.includes(user.id)) {
|
|
|
|
await unFollowContract(contract.id, user.id)
|
|
|
|
toast("You'll no longer receive notifications from this market", {
|
|
|
|
icon: <CheckIcon className={'text-primary h-5 w-5'} />,
|
|
|
|
})
|
|
|
|
track('Unwatch Market', {
|
|
|
|
slug: contract.slug,
|
|
|
|
})
|
|
|
|
} else {
|
|
|
|
await followContract(contract.id, user.id)
|
|
|
|
toast("You'll now receive notifications from this market!", {
|
|
|
|
icon: <CheckIcon className={'text-primary h-5 w-5'} />,
|
|
|
|
})
|
|
|
|
track('Watch Market', {
|
|
|
|
slug: contract.slug,
|
|
|
|
})
|
|
|
|
}
|
|
|
|
if (!user.hasSeenContractFollowModal) {
|
|
|
|
await updateUser(user.id, {
|
|
|
|
hasSeenContractFollowModal: true,
|
|
|
|
})
|
|
|
|
setOpen(true)
|
|
|
|
}
|
|
|
|
}}
|
|
|
|
>
|
|
|
|
{watching ? (
|
|
|
|
<Col className={'items-center gap-x-2 sm:flex-row'}>
|
|
|
|
<EyeOffIcon
|
|
|
|
className={clsx('h-5 w-5 sm:h-6 sm:w-6')}
|
|
|
|
aria-hidden="true"
|
|
|
|
/>
|
|
|
|
{/* Unwatch */}
|
|
|
|
</Col>
|
|
|
|
) : (
|
|
|
|
<Col className={'items-center gap-x-2 sm:flex-row'}>
|
|
|
|
<EyeIcon
|
|
|
|
className={clsx('h-5 w-5 sm:h-6 sm:w-6')}
|
|
|
|
aria-hidden="true"
|
|
|
|
/>
|
|
|
|
{/* Watch */}
|
|
|
|
</Col>
|
|
|
|
)}
|
|
|
|
<WatchMarketModal
|
|
|
|
open={open}
|
|
|
|
setOpen={setOpen}
|
|
|
|
title={`You ${
|
|
|
|
followers?.includes(user?.id ?? 'nope') ? 'watched' : 'unwatched'
|
|
|
|
} a question!`}
|
|
|
|
/>
|
|
|
|
</Button>
|
|
|
|
</Tooltip>
|
2022-08-24 16:49:53 +00:00
|
|
|
)
|
|
|
|
}
|