1
0
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:
xmflsct
2023-01-02 23:18:22 +01:00
parent 6dafbc96af
commit 4c6b8f0959
25 changed files with 298 additions and 71 deletions

View File

@ -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) => {