mirror of
https://github.com/tooot-app/app
synced 2025-02-08 16:08:44 +01:00
Fix remote prop not appended in all places
This commit is contained in:
parent
8c87841fed
commit
e447a91cfb
@ -7,6 +7,7 @@ import TimelineDefault from '@components/Timeline/Default'
|
||||
import { useQuery } 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 { TabSharedStackScreenProps } from '@utils/navigation/navigators'
|
||||
import { queryClient } from '@utils/queryHooks'
|
||||
@ -206,26 +207,7 @@ const TabSharedToot: React.FC<TabSharedStackScreenProps<'Tab-Shared-Toot'>> = ({
|
||||
if (localMatch) {
|
||||
return localMatch
|
||||
} else {
|
||||
return {
|
||||
...ancestor,
|
||||
_remote: true,
|
||||
account: { ...ancestor.account, _remote: true },
|
||||
mentions: ancestor.mentions.map(mention => ({
|
||||
...mention,
|
||||
_remote: true
|
||||
})),
|
||||
...(ancestor.reblog && {
|
||||
reblog: {
|
||||
...ancestor.reblog,
|
||||
_remote: true,
|
||||
account: { ...ancestor.reblog.account, _remote: true },
|
||||
mentions: ancestor.reblog.mentions.map(mention => ({
|
||||
...mention,
|
||||
_remote: true
|
||||
}))
|
||||
}
|
||||
})
|
||||
}
|
||||
return appendRemote.status(ancestor)
|
||||
}
|
||||
})
|
||||
}
|
||||
@ -268,23 +250,7 @@ const TabSharedToot: React.FC<TabSharedStackScreenProps<'Tab-Shared-Toot'>> = ({
|
||||
if (localMatch) {
|
||||
return { ...localMatch, _level: remote._level }
|
||||
} else {
|
||||
return {
|
||||
...remote,
|
||||
_remote: true,
|
||||
account: { ...remote.account, _remote: true },
|
||||
mentions: remote.mentions.map(mention => ({ ...mention, _remote: true })),
|
||||
...(remote.reblog && {
|
||||
reblog: {
|
||||
...remote.reblog,
|
||||
_remote: true,
|
||||
account: { ...remote.reblog.account, _remote: true },
|
||||
mentions: remote.reblog.mentions.map(mention => ({
|
||||
...mention,
|
||||
_remote: true
|
||||
}))
|
||||
}
|
||||
})
|
||||
}
|
||||
return appendRemote.status(remote)
|
||||
}
|
||||
})
|
||||
}
|
||||
|
@ -4,14 +4,12 @@ import Icon from '@components/Icon'
|
||||
import { Loading } from '@components/Loading'
|
||||
import ComponentSeparator from '@components/Separator'
|
||||
import CustomText from '@components/Text'
|
||||
import apiInstance from '@utils/api/instance'
|
||||
import { TabSharedStackScreenProps } from '@utils/navigation/navigators'
|
||||
import { SearchResult } from '@utils/queryHooks/search'
|
||||
import { QueryKeyUsers, useUsersQuery } from '@utils/queryHooks/users'
|
||||
import { flattenPages } from '@utils/queryHooks/utils'
|
||||
import { StyleConstants } from '@utils/styles/constants'
|
||||
import { useTheme } from '@utils/styles/ThemeManager'
|
||||
import React, { useEffect, useState } from 'react'
|
||||
import React, { useEffect } from 'react'
|
||||
import { useTranslation } from 'react-i18next'
|
||||
import { View } from 'react-native'
|
||||
import { FlatList } from 'react-native-gesture-handler'
|
||||
@ -36,8 +34,6 @@ const TabSharedUsers: React.FC<TabSharedStackScreenProps<'Tab-Shared-Users'>> =
|
||||
...queryKey[1]
|
||||
})
|
||||
|
||||
const [isSearching, setIsSearching] = useState<number | null>(null)
|
||||
|
||||
return (
|
||||
<FlatList
|
||||
windowSize={7}
|
||||
@ -46,38 +42,10 @@ const TabSharedUsers: React.FC<TabSharedStackScreenProps<'Tab-Shared-Users'>> =
|
||||
minHeight: '100%',
|
||||
paddingVertical: StyleConstants.Spacing.Global.PagePadding
|
||||
}}
|
||||
renderItem={({ item, index }) => (
|
||||
renderItem={({ item }) => (
|
||||
<ComponentAccount
|
||||
account={item}
|
||||
props={{
|
||||
disabled: isSearching === index,
|
||||
onPress: () => {
|
||||
if (data?.pages[0]?.remoteData) {
|
||||
setIsSearching(index)
|
||||
apiInstance<SearchResult>({
|
||||
version: 'v2',
|
||||
method: 'get',
|
||||
url: 'search',
|
||||
params: {
|
||||
q: `@${item.acct}`,
|
||||
type: 'accounts',
|
||||
limit: 1,
|
||||
resolve: true
|
||||
}
|
||||
})
|
||||
.then(res => {
|
||||
setIsSearching(null)
|
||||
if (res.body.accounts[0]) {
|
||||
navigation.push('Tab-Shared-Account', { account: res.body.accounts[0] })
|
||||
}
|
||||
})
|
||||
.catch(() => setIsSearching(null))
|
||||
} else {
|
||||
navigation.push('Tab-Shared-Account', { account: item })
|
||||
}
|
||||
}
|
||||
}}
|
||||
children={<Loading />}
|
||||
props={{ onPress: () => navigation.push('Tab-Shared-Account', { account: item }) }}
|
||||
/>
|
||||
)}
|
||||
onEndReached={() => hasNextPage && !isFetchingNextPage && fetchNextPage()}
|
||||
|
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()
|
||||
}
|
||||
|
Loading…
x
Reference in New Issue
Block a user