mirror of
https://github.com/tooot-app/app
synced 2025-06-05 22:19:13 +02:00
Fix toot action for #638
This commit is contained in:
@ -24,15 +24,30 @@ import AccountNav from './Nav'
|
||||
const TabSharedAccount: React.FC<TabSharedStackScreenProps<'Tab-Shared-Account'>> = ({
|
||||
navigation,
|
||||
route: {
|
||||
params: { account, isRemote }
|
||||
params: { account }
|
||||
}
|
||||
}) => {
|
||||
const { t } = useTranslation('screenTabs')
|
||||
const { colors, mode } = useTheme()
|
||||
|
||||
const { data, dataUpdatedAt } = useAccountQuery({
|
||||
id: account.id,
|
||||
...(isRemote && { remoteUrl: account.url })
|
||||
account,
|
||||
options: {
|
||||
onSuccess: a => {
|
||||
if (account._remote) {
|
||||
setQueryKey([
|
||||
queryKey[0],
|
||||
{
|
||||
...queryKey[1],
|
||||
page: 'Account',
|
||||
id: a.id,
|
||||
exclude_reblogs: true,
|
||||
only_media: false
|
||||
}
|
||||
])
|
||||
}
|
||||
}
|
||||
}
|
||||
})
|
||||
|
||||
const mShare = menuShare({ type: 'account', url: data?.url })
|
||||
@ -87,7 +102,12 @@ const TabSharedAccount: React.FC<TabSharedStackScreenProps<'Tab-Shared-Account'>
|
||||
const queryClient = useQueryClient()
|
||||
const [queryKey, setQueryKey] = useState<QueryKeyTimeline>([
|
||||
'Timeline',
|
||||
{ page: 'Account', id: data?.id, exclude_reblogs: true, only_media: false }
|
||||
{
|
||||
page: 'Account',
|
||||
id: account._remote ? data?.id : account.id,
|
||||
exclude_reblogs: true,
|
||||
only_media: false
|
||||
}
|
||||
])
|
||||
const page = queryKey[1]
|
||||
|
||||
@ -174,7 +194,7 @@ const TabSharedAccount: React.FC<TabSharedStackScreenProps<'Tab-Shared-Account'>
|
||||
<Timeline
|
||||
queryKey={queryKey}
|
||||
disableRefresh
|
||||
queryOptions={{ enabled: isRemote ? !!data?.id : true }}
|
||||
queryOptions={{ enabled: account._remote ? !!data?.id : true }}
|
||||
customProps={{
|
||||
renderItem: ({ item }) => <TimelineDefault item={item} queryKey={queryKey} />,
|
||||
onScroll: ({ nativeEvent }) => (scrollY.value = nativeEvent.contentOffset.y),
|
||||
|
@ -9,6 +9,7 @@ import apiInstance from '@utils/api/instance'
|
||||
import { getHost } from '@utils/helpers/urlMatcher'
|
||||
import { TabSharedStackScreenProps } from '@utils/navigation/navigators'
|
||||
import { QueryKeyTimeline } from '@utils/queryHooks/timeline'
|
||||
import { getAccountStorage } from '@utils/storage/actions'
|
||||
import { StyleConstants } from '@utils/styles/constants'
|
||||
import { useTheme } from '@utils/styles/ThemeManager'
|
||||
import React, { useEffect, useRef, useState } from 'react'
|
||||
@ -65,8 +66,8 @@ const TabSharedToot: React.FC<TabSharedStackScreenProps<'Tab-Shared-Toot'>> = ({
|
||||
const flRef = useRef<FlatList>(null)
|
||||
const scrolled = useRef(false)
|
||||
|
||||
const finalData = useRef<Mastodon.Status[]>([
|
||||
{ ...toot, _level: 0, _remote: toot._remote }
|
||||
const finalData = useRef<(Mastodon.Status & { key?: string })[]>([
|
||||
{ ...toot, _level: 0, key: 'cached' }
|
||||
])
|
||||
const highlightIndex = useRef<number>(0)
|
||||
const queryKey: { local: QueryKeyTimeline; remote: QueryKeyTimeline } = {
|
||||
@ -86,7 +87,7 @@ const TabSharedToot: React.FC<TabSharedStackScreenProps<'Tab-Shared-Toot'>> = ({
|
||||
|
||||
const statuses: (Mastodon.Status & { _level?: number })[] = [
|
||||
...context.body.ancestors,
|
||||
toot,
|
||||
{ ...toot },
|
||||
...context.body.descendants
|
||||
]
|
||||
|
||||
@ -115,8 +116,7 @@ const TabSharedToot: React.FC<TabSharedStackScreenProps<'Tab-Shared-Toot'>> = ({
|
||||
return
|
||||
}
|
||||
|
||||
if (finalData.current.length < data.pages[0].body.length) {
|
||||
// if the remote has been loaded first
|
||||
if (finalData.current[0].key === 'cached') {
|
||||
finalData.current = data.pages[0].body
|
||||
|
||||
if (!scrolled.current) {
|
||||
@ -178,7 +178,7 @@ const TabSharedToot: React.FC<TabSharedStackScreenProps<'Tab-Shared-Toot'>> = ({
|
||||
|
||||
const statuses: (Mastodon.Status & { _level?: number })[] = [
|
||||
...context.ancestors,
|
||||
toot,
|
||||
{ ...toot },
|
||||
...context.descendants
|
||||
]
|
||||
|
||||
@ -198,7 +198,9 @@ const TabSharedToot: React.FC<TabSharedStackScreenProps<'Tab-Shared-Toot'>> = ({
|
||||
return { pages: [{ body: statuses }] }
|
||||
},
|
||||
{
|
||||
enabled: toot.account.acct !== toot.account.username, // When on the same instance, these two values are the same
|
||||
enabled:
|
||||
['public', 'unlisted'].includes(toot.visibility) &&
|
||||
getHost(toot.uri) !== getAccountStorage.string('auth.domain'),
|
||||
staleTime: 0,
|
||||
refetchOnMount: true,
|
||||
onSuccess: data => {
|
||||
@ -211,12 +213,25 @@ const TabSharedToot: React.FC<TabSharedStackScreenProps<'Tab-Shared-Toot'>> = ({
|
||||
finalData.current = data.pages[0].body.map(remote => {
|
||||
const localMatch = finalData.current.find(local => local.uri === remote.uri)
|
||||
if (localMatch) {
|
||||
delete localMatch.key
|
||||
return localMatch
|
||||
} else {
|
||||
remote._remote = true
|
||||
|
||||
remote.account._remote = true
|
||||
remote.mentions = remote.mentions.map(mention => ({ ...mention, _remote: true }))
|
||||
if (remote.reblog) {
|
||||
remote.reblog.account._remote = true
|
||||
remote.reblog.mentions = remote.mentions.map(mention => ({
|
||||
...mention,
|
||||
_remote: true
|
||||
}))
|
||||
}
|
||||
|
||||
return remote
|
||||
}
|
||||
})
|
||||
|
||||
setHasRemoteContent(true)
|
||||
}
|
||||
|
||||
@ -274,9 +289,8 @@ const TabSharedToot: React.FC<TabSharedStackScreenProps<'Tab-Shared-Toot'>> = ({
|
||||
item={item}
|
||||
queryKey={item._remote ? queryKey.remote : queryKey.local}
|
||||
rootQueryKey={rootQueryKey}
|
||||
highlighted={toot.id === item.id}
|
||||
isConversation={toot.id !== item.id}
|
||||
isRemote={item._remote}
|
||||
highlighted={toot.id === item.id || item.id === 'cached'}
|
||||
isConversation={toot.id !== item.id && item.id !== 'cached'}
|
||||
/>
|
||||
{curr > 1 || next > 1
|
||||
? [...new Array(curr)].map((_, i) => {
|
||||
|
Reference in New Issue
Block a user