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

49 lines
1.2 KiB
JavaScript
Raw Normal View History

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