2022-09-21 14:57:36 -05:00
|
|
|
import { gql, useMutation } from '@apollo/client'
|
2023-07-24 13:35:05 -05:00
|
|
|
import Dropdown from 'react-bootstrap/Dropdown'
|
2023-01-10 17:13:37 -06:00
|
|
|
import { useShowModal } from './modal'
|
2023-08-25 19:21:51 -04:00
|
|
|
import { useToast } from './toast'
|
2023-09-13 21:08:03 -05:00
|
|
|
import ItemAct from './item-act'
|
2022-09-21 14:57:36 -05:00
|
|
|
|
2023-02-16 23:23:59 +01:00
|
|
|
export default function DontLikeThisDropdownItem ({ id }) {
|
2023-08-25 19:21:51 -04:00
|
|
|
const toaster = useToast()
|
2023-01-10 17:13:37 -06:00
|
|
|
const showModal = useShowModal()
|
2022-09-21 14:57:36 -05:00
|
|
|
|
|
|
|
const [dontLikeThis] = useMutation(
|
|
|
|
gql`
|
2023-09-13 21:08:03 -05:00
|
|
|
mutation dontLikeThis($id: ID!, $sats: Int, $hash: String, $hmac: String) {
|
|
|
|
dontLikeThis(id: $id, sats: $sats, hash: $hash, hmac: $hmac)
|
2022-09-21 14:57:36 -05:00
|
|
|
}`, {
|
|
|
|
update (cache) {
|
|
|
|
cache.modify({
|
|
|
|
id: `Item:${id}`,
|
|
|
|
fields: {
|
|
|
|
meDontLike () {
|
|
|
|
return true
|
|
|
|
}
|
|
|
|
}
|
|
|
|
})
|
|
|
|
}
|
|
|
|
}
|
|
|
|
)
|
|
|
|
|
|
|
|
return (
|
2023-02-16 23:23:59 +01:00
|
|
|
<Dropdown.Item
|
|
|
|
onClick={async () => {
|
|
|
|
try {
|
2023-09-13 21:08:03 -05:00
|
|
|
showModal(onClose =>
|
|
|
|
<ItemAct
|
|
|
|
onClose={() => {
|
|
|
|
onClose()
|
|
|
|
toaster.success('item flagged')
|
|
|
|
}} itemId={id} act={dontLikeThis} down
|
|
|
|
/>)
|
2023-02-16 23:23:59 +01:00
|
|
|
} catch (error) {
|
2023-10-06 15:01:51 -05:00
|
|
|
toaster.danger('failed to flag item')
|
2023-02-16 23:23:59 +01:00
|
|
|
}
|
|
|
|
}}
|
|
|
|
>
|
|
|
|
flag
|
|
|
|
</Dropdown.Item>
|
2022-09-21 14:57:36 -05:00
|
|
|
)
|
|
|
|
}
|