mirror of
https://github.com/tooot-app/app
synced 2025-06-05 22:19:13 +02:00
Basic editing works
This commit is contained in:
52
src/utils/queryHooks/timeline/editItem.ts
Normal file
52
src/utils/queryHooks/timeline/editItem.ts
Normal file
@ -0,0 +1,52 @@
|
||||
import queryClient from '@helpers/queryClient'
|
||||
import { InfiniteData } from 'react-query'
|
||||
import { MutationVarsTimelineEditItem } from '../timeline'
|
||||
|
||||
const editItem = ({
|
||||
queryKey,
|
||||
rootQueryKey,
|
||||
status
|
||||
}: MutationVarsTimelineEditItem) => {
|
||||
console.log('START')
|
||||
queryKey &&
|
||||
queryClient.setQueryData<InfiniteData<any> | undefined>(queryKey, old => {
|
||||
if (old) {
|
||||
old.pages = old.pages.map(page => {
|
||||
page.body = page.body.map((item: Mastodon.Status) => {
|
||||
if (item.id === status.id) {
|
||||
console.log('found queryKey', queryKey)
|
||||
console.log('new content', status.content)
|
||||
item = status
|
||||
}
|
||||
return item
|
||||
})
|
||||
return page
|
||||
})
|
||||
return old
|
||||
}
|
||||
})
|
||||
|
||||
rootQueryKey &&
|
||||
queryClient.setQueryData<InfiniteData<any> | undefined>(
|
||||
rootQueryKey,
|
||||
old => {
|
||||
if (old) {
|
||||
old.pages = old.pages.map(page => {
|
||||
page.body = page.body.map((item: Mastodon.Status) => {
|
||||
if (item.id === status.id) {
|
||||
console.log('found rootQueryKey', queryKey)
|
||||
console.log('new content', status.content)
|
||||
item = status
|
||||
}
|
||||
return item
|
||||
})
|
||||
return page
|
||||
})
|
||||
return old
|
||||
}
|
||||
}
|
||||
)
|
||||
console.log('EDN')
|
||||
}
|
||||
|
||||
export default editItem
|
Reference in New Issue
Block a user