import React 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 {s, colors} from '../../lib/styles' import {ago, pluralize} from '../../lib/strings' import {AVIS} from '../../lib/assets' import {useStores} from '../../../state' function iter(n: number, fn: (_i: number) => T): Array { const arr: T[] = [] for (let i = 0; i < n; i++) { arr.push(fn(i)) } return arr } 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 onPressOuter = () => { const urip = new AdxUri(item.uri) store.nav.navigate(`/profile/${item.author.name}/post/${urip.recordKey}`) } const onPressAuthor = () => { store.nav.navigate(`/profile/${item.author.name}`) } const onPressLikes = () => { const urip = new AdxUri(item.uri) store.nav.navigate( `/profile/${item.author.name}/post/${urip.recordKey}/liked-by`, ) } const onPressReposts = () => { const urip = new AdxUri(item.uri) store.nav.navigate( `/profile/${item.author.name}/post/${urip.recordKey}/reposted-by`, ) } const onPressReply = () => { store.nav.navigate(`/composer?replyTo=${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)) } return ( {iter(Math.abs(item._depth), (i: number) => ( ))} {item.author.displayName} @{item.author.name} · {ago(item.indexedAt)} {record.text} {item._isHighlightedPost && hasEngagement ? ( {item.repostCount ? ( {item.repostCount}{' '} {pluralize(item.repostCount, 'repost')} ) : ( <> )} {item.likeCount ? ( {item.likeCount}{' '} {pluralize(item.likeCount, 'like')} ) : ( <> )} ) : ( <> )} {item.replyCount} {item.repostCount} {item.likeCount} onPressShare(item.uri)}> ) }) const styles = StyleSheet.create({ outer: { marginTop: 1, backgroundColor: colors.white, }, layout: { flexDirection: 'row', }, replyBar: { width: 5, backgroundColor: colors.gray2, marginRight: 2, }, layoutAvi: { width: 80, paddingLeft: 10, paddingTop: 10, paddingBottom: 10, }, avi: { width: 60, height: 60, borderRadius: 30, resizeMode: 'cover', }, layoutContent: { flex: 1, paddingRight: 10, paddingTop: 10, paddingBottom: 10, }, meta: { flexDirection: 'row', paddingTop: 2, paddingBottom: 4, }, 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.pink3, }, })