import ComponentAccount from '@components/Account' import GracefullyImage from '@components/GracefullyImage' import openLink from '@components/openLink' import CustomText from '@components/Text' import { useNavigation } from '@react-navigation/native' import { StackNavigationProp } from '@react-navigation/stack' import { urlMatcher } from '@utils/helpers/urlMatcher' import { TabLocalStackParamList } from '@utils/navigation/navigators' import { useAccountQuery } from '@utils/queryHooks/account' import { useStatusQuery } from '@utils/queryHooks/status' import { StyleConstants } from '@utils/styles/constants' import { useTheme } from '@utils/styles/ThemeManager' import React, { useContext, useEffect, useState } from 'react' import { Pressable, View } from 'react-native' import TimelineDefault from '../Default' import StatusContext from './Context' const TimelineCard: React.FC = () => { const { status, spoilerHidden, disableDetails, inThread } = useContext(StatusContext) if (!status || !status.card) return null const { colors } = useTheme() const navigation = useNavigation>() const [loading, setLoading] = useState(false) const match = urlMatcher(status.card.url) const [foundStatus, setFoundStatus] = useState() const [foundAccount, setFoundAccount] = useState() const statusQuery = useStatusQuery({ status: match?.status ? { ...match.status, uri: status.card.url } : undefined, options: { enabled: false, retry: false } }) useEffect(() => { if (match?.status) { setLoading(true) statusQuery .refetch() .then(res => { res.data && setFoundStatus(res.data) setLoading(false) }) .catch(() => setLoading(false)) } }, []) const accountQuery = useAccountQuery({ account: match?.account ? { ...match?.account, url: status.card.url } : undefined, options: { enabled: false, retry: false } }) useEffect(() => { if (match?.account) { setLoading(true) accountQuery .refetch() .then(res => { res.data && setFoundAccount(res.data) setLoading(false) }) .catch(() => setLoading(false)) } }, []) if (loading) { return null } if (status.media_attachments.length) { return null } if ((!status.card?.image || !status.card.title) && !status.card?.description) { return null } const cardContent = () => { if (match?.status && foundStatus) { return } if (match?.account && foundAccount) { return } return ( <> {status.card?.image ? ( ) : null} {status.card?.title.length ? ( {status.card.title} ) : null} {status.card?.description.length ? ( {status.card.description} ) : null} {status.card?.url.length ? ( {status.card.url} ) : null} ) } if (spoilerHidden || disableDetails) return null return ( { if (match?.status && foundStatus) { navigation.push('Tab-Shared-Toot', { toot: foundStatus }) return } if (match?.account && foundAccount) { navigation.push('Tab-Shared-Account', { account: foundAccount }) return } status.card?.url && (await openLink(status.card.url, navigation)) }} children={cardContent()} /> ) } export default TimelineCard