diff --git a/src/screens/Tabs/Shared/Toot.tsx b/src/screens/Tabs/Shared/Toot.tsx index 36c1859d..5f078717 100644 --- a/src/screens/Tabs/Shared/Toot.tsx +++ b/src/screens/Tabs/Shared/Toot.tsx @@ -74,7 +74,7 @@ const TabSharedToot: React.FC> = ({ const match = urlMatcher(toot.url || toot.uri) const highlightIndex = useRef(0) - const query = useQuery<{ pages: { body: (Mastodon.Status & { key?: 'cached' })[] }[] }>( + const query = useQuery<{ pages: { body: Mastodon.Status[] }[] }>( queryKey.local, async () => { const context = await apiInstance<{ @@ -108,7 +108,7 @@ const TabSharedToot: React.FC> = ({ } }, { - initialData: { pages: [{ body: [{ ...toot, _level: 0, key: 'cached' }] }] }, + placeholderData: { pages: [{ body: [toot] }] }, enabled: !toot._remote, staleTime: 0, refetchOnMount: true, @@ -188,12 +188,12 @@ const TabSharedToot: React.FC> = ({ staleTime: 0, refetchOnMount: true, onSuccess: data => { - if (query.data.pages[0].body.length < 1 && data.length < 1) { + if ((query.data?.pages[0].body.length || 0) < 1 && data.length < 1) { navigation.goBack() return } - if (query.data.pages[0].body.length < data.length) { + if ((query.data?.pages[0].body.length || 0) < data.length) { queryClient.cancelQueries(queryKey.local) queryClient.setQueryData<{ pages: { body: Mastodon.Status[] }[] @@ -205,11 +205,10 @@ const TabSharedToot: React.FC> = ({ pages: [ { body: data.map(remote => { - const localMatch = query.data.pages[0].body.find( + const localMatch = query.data?.pages[0].body.find( local => local.uri === remote.uri ) if (localMatch) { - delete localMatch.key return { ...localMatch, _level: remote._level } } else { return { @@ -269,9 +268,9 @@ const TabSharedToot: React.FC> = ({ windowSize={7} data={query.data?.pages?.[0].body} renderItem={({ item, index }) => { - const prev = query.data.pages[0].body[index - 1]?._level || 0 + const prev = query.data?.pages[0].body[index - 1]?._level || 0 const curr = item._level - const next = query.data.pages[0].body[index + 1]?._level || 0 + const next = query.data?.pages[0].body[index + 1]?._level || 0 return ( > = ({ } }) : null} - > = ({ style={{ position: 'absolute', top: 20, left: 4, color: colors.yellow }} /> + /> */} ) }} @@ -425,7 +424,7 @@ const TabSharedToot: React.FC> = ({ const offset = error.averageItemLength * error.index flRef.current?.scrollToOffset({ offset }) try { - error.index < query.data.pages[0].body.length && + error.index < (query.data?.pages[0].body.length || 0) && setTimeout( () => flRef.current?.scrollToIndex({