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'
|
|
|
|
import { FollowMarketModal } from 'web/components/contract/follow-market-modal'
|
|
|
|
import { useState } from 'react'
|
2022-08-24 21:09:28 +00:00
|
|
|
import { Row } from 'web/components/layout/row'
|
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)
|
|
|
|
|
|
|
|
return (
|
|
|
|
<Button
|
|
|
|
size={'lg'}
|
|
|
|
color={'gray-white'}
|
|
|
|
onClick={async () => {
|
|
|
|
if (!user) return firebaseLogin()
|
|
|
|
if (followers?.includes(user.id)) {
|
|
|
|
await unFollowContract(contract.id, user.id)
|
2022-08-24 21:09:28 +00:00
|
|
|
toast("You'll no longer receive notifications from this market", {
|
2022-08-24 16:49:53 +00:00
|
|
|
icon: <CheckIcon className={'text-primary h-5 w-5'} />,
|
|
|
|
})
|
|
|
|
track('Unfollow Market', {
|
|
|
|
slug: contract.slug,
|
|
|
|
})
|
|
|
|
} else {
|
|
|
|
await followContract(contract.id, user.id)
|
2022-08-24 21:09:28 +00:00
|
|
|
toast("You'll now receive notifications from this market!", {
|
2022-08-24 16:49:53 +00:00
|
|
|
icon: <CheckIcon className={'text-primary h-5 w-5'} />,
|
|
|
|
})
|
|
|
|
track('Follow Market', {
|
|
|
|
slug: contract.slug,
|
|
|
|
})
|
|
|
|
}
|
|
|
|
if (!user.hasSeenContractFollowModal) {
|
|
|
|
await updateUser(user.id, {
|
|
|
|
hasSeenContractFollowModal: true,
|
|
|
|
})
|
|
|
|
setOpen(true)
|
|
|
|
}
|
|
|
|
}}
|
|
|
|
>
|
|
|
|
{followers?.includes(user?.id ?? 'nope') ? (
|
2022-08-24 21:09:28 +00:00
|
|
|
<Row className={'gap-2'}>
|
2022-08-24 21:11:38 +00:00
|
|
|
<EyeOffIcon className={clsx('h-6 w-6')} aria-hidden="true" />
|
|
|
|
Unwatch
|
2022-08-24 21:09:28 +00:00
|
|
|
</Row>
|
2022-08-24 16:49:53 +00:00
|
|
|
) : (
|
2022-08-24 21:09:28 +00:00
|
|
|
<Row className={'gap-2'}>
|
2022-08-24 21:11:38 +00:00
|
|
|
<EyeIcon className={clsx('h-6 w-6')} aria-hidden="true" />
|
|
|
|
Watch
|
2022-08-24 21:09:28 +00:00
|
|
|
</Row>
|
2022-08-24 16:49:53 +00:00
|
|
|
)}
|
|
|
|
<FollowMarketModal
|
|
|
|
open={open}
|
|
|
|
setOpen={setOpen}
|
|
|
|
title={`You ${
|
|
|
|
followers?.includes(user?.id ?? 'nope') ? 'followed' : 'unfollowed'
|
|
|
|
} a question!`}
|
|
|
|
/>
|
|
|
|
</Button>
|
|
|
|
)
|
|
|
|
}
|