2023-06-01 00:44:06 +00:00
|
|
|
import { useMutation } from '@apollo/client'
|
2023-07-23 15:08:43 +00:00
|
|
|
import { gql } from 'graphql-tag'
|
2023-07-24 18:35:05 +00:00
|
|
|
import Dropdown from 'react-bootstrap/Dropdown'
|
2023-06-01 00:44:06 +00:00
|
|
|
|
|
|
|
export default function SubscribeDropdownItem ({ item: { id, meSubscription } }) {
|
|
|
|
const [subscribeItem] = useMutation(
|
|
|
|
gql`
|
|
|
|
mutation subscribeItem($id: ID!) {
|
|
|
|
subscribeItem(id: $id) {
|
|
|
|
meSubscription
|
|
|
|
}
|
|
|
|
}`, {
|
|
|
|
update (cache, { data: { subscribeItem } }) {
|
|
|
|
cache.modify({
|
|
|
|
id: `Item:${id}`,
|
|
|
|
fields: {
|
|
|
|
meSubscription: () => subscribeItem.meSubscription
|
|
|
|
}
|
|
|
|
})
|
|
|
|
}
|
|
|
|
}
|
|
|
|
)
|
|
|
|
return (
|
|
|
|
<Dropdown.Item
|
|
|
|
onClick={() => subscribeItem({ variables: { id } })}
|
|
|
|
>
|
|
|
|
{meSubscription ? 'remove subscription' : 'subscribe'}
|
|
|
|
</Dropdown.Item>
|
|
|
|
)
|
|
|
|
}
|