mirror of
https://github.com/tooot-app/app
synced 2025-06-05 22:19:13 +02:00
Fix remote prop not appended in all places
This commit is contained in:
23
src/utils/helpers/appendRemote.ts
Normal file
23
src/utils/helpers/appendRemote.ts
Normal file
@ -0,0 +1,23 @@
|
||||
// Central place appending _remote internal prop
|
||||
|
||||
export const appendRemote = {
|
||||
status: (status: Mastodon.Status) => ({
|
||||
...status,
|
||||
...(status.reblog && {
|
||||
reblog: {
|
||||
...status.reblog,
|
||||
account: appendRemote.account(status.reblog.account),
|
||||
mentions: appendRemote.mentions(status.reblog.mentions)
|
||||
}
|
||||
}),
|
||||
account: appendRemote.account(status.account),
|
||||
mentions: appendRemote.mentions(status.mentions),
|
||||
_remote: true
|
||||
}),
|
||||
account: (account: Mastodon.Account) => ({
|
||||
...account,
|
||||
_remote: true
|
||||
}),
|
||||
mentions: (mentions: Mastodon.Mention[]) =>
|
||||
mentions.map(mention => ({ ...mention, _remote: true }))
|
||||
}
|
@ -1,6 +1,7 @@
|
||||
import { QueryFunctionContext, useQuery, UseQueryOptions } from '@tanstack/react-query'
|
||||
import apiGeneral from '@utils/api/general'
|
||||
import apiInstance from '@utils/api/instance'
|
||||
import { appendRemote } from '@utils/helpers/appendRemote'
|
||||
import { urlMatcher } from '@utils/helpers/urlMatcher'
|
||||
import { AxiosError } from 'axios'
|
||||
import { searchLocalAccount } from './search'
|
||||
@ -34,14 +35,14 @@ const accountQueryFunction = async ({ queryKey }: QueryFunctionContext<QueryKeyA
|
||||
method: 'get',
|
||||
domain: domain,
|
||||
url: `api/v1/accounts/${id}`
|
||||
}).then(res => ({ ...res.body, _remote: true }))
|
||||
}).then(res => appendRemote.account(res.body))
|
||||
} else if (acct) {
|
||||
matchedAccount = await apiGeneral<Mastodon.Account>({
|
||||
method: 'get',
|
||||
domain: domain,
|
||||
url: 'api/v1/accounts/lookup',
|
||||
params: { acct }
|
||||
}).then(res => ({ ...res.body, _remote: true }))
|
||||
}).then(res => appendRemote.account(res.body))
|
||||
}
|
||||
} catch {}
|
||||
}
|
||||
|
@ -1,6 +1,7 @@
|
||||
import { QueryFunctionContext, useQuery, UseQueryOptions } from '@tanstack/react-query'
|
||||
import apiGeneral from '@utils/api/general'
|
||||
import apiInstance from '@utils/api/instance'
|
||||
import { appendRemote } from '@utils/helpers/appendRemote'
|
||||
import { urlMatcher } from '@utils/helpers/urlMatcher'
|
||||
import { AxiosError } from 'axios'
|
||||
import { searchLocalStatus } from './search'
|
||||
@ -26,7 +27,7 @@ const queryFunction = async ({ queryKey }: QueryFunctionContext<QueryKeyStatus>)
|
||||
method: 'get',
|
||||
domain,
|
||||
url: `api/v1/statuses/${id}`
|
||||
}).then(res => ({ ...res.body, _remote: true }))
|
||||
}).then(res => appendRemote.status(res.body))
|
||||
} catch {}
|
||||
}
|
||||
|
||||
|
@ -6,6 +6,7 @@ import {
|
||||
import apiGeneral from '@utils/api/general'
|
||||
import { PagedResponse } from '@utils/api/helpers'
|
||||
import apiInstance from '@utils/api/instance'
|
||||
import { appendRemote } from '@utils/helpers/appendRemote'
|
||||
import { urlMatcher } from '@utils/helpers/urlMatcher'
|
||||
import { TabSharedStackParamList } from '@utils/navigation/navigators'
|
||||
import { AxiosError } from 'axios'
|
||||
@ -54,7 +55,11 @@ const queryFunction = async ({ queryKey, pageParam }: QueryFunctionContext<Query
|
||||
url: `api/v1/accounts/${resLookup.body.id}/${page.type}`,
|
||||
params
|
||||
})
|
||||
return { ...res, remoteData: true }
|
||||
return {
|
||||
...res,
|
||||
body: res.body.map(account => appendRemote.account(account)),
|
||||
remoteData: true
|
||||
}
|
||||
} else {
|
||||
throw new Error()
|
||||
}
|
||||
|
Reference in New Issue
Block a user