stacker.news/components/dont-link-this.js

48 lines
1.0 KiB
JavaScript
Raw Normal View History

2022-09-21 19:57:36 +00:00
import { gql, useMutation } from '@apollo/client'
import { Dropdown } from 'react-bootstrap'
import FundError from './fund-error'
import { useShowModal } from './modal'
2022-09-21 19:57:36 +00:00
export default function DontLikeThisDropdownItem ({ id }) {
const showModal = useShowModal()
2022-09-21 19:57:36 +00:00
const [dontLikeThis] = useMutation(
gql`
mutation dontLikeThis($id: ID!) {
dontLikeThis(id: $id)
}`, {
update (cache) {
cache.modify({
id: `Item:${id}`,
fields: {
meDontLike () {
return true
}
}
})
}
}
)
return (
<Dropdown.Item
onClick={async () => {
try {
await dontLikeThis({
variables: { id },
optimisticResponse: { dontLikeThis: true }
})
} catch (error) {
if (error.toString().includes('insufficient funds')) {
showModal(onClose => {
return <FundError onClose={onClose} />
})
}
}
}}
>
flag
</Dropdown.Item>
2022-09-21 19:57:36 +00:00
)
}