1
0
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:
xmflsct
2023-01-04 22:39:29 +01:00
parent 62a6594f91
commit 06324ee51a
34 changed files with 278 additions and 346 deletions

View File

@ -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