mirror of
https://github.com/tooot-app/app
synced 2025-02-13 02:10:39 +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 { useQuery } from '@tanstack/react-query'
|
||||||
import apiGeneral from '@utils/api/general'
|
import apiGeneral from '@utils/api/general'
|
||||||
import apiInstance from '@utils/api/instance'
|
import apiInstance from '@utils/api/instance'
|
||||||
|
import { appendRemote } from '@utils/helpers/appendRemote'
|
||||||
import { urlMatcher } from '@utils/helpers/urlMatcher'
|
import { urlMatcher } from '@utils/helpers/urlMatcher'
|
||||||
import { TabSharedStackScreenProps } from '@utils/navigation/navigators'
|
import { TabSharedStackScreenProps } from '@utils/navigation/navigators'
|
||||||
import { queryClient } from '@utils/queryHooks'
|
import { queryClient } from '@utils/queryHooks'
|
||||||
@ -206,26 +207,7 @@ const TabSharedToot: React.FC<TabSharedStackScreenProps<'Tab-Shared-Toot'>> = ({
|
|||||||
if (localMatch) {
|
if (localMatch) {
|
||||||
return localMatch
|
return localMatch
|
||||||
} else {
|
} else {
|
||||||
return {
|
return appendRemote.status(ancestor)
|
||||||
...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
|
|
||||||
}))
|
|
||||||
}
|
|
||||||
})
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
})
|
})
|
||||||
}
|
}
|
||||||
@ -268,23 +250,7 @@ const TabSharedToot: React.FC<TabSharedStackScreenProps<'Tab-Shared-Toot'>> = ({
|
|||||||
if (localMatch) {
|
if (localMatch) {
|
||||||
return { ...localMatch, _level: remote._level }
|
return { ...localMatch, _level: remote._level }
|
||||||
} else {
|
} else {
|
||||||
return {
|
return appendRemote.status(remote)
|
||||||
...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
|
|
||||||
}))
|
|
||||||
}
|
|
||||||
})
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
})
|
})
|
||||||
}
|
}
|
||||||
|
@ -4,14 +4,12 @@ import Icon from '@components/Icon'
|
|||||||
import { Loading } from '@components/Loading'
|
import { Loading } from '@components/Loading'
|
||||||
import ComponentSeparator from '@components/Separator'
|
import ComponentSeparator from '@components/Separator'
|
||||||
import CustomText from '@components/Text'
|
import CustomText from '@components/Text'
|
||||||
import apiInstance from '@utils/api/instance'
|
|
||||||
import { TabSharedStackScreenProps } from '@utils/navigation/navigators'
|
import { TabSharedStackScreenProps } from '@utils/navigation/navigators'
|
||||||
import { SearchResult } from '@utils/queryHooks/search'
|
|
||||||
import { QueryKeyUsers, useUsersQuery } from '@utils/queryHooks/users'
|
import { QueryKeyUsers, useUsersQuery } from '@utils/queryHooks/users'
|
||||||
import { flattenPages } from '@utils/queryHooks/utils'
|
import { flattenPages } from '@utils/queryHooks/utils'
|
||||||
import { StyleConstants } from '@utils/styles/constants'
|
import { StyleConstants } from '@utils/styles/constants'
|
||||||
import { useTheme } from '@utils/styles/ThemeManager'
|
import { useTheme } from '@utils/styles/ThemeManager'
|
||||||
import React, { useEffect, useState } from 'react'
|
import React, { useEffect } from 'react'
|
||||||
import { useTranslation } from 'react-i18next'
|
import { useTranslation } from 'react-i18next'
|
||||||
import { View } from 'react-native'
|
import { View } from 'react-native'
|
||||||
import { FlatList } from 'react-native-gesture-handler'
|
import { FlatList } from 'react-native-gesture-handler'
|
||||||
@ -36,8 +34,6 @@ const TabSharedUsers: React.FC<TabSharedStackScreenProps<'Tab-Shared-Users'>> =
|
|||||||
...queryKey[1]
|
...queryKey[1]
|
||||||
})
|
})
|
||||||
|
|
||||||
const [isSearching, setIsSearching] = useState<number | null>(null)
|
|
||||||
|
|
||||||
return (
|
return (
|
||||||
<FlatList
|
<FlatList
|
||||||
windowSize={7}
|
windowSize={7}
|
||||||
@ -46,38 +42,10 @@ const TabSharedUsers: React.FC<TabSharedStackScreenProps<'Tab-Shared-Users'>> =
|
|||||||
minHeight: '100%',
|
minHeight: '100%',
|
||||||
paddingVertical: StyleConstants.Spacing.Global.PagePadding
|
paddingVertical: StyleConstants.Spacing.Global.PagePadding
|
||||||
}}
|
}}
|
||||||
renderItem={({ item, index }) => (
|
renderItem={({ item }) => (
|
||||||
<ComponentAccount
|
<ComponentAccount
|
||||||
account={item}
|
account={item}
|
||||||
props={{
|
props={{ onPress: () => navigation.push('Tab-Shared-Account', { account: item }) }}
|
||||||
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 />}
|
|
||||||
/>
|
/>
|
||||||
)}
|
)}
|
||||||
onEndReached={() => hasNextPage && !isFetchingNextPage && fetchNextPage()}
|
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 { QueryFunctionContext, useQuery, UseQueryOptions } from '@tanstack/react-query'
|
||||||
import apiGeneral from '@utils/api/general'
|
import apiGeneral from '@utils/api/general'
|
||||||
import apiInstance from '@utils/api/instance'
|
import apiInstance from '@utils/api/instance'
|
||||||
|
import { appendRemote } from '@utils/helpers/appendRemote'
|
||||||
import { urlMatcher } from '@utils/helpers/urlMatcher'
|
import { urlMatcher } from '@utils/helpers/urlMatcher'
|
||||||
import { AxiosError } from 'axios'
|
import { AxiosError } from 'axios'
|
||||||
import { searchLocalAccount } from './search'
|
import { searchLocalAccount } from './search'
|
||||||
@ -34,14 +35,14 @@ const accountQueryFunction = async ({ queryKey }: QueryFunctionContext<QueryKeyA
|
|||||||
method: 'get',
|
method: 'get',
|
||||||
domain: domain,
|
domain: domain,
|
||||||
url: `api/v1/accounts/${id}`
|
url: `api/v1/accounts/${id}`
|
||||||
}).then(res => ({ ...res.body, _remote: true }))
|
}).then(res => appendRemote.account(res.body))
|
||||||
} else if (acct) {
|
} else if (acct) {
|
||||||
matchedAccount = await apiGeneral<Mastodon.Account>({
|
matchedAccount = await apiGeneral<Mastodon.Account>({
|
||||||
method: 'get',
|
method: 'get',
|
||||||
domain: domain,
|
domain: domain,
|
||||||
url: 'api/v1/accounts/lookup',
|
url: 'api/v1/accounts/lookup',
|
||||||
params: { acct }
|
params: { acct }
|
||||||
}).then(res => ({ ...res.body, _remote: true }))
|
}).then(res => appendRemote.account(res.body))
|
||||||
}
|
}
|
||||||
} catch {}
|
} catch {}
|
||||||
}
|
}
|
||||||
|
@ -1,6 +1,7 @@
|
|||||||
import { QueryFunctionContext, useQuery, UseQueryOptions } from '@tanstack/react-query'
|
import { QueryFunctionContext, useQuery, UseQueryOptions } from '@tanstack/react-query'
|
||||||
import apiGeneral from '@utils/api/general'
|
import apiGeneral from '@utils/api/general'
|
||||||
import apiInstance from '@utils/api/instance'
|
import apiInstance from '@utils/api/instance'
|
||||||
|
import { appendRemote } from '@utils/helpers/appendRemote'
|
||||||
import { urlMatcher } from '@utils/helpers/urlMatcher'
|
import { urlMatcher } from '@utils/helpers/urlMatcher'
|
||||||
import { AxiosError } from 'axios'
|
import { AxiosError } from 'axios'
|
||||||
import { searchLocalStatus } from './search'
|
import { searchLocalStatus } from './search'
|
||||||
@ -26,7 +27,7 @@ const queryFunction = async ({ queryKey }: QueryFunctionContext<QueryKeyStatus>)
|
|||||||
method: 'get',
|
method: 'get',
|
||||||
domain,
|
domain,
|
||||||
url: `api/v1/statuses/${id}`
|
url: `api/v1/statuses/${id}`
|
||||||
}).then(res => ({ ...res.body, _remote: true }))
|
}).then(res => appendRemote.status(res.body))
|
||||||
} catch {}
|
} catch {}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -6,6 +6,7 @@ import {
|
|||||||
import apiGeneral from '@utils/api/general'
|
import apiGeneral from '@utils/api/general'
|
||||||
import { PagedResponse } from '@utils/api/helpers'
|
import { PagedResponse } from '@utils/api/helpers'
|
||||||
import apiInstance from '@utils/api/instance'
|
import apiInstance from '@utils/api/instance'
|
||||||
|
import { appendRemote } from '@utils/helpers/appendRemote'
|
||||||
import { urlMatcher } from '@utils/helpers/urlMatcher'
|
import { urlMatcher } from '@utils/helpers/urlMatcher'
|
||||||
import { TabSharedStackParamList } from '@utils/navigation/navigators'
|
import { TabSharedStackParamList } from '@utils/navigation/navigators'
|
||||||
import { AxiosError } from 'axios'
|
import { AxiosError } from 'axios'
|
||||||
@ -54,7 +55,11 @@ const queryFunction = async ({ queryKey, pageParam }: QueryFunctionContext<Query
|
|||||||
url: `api/v1/accounts/${resLookup.body.id}/${page.type}`,
|
url: `api/v1/accounts/${resLookup.body.id}/${page.type}`,
|
||||||
params
|
params
|
||||||
})
|
})
|
||||||
return { ...res, remoteData: true }
|
return {
|
||||||
|
...res,
|
||||||
|
body: res.body.map(account => appendRemote.account(account)),
|
||||||
|
remoteData: true
|
||||||
|
}
|
||||||
} else {
|
} else {
|
||||||
throw new Error()
|
throw new Error()
|
||||||
}
|
}
|
||||||
|
Loading…
x
Reference in New Issue
Block a user