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:
@ -13,6 +13,7 @@ import {
|
||||
useMutation
|
||||
} from 'react-query'
|
||||
import deleteItem from './timeline/deleteItem'
|
||||
import editItem from './timeline/editItem'
|
||||
import updateStatusProperty from './timeline/updateStatusProperty'
|
||||
|
||||
export type QueryKeyTimeline = [
|
||||
@ -303,13 +304,21 @@ export type MutationVarsTimelineUpdateAccountProperty = {
|
||||
}
|
||||
}
|
||||
|
||||
export type MutationVarsTimelineEditItem = {
|
||||
// This is for editing status
|
||||
type: 'editItem'
|
||||
queryKey?: QueryKeyTimeline
|
||||
rootQueryKey?: QueryKeyTimeline
|
||||
status: Mastodon.Status
|
||||
}
|
||||
|
||||
export type MutationVarsTimelineDeleteItem = {
|
||||
// This is for deleting status and conversation
|
||||
type: 'deleteItem'
|
||||
source: 'statuses' | 'conversations'
|
||||
queryKey?: QueryKeyTimeline
|
||||
rootQueryKey?: QueryKeyTimeline
|
||||
id: Mastodon.Conversation['id']
|
||||
id: Mastodon.Status['id']
|
||||
}
|
||||
|
||||
export type MutationVarsTimelineDomainBlock = {
|
||||
@ -322,6 +331,7 @@ export type MutationVarsTimelineDomainBlock = {
|
||||
export type MutationVarsTimeline =
|
||||
| MutationVarsTimelineUpdateStatusProperty
|
||||
| MutationVarsTimelineUpdateAccountProperty
|
||||
| MutationVarsTimelineEditItem
|
||||
| MutationVarsTimelineDeleteItem
|
||||
| MutationVarsTimelineDomainBlock
|
||||
|
||||
@ -371,6 +381,8 @@ const mutationFunction = async (params: MutationVarsTimeline) => {
|
||||
}
|
||||
})
|
||||
}
|
||||
case 'editItem':
|
||||
return { body: params.status }
|
||||
case 'deleteItem':
|
||||
return apiInstance<Mastodon.Conversation>({
|
||||
method: 'delete',
|
||||
@ -423,6 +435,9 @@ const useTimelineMutation = ({
|
||||
case 'updateStatusProperty':
|
||||
updateStatusProperty(params)
|
||||
break
|
||||
case 'editItem':
|
||||
editItem(params)
|
||||
break
|
||||
case 'deleteItem':
|
||||
deleteItem(params)
|
||||
break
|
||||
|
@ -6,11 +6,7 @@ const deleteItem = ({
|
||||
queryKey,
|
||||
rootQueryKey,
|
||||
id
|
||||
}: {
|
||||
queryKey?: MutationVarsTimelineDeleteItem['queryKey']
|
||||
rootQueryKey?: MutationVarsTimelineDeleteItem['rootQueryKey']
|
||||
id: MutationVarsTimelineDeleteItem['id']
|
||||
}) => {
|
||||
}: MutationVarsTimelineDeleteItem) => {
|
||||
queryKey &&
|
||||
queryClient.setQueryData<InfiniteData<any> | undefined>(queryKey, old => {
|
||||
if (old) {
|
||||
|
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
|
@ -14,13 +14,7 @@ const updateStatusProperty = ({
|
||||
id,
|
||||
reblog,
|
||||
payload
|
||||
}: {
|
||||
queryKey: MutationVarsTimelineUpdateStatusProperty['queryKey']
|
||||
rootQueryKey?: MutationVarsTimelineUpdateStatusProperty['rootQueryKey']
|
||||
id: MutationVarsTimelineUpdateStatusProperty['id']
|
||||
reblog?: MutationVarsTimelineUpdateStatusProperty['reblog']
|
||||
payload: MutationVarsTimelineUpdateStatusProperty['payload']
|
||||
}) => {
|
||||
}: MutationVarsTimelineUpdateStatusProperty) => {
|
||||
queryClient.setQueryData<InfiniteData<TimelineData> | undefined>(
|
||||
queryKey,
|
||||
old => {
|
||||
|
Reference in New Issue
Block a user