Tune post-thread expanded view: add reply prompt, fix spacing and sizing

zio/stable
Paul Frazee 2022-11-28 09:49:41 -06:00
parent b978a2f18b
commit 490a3bb751
3 changed files with 172 additions and 135 deletions

View File

@ -1,17 +1,29 @@
import React from 'react' import React from 'react'
import {StyleSheet, Text, TouchableOpacity, View} from 'react-native' import {StyleSheet, Text, TouchableOpacity, View} from 'react-native'
import {FontAwesomeIcon} from '@fortawesome/react-native-fontawesome'
import {colors} from '../../lib/styles' import {colors} from '../../lib/styles'
import {useStores} from '../../../state' import {useStores} from '../../../state'
import {UserAvatar} from '../util/UserAvatar' import {UserAvatar} from '../util/UserAvatar'
export function ComposePrompt({onPressCompose}: {onPressCompose: () => void}) { export function ComposePrompt({
noAvi = false,
text = "What's up?",
btn = 'Post',
onPressCompose,
}: {
noAvi?: boolean
text?: string
btn?: string
onPressCompose: () => void
}) {
const store = useStores() const store = useStores()
const onPressAvatar = () => { const onPressAvatar = () => {
store.nav.navigate(`/profile/${store.me.handle}`) store.nav.navigate(`/profile/${store.me.handle}`)
} }
return ( return (
<TouchableOpacity style={styles.container} onPress={onPressCompose}> <TouchableOpacity
style={[styles.container, noAvi ? styles.noAviContainer : undefined]}
onPress={onPressCompose}>
{!noAvi ? (
<TouchableOpacity style={styles.avatar} onPress={onPressAvatar}> <TouchableOpacity style={styles.avatar} onPress={onPressAvatar}>
<UserAvatar <UserAvatar
size={50} size={50}
@ -19,11 +31,12 @@ export function ComposePrompt({onPressCompose}: {onPressCompose: () => void}) {
displayName={store.me.displayName} displayName={store.me.displayName}
/> />
</TouchableOpacity> </TouchableOpacity>
) : undefined}
<View style={styles.textContainer}> <View style={styles.textContainer}>
<Text style={styles.text}>What's up?</Text> <Text style={styles.text}>{text}</Text>
</View> </View>
<View style={styles.btn}> <View style={styles.btn}>
<Text style={styles.btnText}>Post</Text> <Text style={styles.btnText}>{btn}</Text>
</View> </View>
</TouchableOpacity> </TouchableOpacity>
) )
@ -40,6 +53,9 @@ const styles = StyleSheet.create({
alignItems: 'center', alignItems: 'center',
backgroundColor: colors.white, backgroundColor: colors.white,
}, },
noAviContainer: {
paddingVertical: 14,
},
avatar: { avatar: {
width: 50, width: 50,
}, },

View File

@ -16,6 +16,7 @@ import {useStores} from '../../../state'
import {PostMeta} from '../util/PostMeta' import {PostMeta} from '../util/PostMeta'
import {PostEmbeds} from '../util/PostEmbeds' import {PostEmbeds} from '../util/PostEmbeds'
import {PostCtrls} from '../util/PostCtrls' import {PostCtrls} from '../util/PostCtrls'
import {ComposePrompt} from '../composer/Prompt'
const PARENT_REPLY_LINE_LENGTH = 8 const PARENT_REPLY_LINE_LENGTH = 8
const REPLYING_TO_LINE_LENGTH = 6 const REPLYING_TO_LINE_LENGTH = 6
@ -93,6 +94,7 @@ export const PostThreadItem = observer(function PostThreadItem({
if (item._isHighlightedPost) { if (item._isHighlightedPost) {
return ( return (
<>
<View style={styles.outer}> <View style={styles.outer}>
<View style={styles.layout}> <View style={styles.layout}>
<View style={styles.layoutAvi}> <View style={styles.layoutAvi}>
@ -152,7 +154,7 @@ export const PostThreadItem = observer(function PostThreadItem({
style={[styles.postText, styles.postTextLarge]} style={[styles.postText, styles.postTextLarge]}
/> />
</View> </View>
<PostEmbeds entities={record.entities} /> <PostEmbeds entities={record.entities} style={s.mb10} />
{item._isHighlightedPost && hasEngagement ? ( {item._isHighlightedPost && hasEngagement ? (
<View style={styles.expandedInfo}> <View style={styles.expandedInfo}>
{item.repostCount ? ( {item.repostCount ? (
@ -160,8 +162,8 @@ export const PostThreadItem = observer(function PostThreadItem({
style={styles.expandedInfoItem} style={styles.expandedInfoItem}
href={repostsHref} href={repostsHref}
title={repostsTitle}> title={repostsTitle}>
<Text style={[s.gray5, s.semiBold, s.f18]}> <Text style={[s.gray5, s.semiBold, s.f17]}>
<Text style={[s.bold, s.black, s.f18]}> <Text style={[s.bold, s.black, s.f17]}>
{item.repostCount} {item.repostCount}
</Text>{' '} </Text>{' '}
{pluralize(item.repostCount, 'repost')} {pluralize(item.repostCount, 'repost')}
@ -175,8 +177,8 @@ export const PostThreadItem = observer(function PostThreadItem({
style={styles.expandedInfoItem} style={styles.expandedInfoItem}
href={upvotesHref} href={upvotesHref}
title={upvotesTitle}> title={upvotesTitle}>
<Text style={[s.gray5, s.semiBold, s.f18]}> <Text style={[s.gray5, s.semiBold, s.f17]}>
<Text style={[s.bold, s.black, s.f18]}> <Text style={[s.bold, s.black, s.f17]}>
{item.upvoteCount} {item.upvoteCount}
</Text>{' '} </Text>{' '}
{pluralize(item.upvoteCount, 'upvote')} {pluralize(item.upvoteCount, 'upvote')}
@ -189,11 +191,9 @@ export const PostThreadItem = observer(function PostThreadItem({
) : ( ) : (
<></> <></>
)} )}
<View style={[s.pl10]}> <View style={[s.pl10, s.pb5]}>
<PostCtrls <PostCtrls
replyCount={item.replyCount} big
repostCount={item.repostCount}
upvoteCount={item.upvoteCount}
isReposted={!!item.myState.repost} isReposted={!!item.myState.repost}
isUpvoted={!!item.myState.upvote} isUpvoted={!!item.myState.upvote}
onPressReply={onPressReply} onPressReply={onPressReply}
@ -203,6 +203,13 @@ export const PostThreadItem = observer(function PostThreadItem({
</View> </View>
</View> </View>
</View> </View>
<ComposePrompt
noAvi
text="Write your reply"
btn="Reply"
onPressCompose={onPressReply}
/>
</>
) )
} else { } else {
return ( return (
@ -371,7 +378,7 @@ const styles = StyleSheet.create({
borderTopWidth: 1, borderTopWidth: 1,
borderBottomWidth: 1, borderBottomWidth: 1,
marginTop: 5, marginTop: 5,
marginBottom: 10, marginBottom: 15,
}, },
expandedInfoItem: { expandedInfoItem: {
marginRight: 10, marginRight: 10,

View File

@ -12,9 +12,10 @@ import {UpIcon, UpIconSolid} from '../../lib/icons'
import {s, colors} from '../../lib/styles' import {s, colors} from '../../lib/styles'
interface PostCtrlsOpts { interface PostCtrlsOpts {
replyCount: number big?: boolean
repostCount: number replyCount?: number
upvoteCount: number repostCount?: number
upvoteCount?: number
isReposted: boolean isReposted: boolean
isUpvoted: boolean isUpvoted: boolean
onPressReply: () => void onPressReply: () => void
@ -62,9 +63,11 @@ export function PostCtrls(opts: PostCtrlsOpts) {
<FontAwesomeIcon <FontAwesomeIcon
style={styles.ctrlIcon} style={styles.ctrlIcon}
icon={['far', 'comment']} icon={['far', 'comment']}
size={14} size={opts.big ? 20 : 14}
/> />
{typeof opts.replyCount !== 'undefined' ? (
<Text style={[sRedgray, s.ml5, s.f16]}>{opts.replyCount}</Text> <Text style={[sRedgray, s.ml5, s.f16]}>{opts.replyCount}</Text>
) : undefined}
</TouchableOpacity> </TouchableOpacity>
</View> </View>
<View style={s.flex1}> <View style={s.flex1}>
@ -77,9 +80,10 @@ export function PostCtrls(opts: PostCtrlsOpts) {
opts.isReposted ? styles.ctrlIconReposted : styles.ctrlIcon opts.isReposted ? styles.ctrlIconReposted : styles.ctrlIcon
} }
icon="retweet" icon="retweet"
size={18} size={opts.big ? 22 : 18}
/> />
</Animated.View> </Animated.View>
{typeof opts.repostCount !== 'undefined' ? (
<Text <Text
style={ style={
opts.isReposted opts.isReposted
@ -88,6 +92,7 @@ export function PostCtrls(opts: PostCtrlsOpts) {
}> }>
{opts.repostCount} {opts.repostCount}
</Text> </Text>
) : undefined}
</TouchableOpacity> </TouchableOpacity>
</View> </View>
<View style={s.flex1}> <View style={s.flex1}>
@ -96,11 +101,19 @@ export function PostCtrls(opts: PostCtrlsOpts) {
onPress={onPressToggleUpvoteWrapper}> onPress={onPressToggleUpvoteWrapper}>
<Animated.View style={anim2Style}> <Animated.View style={anim2Style}>
{opts.isUpvoted ? ( {opts.isUpvoted ? (
<UpIconSolid style={[styles.ctrlIconUpvoted]} size={18} /> <UpIconSolid
style={[styles.ctrlIconUpvoted]}
size={opts.big ? 22 : 18}
/>
) : ( ) : (
<UpIcon style={[styles.ctrlIcon]} size={18} strokeWidth={1.5} /> <UpIcon
style={[styles.ctrlIcon]}
size={opts.big ? 22 : 18}
strokeWidth={1.5}
/>
)} )}
</Animated.View> </Animated.View>
{typeof opts.upvoteCount !== 'undefined' ? (
<Text <Text
style={ style={
opts.isUpvoted opts.isUpvoted
@ -109,6 +122,7 @@ export function PostCtrls(opts: PostCtrlsOpts) {
}> }>
{opts.upvoteCount} {opts.upvoteCount}
</Text> </Text>
) : undefined}
</TouchableOpacity> </TouchableOpacity>
</View> </View>
<View style={s.flex1}></View> <View style={s.flex1}></View>