Merge pull request #731 from omnivore-app/OMN-700

[OMN-700] - Add unsubscribe menu option for subscriptions
This commit is contained in:
Jackson Harper
2022-06-09 12:43:58 -07:00
committed by GitHub
4 changed files with 39 additions and 0 deletions

View File

@ -14,6 +14,7 @@ export type CardMenuDropdownAction =
| 'snooze'
| 'set-labels'
| 'showOriginal'
| 'unsubscribe'
type CardMenuProps = {
item: LibraryItemNode
@ -81,6 +82,14 @@ export function CardMenu(props: CardMenuProps): JSX.Element {
}}
title="Remove"
/>
{!!props.item.subscription && (
<DropdownOption
onSelect={() => {
props.actionHandler('unsubscribe')
}}
title="Unsubscribe"
/>
)}
</Dropdown>
)
}

View File

@ -13,6 +13,7 @@ export type LinkedItemCardAction =
| 'share'
| 'snooze'
| 'set-labels'
| 'unsubscribe'
export type LinkedItemCardProps = {
item: LibraryItemNode

View File

@ -296,6 +296,9 @@ export function HomeFeedContainer(props: HomeFeedContainerProps): JSX.Element {
case 'set-labels':
setLabelsTarget(item)
break
case 'unsubscribe':
performActionOnItem('unsubscribe', item)
break
}
}

View File

@ -5,6 +5,7 @@ import type { PageType, State } from '../fragments/articleFragment'
import { ContentReader } from '../fragments/articleFragment'
import { setLinkArchivedMutation } from '../mutations/setLinkArchivedMutation'
import { deleteLinkMutation } from '../mutations/deleteLinkMutation'
import { unsubscribeMutation } from '../mutations/unsubscribeMutation'
import { articleReadingProgressMutation } from '../mutations/articleReadingProgressMutation'
import { Label } from './../fragments/labelFragment'
import { showErrorToast, showSuccessToast } from '../../toastHelpers'
@ -35,6 +36,7 @@ type LibraryItemAction =
| 'mark-read'
| 'mark-unread'
| 'refresh'
| 'unsubscribe'
export type LibraryItemsData = {
search: LibraryItems
@ -76,6 +78,8 @@ export type LibraryItemNode = {
state: State
pageType: PageType
siteName?: string
subscription?: string,
readAt?: string
}
export type PageInfo = {
@ -127,6 +131,8 @@ export function useGetLibraryItemsQuery({
annotation
state
siteName
subscription
readAt
}
}
pageInfo {
@ -305,6 +311,26 @@ export function useGetLibraryItemsQuery({
readingProgressAnchorIndex: 0,
})
break
case 'unsubscribe':
if (!!item.node.subscription) {
updateData({
cursor: item.cursor,
node: {
...item.node,
subscription: undefined,
},
})
unsubscribeMutation(item.node.subscription).then((res) => {
if (res) {
showSuccessToast('Unsubscribed successfully', { position: 'bottom-right' })
} else {
showErrorToast('Error unsubscribing', {
position: 'bottom-right',
})
}
})
}
break
case 'refresh':
await mutate()
}