From 2f0939a1c298a9b7db17005677fc2819b5cb4095 Mon Sep 17 00:00:00 2001 From: Paul Frazee Date: Fri, 2 Sep 2022 11:52:33 -0500 Subject: Implement consistent Link component --- src/view/com/post-thread/PostThreadItem.tsx | 120 +++++++++++++++------------- 1 file changed, 65 insertions(+), 55 deletions(-) (limited to 'src/view/com/post-thread/PostThreadItem.tsx') diff --git a/src/view/com/post-thread/PostThreadItem.tsx b/src/view/com/post-thread/PostThreadItem.tsx index 376ec6805..5909cac8a 100644 --- a/src/view/com/post-thread/PostThreadItem.tsx +++ b/src/view/com/post-thread/PostThreadItem.tsx @@ -1,9 +1,10 @@ -import React from 'react' +import React, {useMemo} 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 {FontAwesomeIcon} from '@fortawesome/react-native-fontawesome' import {PostThreadViewPostModel} from '../../../state/models/post-thread-view' +import {Link} from '../util/Link' import {s, colors} from '../../lib/styles' import {ago, pluralize} from '../../lib/strings' import {AVIS} from '../../lib/assets' @@ -20,25 +21,24 @@ export const PostThreadItem = observer(function PostThreadItem({ const record = item.record as unknown as bsky.Post.Record const hasEngagement = item.likeCount || item.repostCount - const onPressOuter = () => { + const itemHref = useMemo(() => { const urip = new AdxUri(item.uri) - store.nav.navigate(`/profile/${item.author.name}/post/${urip.recordKey}`) - } - const onPressAuthor = () => { - store.nav.navigate(`/profile/${item.author.name}`) - } - const onPressLikes = () => { + return `/profile/${item.author.name}/post/${urip.recordKey}` + }, [item.uri, item.author.name]) + const itemTitle = `Post by ${item.author.name}` + const authorHref = `/profile/${item.author.name}` + const authorTitle = item.author.name + const likesHref = useMemo(() => { const urip = new AdxUri(item.uri) - store.nav.navigate( - `/profile/${item.author.name}/post/${urip.recordKey}/liked-by`, - ) - } - const onPressReposts = () => { + return `/profile/${item.author.name}/post/${urip.recordKey}/liked-by` + }, [item.uri, item.author.name]) + const likesTitle = 'Likes on this post' + const repostsHref = useMemo(() => { const urip = new AdxUri(item.uri) - store.nav.navigate( - `/profile/${item.author.name}/post/${urip.recordKey}/reposted-by`, - ) - } + return `/profile/${item.author.name}/post/${urip.recordKey}/reposted-by` + }, [item.uri, item.author.name]) + const repostsTitle = 'Reposts of this post' + const onPressReply = () => { store.nav.navigate(`/composer?replyTo=${item.uri}`) } @@ -102,29 +102,31 @@ export const PostThreadItem = observer(function PostThreadItem({ return ( - + - + - - {item.author.displayName} - + + {item.author.displayName} + · {ago(item.indexedAt)} - - @{item.author.name} - + + @{item.author.name} + @@ -135,22 +137,28 @@ export const PostThreadItem = observer(function PostThreadItem({ {item._isHighlightedPost && hasEngagement ? ( {item.repostCount ? ( - - {item.repostCount}{' '} - {pluralize(item.repostCount, 'repost')} - + + + {item.repostCount}{' '} + {pluralize(item.repostCount, 'repost')} + + ) : ( <> )} {item.likeCount ? ( - - {item.likeCount}{' '} - {pluralize(item.likeCount, 'like')} - + + + {item.likeCount}{' '} + {pluralize(item.likeCount, 'like')} + + ) : ( <> )} @@ -166,26 +174,28 @@ export const PostThreadItem = observer(function PostThreadItem({ ) } else { return ( - + - + - + - - {item.author.displayName} - - - @{item.author.name} - + + {item.author.displayName} + + + @{item.author.name} + · {ago(item.indexedAt)} @@ -196,7 +206,7 @@ export const PostThreadItem = observer(function PostThreadItem({ - + ) } }) -- cgit 1.4.1