mirror of
https://github.com/tooot-app/app
synced 2025-06-05 22:19:13 +02:00
Believe #638 can be closed now!
This commit is contained in:
@ -1,29 +1,31 @@
|
||||
import { InfiniteData } from '@tanstack/react-query'
|
||||
import { queryClient } from '@utils/queryHooks'
|
||||
import { MutationVarsTimelineDeleteItem } from '../timeline'
|
||||
import { MutationVarsTimelineDeleteItem, QueryKeyTimeline, TimelineData } from '../timeline'
|
||||
|
||||
const deleteItem = ({ queryKey, rootQueryKey, id }: MutationVarsTimelineDeleteItem) => {
|
||||
queryKey &&
|
||||
queryClient.setQueryData<InfiniteData<any> | undefined>(queryKey, old => {
|
||||
const deleteItem = (
|
||||
{ id }: MutationVarsTimelineDeleteItem,
|
||||
navigationState: (QueryKeyTimeline | undefined)[]
|
||||
) => {
|
||||
for (const key of navigationState) {
|
||||
if (!key) continue
|
||||
|
||||
queryClient.setQueryData<InfiniteData<TimelineData> | undefined>(key, old => {
|
||||
if (old) {
|
||||
let foundToot: boolean = false
|
||||
old.pages = old.pages.map(page => {
|
||||
page.body = page.body.filter((item: Mastodon.Status) => item.id !== id)
|
||||
if (foundToot) return page
|
||||
|
||||
page.body = (page.body as Mastodon.Status[]).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
|
||||
}
|
||||
return old
|
||||
})
|
||||
}
|
||||
}
|
||||
|
||||
export default deleteItem
|
||||
|
Reference in New Issue
Block a user