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 moment from 'moment' import {FontAwesomeIcon} from '@fortawesome/react-native-fontawesome' import {OnNavigateContent} from '../../routes/types' import {PostThreadViewPostModel} from '../../../state/models/post-thread-view' import {s} from '../../lib/styles' import {pluralize} from '../../lib/strings' import {AVIS} from '../../lib/assets' 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, onNavigateContent, }: { item: PostThreadViewPostModel onNavigateContent: OnNavigateContent }) { const record = item.record as unknown as bsky.Post.Record const hasEngagement = item.likeCount || item.repostCount const onPressOuter = () => { const urip = new AdxUri(item.uri) onNavigateContent('PostThread', { name: item.author.name, recordKey: urip.recordKey, }) } const onPressAuthor = () => { onNavigateContent('Profile', { name: item.author.name, }) } const onPressLikes = () => { const urip = new AdxUri(item.uri) onNavigateContent('PostLikedBy', { name: item.author.name, recordKey: urip.recordKey, }) } const onPressReposts = () => { const urip = new AdxUri(item.uri) onNavigateContent('PostRepostedBy', { name: item.author.name, recordKey: urip.recordKey, }) } const onPressReply = () => { onNavigateContent('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} · {moment(item.indexedAt).fromNow(true)} {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} ) }) const styles = StyleSheet.create({ outer: { borderTopWidth: 1, borderTopColor: '#e8e8e8', backgroundColor: '#fff', }, layout: { flexDirection: 'row', }, replyBar: { width: 5, backgroundColor: 'gray', 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, }, expandedInfo: { flexDirection: 'row', padding: 10, borderColor: '#e8e8e8', 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: 'gray', }, ctrlIconReposted: { marginRight: 5, color: 'green', }, ctrlIconLiked: { marginRight: 5, color: 'red', }, })