import {type RefObject, useCallback} from 'react' import {View} from 'react-native' import {type AppBskyFeedDefs} from '@atproto/api' import {Trans, useLingui} from '@lingui/react/macro' import {useQueryClient} from '@tanstack/react-query' import {cleanError} from '#/lib/strings/errors' import {unstableCacheProfileView} from '#/state/queries/profile' import { buildPostSourceKey, setUnstablePostSource, } from '#/state/unstable-post-source' import {Post} from '#/view/com/post/Post' import {PostLoadingPlaceholder} from '#/view/com/util/LoadingPlaceholder' import {atoms as a, useTheme} from '#/alf' import * as Button from '#/components/Button' import { ChevronBottom_Stroke2_Corner0_Rounded as ChevronDownIcon, ChevronTop_Stroke2_Corner0_Rounded as ChevronUpIcon, } from '#/components/icons/Chevron' import {Text} from '#/components/Typography' export function ThreadAlsoLiked({ posts, visible, collapsed, isLoading: _isLoading, showLoadingState, isFetchingNextPage, error, onRetry, headerRef, onToggleCollapsed, spacerHeight, isTombstoneView, }: { posts: AppBskyFeedDefs.PostView[] visible: boolean collapsed: boolean isLoading: boolean showLoadingState: boolean isFetchingNextPage: boolean error: unknown onRetry: () => void headerRef: RefObject onToggleCollapsed: () => void spacerHeight: number | undefined isTombstoneView: boolean }) { const {t: l} = useLingui() const t = useTheme() const queryClient = useQueryClient() const hasSection = visible const onBeforePress = useCallback( (post: AppBskyFeedDefs.PostView) => { unstableCacheProfileView(queryClient, post.author) setUnstablePostSource(buildPostSourceKey(post.uri, post.author.handle), { post: {post}, }) }, [queryClient], ) return ( {hasSection && ( {({hovered, pressed}) => ( Also liked Posts liked by people who liked this post {collapsed ? ( ) : ( )} )} {!collapsed && ( <> {posts.map((post, index) => ( onBeforePress(post)} /> ))} {showLoadingState && posts.length === 0 && ( <> )} {isFetchingNextPage && ( )} {Boolean(error) && !showLoadingState && !isFetchingNextPage && ( {cleanError(error)} Retry )} )} )} ) }