mirror of
https://github.com/tooot-app/app
synced 2025-06-05 22:19:13 +02:00
Fixed #19
This commit is contained in:
@ -11,7 +11,7 @@ const queryFunction = ({ queryKey }: { queryKey: QueryKey }) => {
|
||||
method: 'get',
|
||||
instance: 'local',
|
||||
url: `accounts/${id}`
|
||||
})
|
||||
}).then(res => res.body)
|
||||
}
|
||||
|
||||
const useAccountQuery = <TData = Mastodon.Account>({
|
||||
|
@ -19,7 +19,7 @@ const queryFunction = async ({ queryKey }: { queryKey: QueryKey }) => {
|
||||
instance: 'local',
|
||||
localIndex: index,
|
||||
url: `accounts/${id}`
|
||||
})
|
||||
}).then(res => res.body)
|
||||
}
|
||||
|
||||
const useAccountCheckQuery = <TData = Mastodon.Account>({
|
||||
|
@ -21,7 +21,7 @@ const queryFunction = ({ queryKey }: { queryKey: QueryKeyAnnouncement }) => {
|
||||
with_dismissed: 'true'
|
||||
}
|
||||
})
|
||||
})
|
||||
}).then(res => res.body)
|
||||
}
|
||||
|
||||
const useAnnouncementQuery = <TData = Mastodon.Announcement[]>({
|
||||
|
@ -25,7 +25,7 @@ const queryFunction = ({ queryKey }: { queryKey: QueryKey }) => {
|
||||
instanceDomain,
|
||||
url: `apps`,
|
||||
body: formData
|
||||
})
|
||||
}).then(res => res.body)
|
||||
}
|
||||
|
||||
const useAppsQuery = <TData = Mastodon.Apps>({
|
||||
|
@ -9,7 +9,7 @@ const queryFunction = () => {
|
||||
method: 'get',
|
||||
instance: 'local',
|
||||
url: 'custom_emojis'
|
||||
})
|
||||
}).then(res => res.body)
|
||||
}
|
||||
|
||||
const useEmojisQuery = <TData = Mastodon.Emoji[]>({
|
||||
|
@ -12,7 +12,7 @@ const queryFunction = ({ queryKey }: { queryKey: QueryKey }) => {
|
||||
instance: 'remote',
|
||||
instanceDomain,
|
||||
url: `instance`
|
||||
})
|
||||
}).then(res => res.body)
|
||||
}
|
||||
|
||||
const useInstanceQuery = <
|
||||
|
@ -9,7 +9,7 @@ const queryFunction = () => {
|
||||
method: 'get',
|
||||
instance: 'local',
|
||||
url: 'lists'
|
||||
})
|
||||
}).then(res => res.body)
|
||||
}
|
||||
|
||||
const useListsQuery = <TData = Mastodon.List[]>({
|
||||
|
@ -22,7 +22,7 @@ const queryFunction = ({ queryKey }: { queryKey: QueryKeyRelationship }) => {
|
||||
params: {
|
||||
'id[]': id
|
||||
}
|
||||
})
|
||||
}).then(res => res.body)
|
||||
}
|
||||
|
||||
const useRelationshipQuery = ({
|
||||
@ -61,7 +61,7 @@ const mutationFunction = async (params: MutationVarsRelationship) => {
|
||||
method: 'post',
|
||||
instance: 'local',
|
||||
url: `follow_requests/${params.id}/${params.payload.action}`
|
||||
})
|
||||
}).then(res => res.body)
|
||||
case 'outgoing':
|
||||
return client<Mastodon.Relationship>({
|
||||
method: 'post',
|
||||
@ -69,7 +69,7 @@ const mutationFunction = async (params: MutationVarsRelationship) => {
|
||||
url: `accounts/${params.id}/${params.payload.state ? 'un' : ''}${
|
||||
params.payload.action
|
||||
}`
|
||||
})
|
||||
}).then(res => res.body)
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -12,18 +12,10 @@ const queryFunction = ({
|
||||
pageParam
|
||||
}: {
|
||||
queryKey: QueryKey
|
||||
pageParam?: { direction: 'next'; id: Mastodon.Status['id'] }
|
||||
pageParam?: { [key: string]: string }
|
||||
}) => {
|
||||
const { type, id } = queryKey[1]
|
||||
let params: { [key: string]: string } = {}
|
||||
|
||||
if (pageParam) {
|
||||
switch (pageParam.direction) {
|
||||
case 'next':
|
||||
params.max_id = pageParam.id
|
||||
break
|
||||
}
|
||||
}
|
||||
let params: { [key: string]: string } = { ...pageParam }
|
||||
|
||||
return client<Mastodon.Account[]>({
|
||||
method: 'get',
|
||||
@ -37,7 +29,14 @@ const useRelationshipsQuery = <TData = Mastodon.Account[]>({
|
||||
options,
|
||||
...queryKeyParams
|
||||
}: QueryKey[1] & {
|
||||
options?: UseInfiniteQueryOptions<Mastodon.Account[], AxiosError, TData>
|
||||
options?: UseInfiniteQueryOptions<
|
||||
{
|
||||
body: Mastodon.Account[]
|
||||
links?: { prev?: string; next?: string }
|
||||
},
|
||||
AxiosError,
|
||||
TData
|
||||
>
|
||||
}) => {
|
||||
const queryKey: QueryKey = ['Relationships', { ...queryKeyParams }]
|
||||
return useInfiniteQuery(queryKey, queryFunction, options)
|
||||
|
@ -25,7 +25,7 @@ const queryFunction = ({ queryKey }: { queryKey: QueryKey }) => {
|
||||
instance: 'local',
|
||||
url: 'search',
|
||||
params: { ...(type && { type }), ...(term && { q: term }), limit }
|
||||
})
|
||||
}).then(res => res.body)
|
||||
}
|
||||
|
||||
const useSearchQuery = <TData = SearchResult>({
|
||||
|
@ -28,29 +28,10 @@ const queryFunction = ({
|
||||
pageParam
|
||||
}: {
|
||||
queryKey: QueryKeyTimeline
|
||||
pageParam?: { direction: 'prev' | 'next'; id: Mastodon.Status['id'] }
|
||||
pageParam?: { [key: string]: string }
|
||||
}) => {
|
||||
const { page, account, hashtag, list, toot } = queryKey[1]
|
||||
let params: { [key: string]: string } = {}
|
||||
|
||||
if (pageParam) {
|
||||
switch (pageParam.direction) {
|
||||
case 'prev':
|
||||
if (page === 'Bookmarks' || page === 'Favourites') {
|
||||
params.max_id = pageParam.id
|
||||
} else {
|
||||
params.min_id = pageParam.id
|
||||
}
|
||||
break
|
||||
case 'next':
|
||||
if (page === 'Bookmarks' || page === 'Favourites') {
|
||||
params.min_id = pageParam.id
|
||||
} else {
|
||||
params.max_id = pageParam.id
|
||||
}
|
||||
break
|
||||
}
|
||||
}
|
||||
let params: { [key: string]: string } = { ...pageParam }
|
||||
|
||||
switch (page) {
|
||||
case 'Following':
|
||||
@ -89,7 +70,7 @@ const queryFunction = ({
|
||||
})
|
||||
|
||||
case 'Account_Default':
|
||||
if (pageParam && pageParam.direction === 'next') {
|
||||
if (pageParam && pageParam.pointer === 'max_id') {
|
||||
return client<Mastodon.Status[]>({
|
||||
method: 'get',
|
||||
instance: 'local',
|
||||
@ -108,10 +89,8 @@ const queryFunction = ({
|
||||
pinned: 'true'
|
||||
}
|
||||
}).then(async res1 => {
|
||||
let toots = res1.map(status => {
|
||||
status.isPinned = true
|
||||
return status
|
||||
})
|
||||
let pinned: Mastodon.Status['id'][] = []
|
||||
res1.body.forEach(status => pinned.push(status.id))
|
||||
const res2 = await client<Mastodon.Status[]>({
|
||||
method: 'get',
|
||||
instance: 'local',
|
||||
@ -120,7 +99,11 @@ const queryFunction = ({
|
||||
exclude_replies: 'true'
|
||||
}
|
||||
})
|
||||
return uniqBy([...toots, ...res2], 'id')
|
||||
return {
|
||||
body: uniqBy([...res1.body, ...res2.body], 'id'),
|
||||
...(res2.links.next && { links: { max_id: res2.links.next } }),
|
||||
pinned
|
||||
}
|
||||
})
|
||||
}
|
||||
|
||||
@ -197,7 +180,9 @@ const queryFunction = ({
|
||||
instance: 'local',
|
||||
url: `statuses/${toot}/context`
|
||||
})
|
||||
return [...res2.ancestors, res1, ...res2.descendants]
|
||||
return {
|
||||
body: [...res2.body.ancestors, res1.body, ...res2.body.descendants]
|
||||
}
|
||||
})
|
||||
default:
|
||||
return Promise.reject()
|
||||
@ -210,7 +195,18 @@ const useTimelineQuery = <TData = TimelineData>({
|
||||
options,
|
||||
...queryKeyParams
|
||||
}: QueryKeyTimeline[1] & {
|
||||
options?: UseInfiniteQueryOptions<any, AxiosError, TData>
|
||||
options?: UseInfiniteQueryOptions<
|
||||
{
|
||||
body:
|
||||
| Mastodon.Status[]
|
||||
| Mastodon.Notification[]
|
||||
| Mastodon.Conversation[]
|
||||
links?: { prev?: string; next?: string }
|
||||
pinned?: Mastodon.Status['id'][]
|
||||
},
|
||||
AxiosError,
|
||||
TData
|
||||
>
|
||||
}) => {
|
||||
const queryKey: QueryKeyTimeline = ['Timeline', { ...queryKeyParams }]
|
||||
return useInfiniteQuery(queryKey, queryFunction, options)
|
||||
@ -354,7 +350,7 @@ const mutationFunction = async (params: MutationVarsTimeline) => {
|
||||
}
|
||||
|
||||
type MutationOptionsTimeline = MutationOptions<
|
||||
Mastodon.Conversation | Mastodon.Notification | Mastodon.Status,
|
||||
{ body: Mastodon.Conversation | Mastodon.Notification | Mastodon.Status },
|
||||
AxiosError,
|
||||
MutationVarsTimeline
|
||||
>
|
||||
@ -373,7 +369,7 @@ const useTimelineMutation = ({
|
||||
onSuccess?: MutationOptionsTimeline['onSuccess'] | boolean
|
||||
}) => {
|
||||
return useMutation<
|
||||
Mastodon.Conversation | Mastodon.Notification | Mastodon.Status,
|
||||
{ body: Mastodon.Conversation | Mastodon.Notification | Mastodon.Status },
|
||||
AxiosError,
|
||||
MutationVarsTimeline
|
||||
>(mutationFunction, {
|
||||
|
@ -1,5 +1,5 @@
|
||||
import { InfiniteData, QueryClient } from 'react-query'
|
||||
import { QueryKeyTimeline } from '../timeline'
|
||||
import { QueryKeyTimeline, TimelineData } from '../timeline'
|
||||
|
||||
const deleteItem = ({
|
||||
queryClient,
|
||||
@ -10,16 +10,15 @@ const deleteItem = ({
|
||||
queryKey: QueryKeyTimeline
|
||||
id: Mastodon.Status['id']
|
||||
}) => {
|
||||
queryClient.setQueryData<InfiniteData<Mastodon.Conversation[]> | undefined>(
|
||||
queryKey,
|
||||
old => {
|
||||
if (old) {
|
||||
old.pages = old.pages.map(page => page.filter(item => item.id !== id))
|
||||
}
|
||||
|
||||
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
|
||||
}
|
||||
)
|
||||
})
|
||||
}
|
||||
|
||||
export default deleteItem
|
||||
|
@ -32,9 +32,10 @@ const updateStatusProperty = ({
|
||||
return page
|
||||
} else {
|
||||
if (
|
||||
typeof (page as Mastodon.Conversation[])[0].unread === 'boolean'
|
||||
typeof (page.body as Mastodon.Conversation[])[0].unread ===
|
||||
'boolean'
|
||||
) {
|
||||
const items = page as Mastodon.Conversation[]
|
||||
const items = page.body as Mastodon.Conversation[]
|
||||
const tootIndex = findIndex(items, ['last_status.id', id])
|
||||
if (tootIndex >= 0) {
|
||||
foundToot = true
|
||||
@ -42,16 +43,16 @@ const updateStatusProperty = ({
|
||||
}
|
||||
return page
|
||||
} else if (
|
||||
typeof (page as Mastodon.Notification[])[0].type === 'string'
|
||||
typeof (page.body as Mastodon.Notification[])[0].type === 'string'
|
||||
) {
|
||||
const items = page as Mastodon.Notification[]
|
||||
const items = page.body as Mastodon.Notification[]
|
||||
const tootIndex = findIndex(items, ['status.id', id])
|
||||
if (tootIndex >= 0) {
|
||||
foundToot = true
|
||||
updateNotification({ item: items[tootIndex], payload })
|
||||
}
|
||||
} else {
|
||||
const items = page as Mastodon.Status[]
|
||||
const items = page.body as Mastodon.Status[]
|
||||
const tootIndex = findIndex(items, [
|
||||
reblog ? 'reblog.id' : 'id',
|
||||
id
|
||||
|
Reference in New Issue
Block a user