Move menu controls into post footers and improve meta info rendering

zio/stable
Paul Frazee 2023-01-16 16:09:51 -06:00
parent 0e85b33276
commit 7f8f53b087
5 changed files with 58 additions and 53 deletions

View File

@ -222,11 +222,16 @@ export const PostThreadItem = observer(function PostThreadItem({
<View style={[s.pl10, s.pb5]}> <View style={[s.pl10, s.pb5]}>
<PostCtrls <PostCtrls
big big
itemHref={itemHref}
itemTitle={itemTitle}
isAuthor={item.post.author.did === store.me.did}
isReposted={!!item.post.viewer.repost} isReposted={!!item.post.viewer.repost}
isUpvoted={!!item.post.viewer.upvote} isUpvoted={!!item.post.viewer.upvote}
onPressReply={onPressReply} onPressReply={onPressReply}
onPressToggleRepost={onPressToggleRepost} onPressToggleRepost={onPressToggleRepost}
onPressToggleUpvote={onPressToggleUpvote} onPressToggleUpvote={onPressToggleUpvote}
onCopyPostText={onCopyPostText}
onDeletePost={onDeletePost}
/> />
</View> </View>
</View> </View>
@ -276,15 +281,10 @@ export const PostThreadItem = observer(function PostThreadItem({
</View> </View>
<View style={styles.layoutContent}> <View style={styles.layoutContent}>
<PostMeta <PostMeta
itemHref={itemHref}
itemTitle={itemTitle}
authorHref={authorHref} authorHref={authorHref}
authorHandle={item.post.author.handle} authorHandle={item.post.author.handle}
authorDisplayName={item.post.author.displayName} authorDisplayName={item.post.author.displayName}
timestamp={item.post.indexedAt} timestamp={item.post.indexedAt}
isAuthor={item.post.author.did === store.me.did}
onCopyPostText={onCopyPostText}
onDeletePost={onDeletePost}
/> />
{item.post.author.viewer?.muted ? ( {item.post.author.viewer?.muted ? (
<View style={[styles.mutedWarning, pal.btn]}> <View style={[styles.mutedWarning, pal.btn]}>
@ -304,14 +304,16 @@ export const PostThreadItem = observer(function PostThreadItem({
)} )}
<PostEmbeds embed={item.post.embed} style={{marginBottom: 10}} /> <PostEmbeds embed={item.post.embed} style={{marginBottom: 10}} />
<PostCtrls <PostCtrls
replyCount={item.post.replyCount} itemHref={itemHref}
repostCount={item.post.repostCount} itemTitle={itemTitle}
upvoteCount={item.post.upvoteCount} isAuthor={item.post.author.did === store.me.did}
isReposted={!!item.post.viewer.repost} isReposted={!!item.post.viewer.repost}
isUpvoted={!!item.post.viewer.upvote} isUpvoted={!!item.post.viewer.upvote}
onPressReply={onPressReply} onPressReply={onPressReply}
onPressToggleRepost={onPressToggleRepost} onPressToggleRepost={onPressToggleRepost}
onPressToggleUpvote={onPressToggleUpvote} onPressToggleUpvote={onPressToggleUpvote}
onCopyPostText={onCopyPostText}
onDeletePost={onDeletePost}
/> />
</View> </View>
</View> </View>

View File

@ -154,15 +154,10 @@ export const Post = observer(function Post({
</View> </View>
<View style={styles.layoutContent}> <View style={styles.layoutContent}>
<PostMeta <PostMeta
itemHref={itemHref}
itemTitle={itemTitle}
authorHref={authorHref} authorHref={authorHref}
authorHandle={item.post.author.handle} authorHandle={item.post.author.handle}
authorDisplayName={item.post.author.displayName} authorDisplayName={item.post.author.displayName}
timestamp={item.post.indexedAt} timestamp={item.post.indexedAt}
isAuthor={item.post.author.did === store.me.did}
onCopyPostText={onCopyPostText}
onDeletePost={onDeletePost}
/> />
{replyHref !== '' && ( {replyHref !== '' && (
<View style={[s.flexRow, s.mb2, {alignItems: 'center'}]}> <View style={[s.flexRow, s.mb2, {alignItems: 'center'}]}>
@ -198,6 +193,9 @@ export const Post = observer(function Post({
)} )}
<PostEmbeds embed={item.post.embed} style={{marginBottom: 10}} /> <PostEmbeds embed={item.post.embed} style={{marginBottom: 10}} />
<PostCtrls <PostCtrls
itemHref={itemHref}
itemTitle={itemTitle}
isAuthor={item.post.author.did === store.me.did}
replyCount={item.post.replyCount} replyCount={item.post.replyCount}
repostCount={item.post.repostCount} repostCount={item.post.repostCount}
upvoteCount={item.post.upvoteCount} upvoteCount={item.post.upvoteCount}
@ -206,6 +204,8 @@ export const Post = observer(function Post({
onPressReply={onPressReply} onPressReply={onPressReply}
onPressToggleRepost={onPressToggleRepost} onPressToggleRepost={onPressToggleRepost}
onPressToggleUpvote={onPressToggleUpvote} onPressToggleUpvote={onPressToggleUpvote}
onCopyPostText={onCopyPostText}
onDeletePost={onDeletePost}
/> />
</View> </View>
</View> </View>

View File

@ -177,15 +177,10 @@ export const FeedItem = observer(function ({
</View> </View>
<View style={styles.layoutContent}> <View style={styles.layoutContent}>
<PostMeta <PostMeta
itemHref={itemHref}
itemTitle={itemTitle}
authorHref={authorHref} authorHref={authorHref}
authorHandle={item.post.author.handle} authorHandle={item.post.author.handle}
authorDisplayName={item.post.author.displayName} authorDisplayName={item.post.author.displayName}
timestamp={item.post.indexedAt} timestamp={item.post.indexedAt}
isAuthor={item.post.author.did === store.me.did}
onCopyPostText={onCopyPostText}
onDeletePost={onDeletePost}
/> />
{!isChild && replyHref !== '' && ( {!isChild && replyHref !== '' && (
<View style={[s.flexRow, s.mb2, {alignItems: 'center'}]}> <View style={[s.flexRow, s.mb2, {alignItems: 'center'}]}>
@ -226,6 +221,9 @@ export const FeedItem = observer(function ({
)} )}
<PostEmbeds embed={item.post.embed} style={styles.postEmbeds} /> <PostEmbeds embed={item.post.embed} style={styles.postEmbeds} />
<PostCtrls <PostCtrls
itemHref={itemHref}
itemTitle={itemTitle}
isAuthor={item.post.author.did === store.me.did}
replyCount={item.post.replyCount} replyCount={item.post.replyCount}
repostCount={item.post.repostCount} repostCount={item.post.repostCount}
upvoteCount={item.post.upvoteCount} upvoteCount={item.post.upvoteCount}
@ -234,6 +232,8 @@ export const FeedItem = observer(function ({
onPressReply={onPressReply} onPressReply={onPressReply}
onPressToggleRepost={onPressToggleRepost} onPressToggleRepost={onPressToggleRepost}
onPressToggleUpvote={onPressToggleUpvote} onPressToggleUpvote={onPressToggleUpvote}
onCopyPostText={onCopyPostText}
onDeletePost={onDeletePost}
/> />
</View> </View>
</View> </View>

View File

@ -3,11 +3,15 @@ import {Animated, StyleSheet, TouchableOpacity, View} from 'react-native'
import {FontAwesomeIcon} from '@fortawesome/react-native-fontawesome' import {FontAwesomeIcon} from '@fortawesome/react-native-fontawesome'
import ReactNativeHapticFeedback from 'react-native-haptic-feedback' import ReactNativeHapticFeedback from 'react-native-haptic-feedback'
import {Text} from './text/Text' import {Text} from './text/Text'
import {PostDropdownBtn} from './forms/DropdownButton'
import {UpIcon, UpIconSolid, CommentBottomArrow} from '../../lib/icons' import {UpIcon, UpIconSolid, CommentBottomArrow} from '../../lib/icons'
import {s, colors} from '../../lib/styles' import {s, colors} from '../../lib/styles'
import {useAnimatedValue} from '../../lib/hooks/useAnimatedValue' import {useAnimatedValue} from '../../lib/hooks/useAnimatedValue'
interface PostCtrlsOpts { interface PostCtrlsOpts {
itemHref: string
itemTitle: string
isAuthor: boolean
big?: boolean big?: boolean
replyCount?: number replyCount?: number
repostCount?: number repostCount?: number
@ -17,6 +21,8 @@ interface PostCtrlsOpts {
onPressReply: () => void onPressReply: () => void
onPressToggleRepost: () => void onPressToggleRepost: () => void
onPressToggleUpvote: () => void onPressToggleUpvote: () => void
onCopyPostText: () => void
onDeletePost: () => void
} }
const redgray = '#7A6161' const redgray = '#7A6161'
@ -169,7 +175,23 @@ export function PostCtrls(opts: PostCtrlsOpts) {
) : undefined} ) : undefined}
</TouchableOpacity> </TouchableOpacity>
</View> </View>
<View style={s.flex1}></View> <View style={s.flex1}>
{opts.big ? undefined : (
<PostDropdownBtn
style={styles.ctrl}
itemHref={opts.itemHref}
itemTitle={opts.itemTitle}
isAuthor={opts.isAuthor}
onCopyPostText={opts.onCopyPostText}
onDeletePost={opts.onDeletePost}>
<FontAwesomeIcon
icon="ellipsis-h"
size={16}
style={[s.mt2, s.mr5, sRedgray]}
/>
</PostDropdownBtn>
)}
</View>
</View> </View>
) )
} }

View File

@ -1,28 +1,18 @@
import React from 'react' import React from 'react'
import {StyleSheet, View} from 'react-native' import {Platform, StyleSheet, View} from 'react-native'
import {FontAwesomeIcon} from '@fortawesome/react-native-fontawesome'
import {Link} from '../util/Link' import {Link} from '../util/Link'
import {Text} from './text/Text' import {Text} from './text/Text'
import {PostDropdownBtn} from './forms/DropdownButton'
import {s} from '../../lib/styles'
import {ago} from '../../../lib/strings' import {ago} from '../../../lib/strings'
import {useTheme} from '../../lib/ThemeContext'
import {usePalette} from '../../lib/hooks/usePalette' import {usePalette} from '../../lib/hooks/usePalette'
interface PostMetaOpts { interface PostMetaOpts {
itemHref: string
itemTitle: string
authorHref: string authorHref: string
authorHandle: string authorHandle: string
authorDisplayName: string | undefined authorDisplayName: string | undefined
timestamp: string timestamp: string
isAuthor: boolean
onCopyPostText: () => void
onDeletePost: () => void
} }
export function PostMeta(opts: PostMetaOpts) { export function PostMeta(opts: PostMetaOpts) {
const theme = useTheme()
const pal = usePalette('default') const pal = usePalette('default')
let displayName = opts.authorDisplayName || opts.authorHandle let displayName = opts.authorDisplayName || opts.authorHandle
let handle = opts.authorHandle let handle = opts.authorHandle
@ -31,6 +21,7 @@ export function PostMeta(opts: PostMetaOpts) {
// Android simply cannot handle the truncation case we need // Android simply cannot handle the truncation case we need
// so we have to do it manually here // so we have to do it manually here
// -prf // -prf
if (Platform.OS === 'android') {
if (displayName.length + handle.length > 26) { if (displayName.length + handle.length > 26) {
if (displayName.length > 26) { if (displayName.length > 26) {
displayName = displayName.slice(0, 23) + '...' displayName = displayName.slice(0, 23) + '...'
@ -41,11 +32,12 @@ export function PostMeta(opts: PostMetaOpts) {
} }
} }
} }
}
return ( return (
<View style={styles.meta}> <View style={styles.meta}>
<Link <Link
style={styles.metaItem} style={[styles.metaItem, styles.maxWidth]}
href={opts.authorHref} href={opts.authorHref}
title={opts.authorHandle}> title={opts.authorHandle}>
<Text type="h5" style={[pal.text]} numberOfLines={1}> <Text type="h5" style={[pal.text]} numberOfLines={1}>
@ -60,20 +52,6 @@ export function PostMeta(opts: PostMetaOpts) {
<Text type="h6" style={[styles.metaItem, pal.textLight]}> <Text type="h6" style={[styles.metaItem, pal.textLight]}>
&middot; {ago(opts.timestamp)} &middot; {ago(opts.timestamp)}
</Text> </Text>
<View style={s.flex1} />
<PostDropdownBtn
style={[styles.metaItem, s.pl5]}
itemHref={opts.itemHref}
itemTitle={opts.itemTitle}
isAuthor={opts.isAuthor}
onCopyPostText={opts.onCopyPostText}
onDeletePost={opts.onDeletePost}>
<FontAwesomeIcon
icon="ellipsis-h"
size={14}
style={[s.mt2, s.mr5, pal.text]}
/>
</PostDropdownBtn>
</View> </View>
) )
} }
@ -81,11 +59,14 @@ export function PostMeta(opts: PostMetaOpts) {
const styles = StyleSheet.create({ const styles = StyleSheet.create({
meta: { meta: {
flexDirection: 'row', flexDirection: 'row',
alignItems: 'center', alignItems: 'baseline',
paddingTop: 0, paddingTop: 0,
paddingBottom: 2, paddingBottom: 2,
}, },
metaItem: { metaItem: {
paddingRight: 5, paddingRight: 5,
}, },
maxWidth: {
maxWidth: '70%',
},
}) })