import React, {useMemo} from 'react' import {observer} from 'mobx-react-lite' import {Image, StyleSheet, Text, TouchableOpacity, View} from 'react-native' import {bsky, AdxUri} from '@adxp/mock-api' 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 {PostDropdownBtn} from '../util/DropdownBtn' import {s, colors} from '../../lib/styles' import {ago, pluralize} from '../../lib/strings' import {AVIS} from '../../lib/assets' import {useStores} from '../../../state' export const PostThreadItem = observer(function PostThreadItem({ item, onPressShare, }: { item: PostThreadViewPostModel onPressShare: (_uri: string) => void }) { const store = useStores() const record = item.record as unknown as bsky.Post.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(item.uri)) } 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} {record.text} {item._isHighlightedPost && hasEngagement ? ( {item.repostCount ? ( {item.repostCount}{' '} {pluralize(item.repostCount, 'repost')} ) : ( <> )} {item.likeCount ? ( {item.likeCount}{' '} {pluralize(item.likeCount, 'like')} ) : ( <> )} ) : ( <> )} ) } else { return ( {item.author.displayName} @{item.author.name} · {ago(item.indexedAt)} {record.text} ) } }) const styles = StyleSheet.create({ outer: { backgroundColor: colors.white, borderRadius: 10, margin: 2, marginBottom: 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: { paddingBottom: 5, fontFamily: 'Helvetica Neue', }, 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, }, })