Tweak rendering of hashtags and expanded posts for clarity and information density
This commit is contained in:
+22
-4
@@ -1,5 +1,5 @@
|
||||
import React from 'react'
|
||||
import {StyleSheet, Pressable} from 'react-native'
|
||||
import {StyleSheet, Pressable, StyleProp, TextStyle} from 'react-native'
|
||||
import {
|
||||
FontAwesomeIcon,
|
||||
FontAwesomeIconStyle,
|
||||
@@ -7,18 +7,25 @@ import {
|
||||
|
||||
import {isWeb} from 'platform/detection'
|
||||
import {usePalette} from 'lib/hooks/usePalette'
|
||||
import {useTheme} from 'lib/ThemeContext'
|
||||
import {Text, CustomTextProps} from 'view/com/util/text/Text'
|
||||
import {TextLink} from 'view/com/util/Link'
|
||||
|
||||
export function Tag({
|
||||
value,
|
||||
textSize,
|
||||
smallSigil,
|
||||
style,
|
||||
}: {
|
||||
value: string
|
||||
textSize?: CustomTextProps['type']
|
||||
smallSigil?: boolean
|
||||
style?: StyleProp<TextStyle>
|
||||
}) {
|
||||
const pal = usePalette('default')
|
||||
const theme = useTheme()
|
||||
const type = textSize || 'xs-medium'
|
||||
const typeFontSize = theme.typography[type].fontSize || 16
|
||||
const hashtagFontSize = typeFontSize * (smallSigil ? 0.8 : 1)
|
||||
|
||||
return (
|
||||
<TextLink
|
||||
@@ -26,8 +33,19 @@ export function Tag({
|
||||
text={`#${value}`}
|
||||
accessible
|
||||
href={`/search?q=${value}`}
|
||||
style={[pal.textLight]}
|
||||
/>
|
||||
style={style}>
|
||||
<Text
|
||||
style={[
|
||||
style,
|
||||
{
|
||||
fontSize: hashtagFontSize,
|
||||
fontWeight: '500',
|
||||
},
|
||||
]}>
|
||||
#
|
||||
</Text>
|
||||
{value}
|
||||
</TextLink>
|
||||
)
|
||||
}
|
||||
|
||||
|
||||
@@ -53,7 +53,6 @@ export const PostThreadItem = observer(function PostThreadItem({
|
||||
const [deleted, setDeleted] = React.useState(false)
|
||||
const styles = useStyles()
|
||||
const record = item.postRecord
|
||||
const hasEngagement = item.post.likeCount || item.post.repostCount
|
||||
|
||||
const itemUri = item.post.uri
|
||||
const itemCid = item.post.cid
|
||||
@@ -332,25 +331,29 @@ export const PostThreadItem = observer(function PostThreadItem({
|
||||
)}
|
||||
</ContentHider>
|
||||
|
||||
{AppBskyFeedPost.isRecord(item.post.record) &&
|
||||
item.post.record.tags?.length ? (
|
||||
<View
|
||||
style={[
|
||||
pal.border,
|
||||
{
|
||||
flexDirection: 'row',
|
||||
flexWrap: 'wrap',
|
||||
gap: 8,
|
||||
paddingBottom: 12,
|
||||
marginBottom: 12,
|
||||
borderBottomWidth: 1,
|
||||
},
|
||||
]}>
|
||||
{item.post.record.tags.map(tag => (
|
||||
<Tag key={tag} value={tag} textSize="md-medium" />
|
||||
))}
|
||||
</View>
|
||||
) : null}
|
||||
<View style={[styles.expandedInfo, pal.border]}>
|
||||
{item.post.repostCount ? (
|
||||
<Link href={repostsHref} title={repostsTitle}>
|
||||
<Text testID="repostCount" type="lg" style={pal.textLight}>
|
||||
<Text type="xl-bold" style={pal.text}>
|
||||
{formatCount(item.post.repostCount)}
|
||||
</Text>{' '}
|
||||
{pluralize(item.post.repostCount, 'repost')}
|
||||
</Text>
|
||||
</Link>
|
||||
) : null}
|
||||
{item.post.likeCount ? (
|
||||
<Link href={likesHref} title={likesTitle}>
|
||||
<Text testID="likeCount" type="lg" style={pal.textLight}>
|
||||
<Text type="xl-bold" style={pal.text}>
|
||||
{formatCount(item.post.likeCount)}
|
||||
</Text>{' '}
|
||||
{pluralize(item.post.likeCount, 'like')}
|
||||
</Text>
|
||||
</Link>
|
||||
) : null}
|
||||
<Text style={pal.textLight}>{niceDate(item.post.indexedAt)}</Text>
|
||||
</View>
|
||||
|
||||
<ExpandedPostDetails
|
||||
post={item.post}
|
||||
@@ -358,43 +361,7 @@ export const PostThreadItem = observer(function PostThreadItem({
|
||||
needsTranslation={needsTranslation}
|
||||
/>
|
||||
|
||||
{hasEngagement ? (
|
||||
<View style={[styles.expandedInfo, pal.border]}>
|
||||
{item.post.repostCount ? (
|
||||
<Link
|
||||
style={styles.expandedInfoItem}
|
||||
href={repostsHref}
|
||||
title={repostsTitle}>
|
||||
<Text testID="repostCount" type="lg" style={pal.textLight}>
|
||||
<Text type="xl-bold" style={pal.text}>
|
||||
{formatCount(item.post.repostCount)}
|
||||
</Text>{' '}
|
||||
{pluralize(item.post.repostCount, 'repost')}
|
||||
</Text>
|
||||
</Link>
|
||||
) : (
|
||||
<></>
|
||||
)}
|
||||
{item.post.likeCount ? (
|
||||
<Link
|
||||
style={styles.expandedInfoItem}
|
||||
href={likesHref}
|
||||
title={likesTitle}>
|
||||
<Text testID="likeCount" type="lg" style={pal.textLight}>
|
||||
<Text type="xl-bold" style={pal.text}>
|
||||
{formatCount(item.post.likeCount)}
|
||||
</Text>{' '}
|
||||
{pluralize(item.post.likeCount, 'like')}
|
||||
</Text>
|
||||
</Link>
|
||||
) : (
|
||||
<></>
|
||||
)}
|
||||
</View>
|
||||
) : (
|
||||
<></>
|
||||
)}
|
||||
<View style={[s.pb5]}>
|
||||
<View style={{paddingTop: 15, paddingBottom: 5}}>
|
||||
<PostCtrls
|
||||
big
|
||||
itemUri={itemUri}
|
||||
@@ -649,17 +616,37 @@ function ExpandedPostDetails({
|
||||
translatorUrl: string
|
||||
}) {
|
||||
const pal = usePalette('default')
|
||||
const hasTags =
|
||||
AppBskyFeedPost.isRecord(post.record) && post.record.tags?.length
|
||||
if (!hasTags && !needsTranslation) {
|
||||
return null
|
||||
}
|
||||
return (
|
||||
<View style={[s.flexRow, s.mt2, s.mb10]}>
|
||||
<Text style={pal.textLight}>{niceDate(post.indexedAt)}</Text>
|
||||
<View
|
||||
style={{
|
||||
flexDirection: 'row',
|
||||
flexWrap: 'wrap',
|
||||
marginTop: 10,
|
||||
marginBottom: 2,
|
||||
rowGap: 6,
|
||||
columnGap: 8,
|
||||
}}>
|
||||
{needsTranslation && (
|
||||
<>
|
||||
<Text style={pal.textLight}> • </Text>
|
||||
<Link href={translatorUrl} title="Translate">
|
||||
<Text style={pal.link}>Translate</Text>
|
||||
</Link>
|
||||
</>
|
||||
<Link href={translatorUrl} title="Translate">
|
||||
<Text style={pal.link}>Translate</Text>
|
||||
</Link>
|
||||
)}
|
||||
{hasTags && AppBskyFeedPost.isRecord(post.record)
|
||||
? post.record.tags!.map(tag => (
|
||||
<Tag
|
||||
key={tag}
|
||||
value={tag}
|
||||
textSize="md"
|
||||
style={pal.textLight}
|
||||
smallSigil
|
||||
/>
|
||||
))
|
||||
: null}
|
||||
</View>
|
||||
)
|
||||
}
|
||||
@@ -714,7 +701,7 @@ const useStyles = () => {
|
||||
},
|
||||
postTextLargeContainer: {
|
||||
paddingHorizontal: 0,
|
||||
paddingBottom: 10,
|
||||
// paddingBottom: 10,
|
||||
},
|
||||
translateLink: {
|
||||
marginBottom: 6,
|
||||
@@ -727,14 +714,14 @@ const useStyles = () => {
|
||||
},
|
||||
expandedInfo: {
|
||||
flexDirection: 'row',
|
||||
flexWrap: 'wrap',
|
||||
alignItems: 'baseline',
|
||||
gap: 12,
|
||||
paddingVertical: 10,
|
||||
paddingHorizontal: 2,
|
||||
borderTopWidth: 1,
|
||||
borderBottomWidth: 1,
|
||||
marginTop: 5,
|
||||
marginBottom: 15,
|
||||
},
|
||||
expandedInfoItem: {
|
||||
marginRight: 10,
|
||||
},
|
||||
loadMore: {
|
||||
flexDirection: 'row',
|
||||
|
||||
+16
-13
@@ -148,19 +148,22 @@ export const TextLink = observer(function TextLink({
|
||||
title,
|
||||
onPress,
|
||||
warnOnMismatchingLabel,
|
||||
children,
|
||||
...orgProps
|
||||
}: {
|
||||
testID?: string
|
||||
type?: TypographyVariant
|
||||
style?: StyleProp<TextStyle>
|
||||
href: string
|
||||
text: string | JSX.Element | React.ReactNode
|
||||
numberOfLines?: number
|
||||
lineHeight?: number
|
||||
dataSet?: any
|
||||
title?: string
|
||||
warnOnMismatchingLabel?: boolean
|
||||
} & TextProps) {
|
||||
}: React.PropsWithChildren<
|
||||
{
|
||||
testID?: string
|
||||
type?: TypographyVariant
|
||||
style?: StyleProp<TextStyle>
|
||||
href: string
|
||||
text: string | JSX.Element | React.ReactNode
|
||||
numberOfLines?: number
|
||||
lineHeight?: number
|
||||
dataSet?: any
|
||||
title?: string
|
||||
warnOnMismatchingLabel?: boolean
|
||||
} & TextProps
|
||||
>) {
|
||||
const {...props} = useLinkProps({to: sanitizeUrl(href)})
|
||||
const store = useStores()
|
||||
const navigation = useNavigation<NavigationProp>()
|
||||
@@ -215,7 +218,7 @@ export const TextLink = observer(function TextLink({
|
||||
hrefAttrs={hrefAttrs} // hack to get open in new tab to work on safari. without this, safari will open in a new window
|
||||
{...props}
|
||||
{...orgProps}>
|
||||
{text}
|
||||
{children || text}
|
||||
</Text>
|
||||
)
|
||||
})
|
||||
|
||||
@@ -95,7 +95,15 @@ export function RichText({
|
||||
/>,
|
||||
)
|
||||
} else if (tag && AppBskyRichtextFacet.validateTag(tag).success) {
|
||||
els.push(<Tag key={key} value={tag.tag} textSize={type} />)
|
||||
els.push(
|
||||
<Tag
|
||||
key={key}
|
||||
value={tag.tag}
|
||||
textSize={type}
|
||||
style={pal.link}
|
||||
smallSigil
|
||||
/>,
|
||||
)
|
||||
} else {
|
||||
els.push(segment.text)
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user