2021-05-12 15:40:55 +02:00
|
|
|
import queryClient from '@helpers/queryClient'
|
2021-03-25 00:25:37 +01:00
|
|
|
import { InfiniteData } from 'react-query'
|
2021-02-13 01:26:02 +01:00
|
|
|
import { MutationVarsTimelineDeleteItem } from '../timeline'
|
2021-01-11 21:36:57 +01:00
|
|
|
|
|
|
|
const deleteItem = ({
|
|
|
|
queryKey,
|
2021-02-13 01:26:02 +01:00
|
|
|
rootQueryKey,
|
2021-01-11 21:36:57 +01:00
|
|
|
id
|
|
|
|
}: {
|
2021-02-13 01:26:02 +01:00
|
|
|
queryKey?: MutationVarsTimelineDeleteItem['queryKey']
|
|
|
|
rootQueryKey?: MutationVarsTimelineDeleteItem['rootQueryKey']
|
|
|
|
id: MutationVarsTimelineDeleteItem['id']
|
2021-01-11 21:36:57 +01:00
|
|
|
}) => {
|
2021-02-13 01:26:02 +01:00
|
|
|
queryKey &&
|
|
|
|
queryClient.setQueryData<InfiniteData<any> | undefined>(queryKey, old => {
|
|
|
|
if (old) {
|
|
|
|
old.pages = old.pages.map(page => {
|
|
|
|
page.body = page.body.filter(
|
|
|
|
(item: Mastodon.Status) => item.id !== id
|
|
|
|
)
|
|
|
|
return page
|
|
|
|
})
|
|
|
|
return old
|
|
|
|
}
|
|
|
|
})
|
|
|
|
|
|
|
|
rootQueryKey &&
|
|
|
|
queryClient.setQueryData<InfiniteData<any> | undefined>(
|
|
|
|
rootQueryKey,
|
|
|
|
old => {
|
|
|
|
if (old) {
|
|
|
|
old.pages = old.pages.map(page => {
|
|
|
|
page.body = page.body.filter(
|
|
|
|
(item: Mastodon.Status) => item.id !== id
|
|
|
|
)
|
|
|
|
return page
|
|
|
|
})
|
|
|
|
return old
|
|
|
|
}
|
|
|
|
}
|
|
|
|
)
|
2021-01-11 21:36:57 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
export default deleteItem
|