Update post thread aesthetics

zio/stable
Paul Frazee 2022-08-31 21:02:12 -05:00
parent 6bec139679
commit 71594d069c
3 changed files with 118 additions and 101 deletions

View File

@ -133,8 +133,6 @@ export const FeedItem = observer(function FeedItem({
const styles = StyleSheet.create({ const styles = StyleSheet.create({
outer: { outer: {
// borderWidth: 1,
// borderColor: '#e8e8e8',
borderRadius: 10, borderRadius: 10,
margin: 2, margin: 2,
marginBottom: 0, marginBottom: 0,

View File

@ -75,7 +75,7 @@ export const PostThread = observer(function PostThread({uri}: {uri: string}) {
<PostThreadItem item={item} onPressShare={onPressShare} /> <PostThreadItem item={item} onPressShare={onPressShare} />
) )
return ( return (
<View style={s.h100pct}> <View>
<FlatList <FlatList
data={posts} data={posts}
keyExtractor={item => item._reactKey} keyExtractor={item => item._reactKey}

View File

@ -9,14 +9,6 @@ import {ago, pluralize} from '../../lib/strings'
import {AVIS} from '../../lib/assets' import {AVIS} from '../../lib/assets'
import {useStores} from '../../../state' import {useStores} from '../../../state'
function iter<T>(n: number, fn: (_i: number) => T): Array<T> {
const arr: T[] = []
for (let i = 0; i < n; i++) {
arr.push(fn(i))
}
return arr
}
export const PostThreadItem = observer(function PostThreadItem({ export const PostThreadItem = observer(function PostThreadItem({
item, item,
onPressShare, onPressShare,
@ -61,41 +53,83 @@ export const PostThreadItem = observer(function PostThreadItem({
.catch(e => console.error('Failed to toggle like', record, e)) .catch(e => console.error('Failed to toggle like', record, e))
} }
return ( const Ctrls = () => (
<TouchableOpacity style={styles.outer} onPress={onPressOuter}> <View style={styles.ctrls}>
<View style={styles.layout}> <TouchableOpacity style={styles.ctrl} onPress={onPressReply}>
{iter(Math.abs(item._depth), (i: number) => ( <FontAwesomeIcon
<View key={i} style={styles.replyBar} /> style={styles.ctrlIcon}
))} icon={['far', 'comment']}
<TouchableOpacity style={styles.layoutAvi} onPress={onPressAuthor}> size={14}
<Image />
style={styles.avi} <Text style={s.f13}>{item.replyCount}</Text>
source={AVIS[item.author.name] || AVIS['alice.com']} </TouchableOpacity>
/> <TouchableOpacity style={styles.ctrl} onPress={onPressToggleRepost}>
</TouchableOpacity> <FontAwesomeIcon
<View style={styles.layoutContent}> style={
<View style={styles.meta}> item.myState.hasReposted ? styles.ctrlIconReposted : styles.ctrlIcon
<Text }
style={[styles.metaItem, s.f15, s.bold]} icon="retweet"
onPress={onPressAuthor}> size={18}
{item.author.displayName} />
</Text> <Text
<Text style={item.myState.hasReposted ? [s.bold, s.green3, s.f13] : s.f13}>
style={[styles.metaItem, s.f14, s.gray5]} {item.repostCount}
onPress={onPressAuthor}> </Text>
@{item.author.name} </TouchableOpacity>
</Text> <TouchableOpacity style={styles.ctrl} onPress={onPressToggleLike}>
<Text style={[styles.metaItem, s.f14, s.gray5]}> <FontAwesomeIcon
&middot; {ago(item.indexedAt)} style={item.myState.hasLiked ? styles.ctrlIconLiked : styles.ctrlIcon}
</Text> icon={[item.myState.hasLiked ? 'fas' : 'far', 'heart']}
size={14}
/>
<Text style={item.myState.hasLiked ? [s.bold, s.red3, s.f13] : s.f13}>
{item.likeCount}
</Text>
</TouchableOpacity>
<TouchableOpacity
style={styles.ctrl}
onPress={() => onPressShare(item.uri)}>
<FontAwesomeIcon
style={styles.ctrlIcon}
icon="share-from-square"
size={14}
/>
</TouchableOpacity>
</View>
)
if (item._isHighlightedPost) {
return (
<View style={styles.outer}>
<View style={styles.layout}>
<TouchableOpacity style={styles.layoutAvi} onPress={onPressAuthor}>
<Image
style={styles.avi}
source={AVIS[item.author.name] || AVIS['alice.com']}
/>
</TouchableOpacity>
<View style={styles.layoutContent}>
<View style={[styles.meta, s.mt5]}>
<Text
style={[styles.metaItem, s.f15, s.bold]}
onPress={onPressAuthor}>
{item.author.displayName}
</Text>
<Text style={[styles.metaItem, s.f14, s.gray5]}>
&middot; {ago(item.indexedAt)}
</Text>
</View>
<View style={styles.meta}>
<Text
style={[styles.metaItem, s.f14, s.gray5]}
onPress={onPressAuthor}>
@{item.author.name}
</Text>
</View>
</View> </View>
<Text </View>
style={[ <View style={[s.pl10, s.pr10, s.pb10]}>
styles.postText, <Text style={[styles.postText, s.f18, s['lh18-1.3']]}>
...(item._isHighlightedPost
? [s.f16, s['lh16-1.3']]
: [s.f15, s['lh15-1.3']]),
]}>
{record.text} {record.text}
</Text> </Text>
{item._isHighlightedPost && hasEngagement ? ( {item._isHighlightedPost && hasEngagement ? (
@ -124,74 +158,59 @@ export const PostThreadItem = observer(function PostThreadItem({
) : ( ) : (
<></> <></>
)} )}
<View style={styles.ctrls}> <View style={[s.pl10]}>
<TouchableOpacity style={styles.ctrl} onPress={onPressReply}> <Ctrls />
<FontAwesomeIcon
style={styles.ctrlIcon}
icon={['far', 'comment']}
size={14}
/>
<Text style={s.f13}>{item.replyCount}</Text>
</TouchableOpacity>
<TouchableOpacity style={styles.ctrl} onPress={onPressToggleRepost}>
<FontAwesomeIcon
style={
item.myState.hasReposted
? styles.ctrlIconReposted
: styles.ctrlIcon
}
icon="retweet"
size={18}
/>
<Text
style={
item.myState.hasReposted ? [s.bold, s.green3, s.f13] : s.f13
}>
{item.repostCount}
</Text>
</TouchableOpacity>
<TouchableOpacity style={styles.ctrl} onPress={onPressToggleLike}>
<FontAwesomeIcon
style={
item.myState.hasLiked ? styles.ctrlIconLiked : styles.ctrlIcon
}
icon={[item.myState.hasLiked ? 'fas' : 'far', 'heart']}
size={14}
/>
<Text
style={item.myState.hasLiked ? [s.bold, s.red3, s.f13] : s.f13}>
{item.likeCount}
</Text>
</TouchableOpacity>
<TouchableOpacity
style={styles.ctrl}
onPress={() => onPressShare(item.uri)}>
<FontAwesomeIcon
style={styles.ctrlIcon}
icon="share-from-square"
size={14}
/>
</TouchableOpacity>
</View> </View>
</View> </View>
</View> </View>
</TouchableOpacity> )
) } else {
return (
<TouchableOpacity style={styles.outer} onPress={onPressOuter}>
<View style={styles.layout}>
<TouchableOpacity style={styles.layoutAvi} onPress={onPressAuthor}>
<Image
style={styles.avi}
source={AVIS[item.author.name] || AVIS['alice.com']}
/>
</TouchableOpacity>
<View style={styles.layoutContent}>
<View style={styles.meta}>
<Text
style={[styles.metaItem, s.f15, s.bold]}
onPress={onPressAuthor}>
{item.author.displayName}
</Text>
<Text
style={[styles.metaItem, s.f14, s.gray5]}
onPress={onPressAuthor}>
@{item.author.name}
</Text>
<Text style={[styles.metaItem, s.f14, s.gray5]}>
&middot; {ago(item.indexedAt)}
</Text>
</View>
<Text style={[styles.postText, s.f15, s['lh15-1.3']]}>
{record.text}
</Text>
<Ctrls />
</View>
</View>
</TouchableOpacity>
)
}
}) })
const styles = StyleSheet.create({ const styles = StyleSheet.create({
outer: { outer: {
marginTop: 1,
backgroundColor: colors.white, backgroundColor: colors.white,
borderRadius: 10,
margin: 2,
marginBottom: 0,
}, },
layout: { layout: {
flexDirection: 'row', flexDirection: 'row',
}, },
replyBar: {
width: 5,
backgroundColor: colors.gray2,
marginRight: 2,
},
layoutAvi: { layoutAvi: {
width: 70, width: 70,
paddingLeft: 10, paddingLeft: 10,