import React, {useMemo} from 'react' import {observer} from 'mobx-react-lite' import {Image, StyleSheet, Text, TouchableOpacity, View} from 'react-native' import Svg, {Line} from 'react-native-svg' import {AdxUri} from '../../../third-party/uri' import * as PostType from '../../../third-party/api/src/types/app/bsky/post' import {FontAwesomeIcon} from '@fortawesome/react-native-fontawesome' import {PostThreadViewPostModel} from '../../../state/models/post-thread-view' import {ComposePostModel} from '../../../state/models/shell' import {Link} from '../util/Link' import {RichText} from '../util/RichText' import {PostDropdownBtn} from '../util/DropdownBtn' import {s, colors} from '../../lib/styles' import {ago, pluralize} from '../../lib/strings' import {DEF_AVATER} from '../../lib/assets' import {useStores} from '../../../state' const PARENT_REPLY_LINE_LENGTH = 8 export const PostThreadItem = observer(function PostThreadItem({ item, onPressShare, onPostReply, }: { item: PostThreadViewPostModel onPressShare: (_uri: string) => void onPostReply: () => void }) { const store = useStores() const record = item.record as unknown as PostType.Record const hasEngagement = item.likeCount || item.repostCount const itemHref = useMemo(() => { const urip = new AdxUri(item.uri) return `/profile/${item.author.name}/post/${urip.recordKey}` }, [item.uri, item.author.name]) const itemTitle = `Post by ${item.author.name}` const authorHref = `/profile/${item.author.name}` const authorTitle = item.author.name const likesHref = useMemo(() => { const urip = new AdxUri(item.uri) return `/profile/${item.author.name}/post/${urip.recordKey}/liked-by` }, [item.uri, item.author.name]) const likesTitle = 'Likes on this post' const repostsHref = useMemo(() => { const urip = new AdxUri(item.uri) return `/profile/${item.author.name}/post/${urip.recordKey}/reposted-by` }, [item.uri, item.author.name]) const repostsTitle = 'Reposts of this post' const onPressReply = () => { store.shell.openModal( new ComposePostModel({replyTo: item.uri, onPost: onPostReply}), ) } const onPressToggleRepost = () => { item .toggleRepost() .catch(e => console.error('Failed to toggle repost', record, e)) } const onPressToggleLike = () => { item .toggleLike() .catch(e => console.error('Failed to toggle like', record, e)) } const Ctrls = () => ( {item.replyCount} {item.repostCount} {item.likeCount} onPressShare(item.uri)}> ) if (item._isHighlightedPost) { return ( {item.author.displayName} · {ago(item.indexedAt)} @{item.author.name} {item._isHighlightedPost && hasEngagement ? ( {item.repostCount ? ( {item.repostCount}{' '} {pluralize(item.repostCount, 'repost')} ) : ( <> )} {item.likeCount ? ( {item.likeCount}{' '} {pluralize(item.likeCount, 'like')} ) : ( <> )} ) : ( <> )} ) } else { return ( {!!item.replyingToAuthor && ( )} {item.replies?.length !== 0 && ( )} {item.replyingToAuthor && item.replyingToAuthor !== item.author.name && ( @{item.replyingToAuthor} )} {item.author.displayName} @{item.author.name} · {ago(item.indexedAt)} ) } }) const styles = StyleSheet.create({ outer: { backgroundColor: colors.white, borderRadius: 6, margin: 2, marginBottom: 0, }, parentReplyLine: { position: 'absolute', left: 30, top: -1 * PARENT_REPLY_LINE_LENGTH + 6, }, childReplyLine: { position: 'absolute', left: 30, top: 65, bottom: 0, }, layout: { flexDirection: 'row', }, layoutAvi: { width: 70, paddingLeft: 10, paddingTop: 10, paddingBottom: 10, }, avi: { width: 50, height: 50, borderRadius: 25, resizeMode: 'cover', }, layoutContent: { flex: 1, paddingRight: 10, paddingTop: 10, paddingBottom: 10, }, meta: { flexDirection: 'row', paddingTop: 2, paddingBottom: 2, }, metaItem: { paddingRight: 5, }, postText: { fontFamily: 'Helvetica Neue', }, postTextContainer: { flexDirection: 'row', alignItems: 'center', flexWrap: 'wrap', paddingBottom: 8, }, postTextLarge: { fontSize: 24, lineHeight: 32, fontWeight: '300', }, postTextLargeContainer: { paddingLeft: 4, paddingBottom: 20, }, expandedInfo: { flexDirection: 'row', padding: 10, borderColor: colors.gray2, borderTopWidth: 1, borderBottomWidth: 1, marginTop: 5, marginBottom: 10, }, expandedInfoItem: { marginRight: 10, }, ctrls: { flexDirection: 'row', }, ctrl: { flexDirection: 'row', alignItems: 'center', flex: 1, paddingLeft: 4, paddingRight: 4, }, ctrlIcon: { marginRight: 5, color: colors.gray5, }, ctrlIconReposted: { marginRight: 5, color: colors.green3, }, ctrlIconLiked: { marginRight: 5, color: colors.red3, }, })