From 1fbc4cf1f2279cf4cf6804ff02616515e82d2a38 Mon Sep 17 00:00:00 2001 From: Paul Frazee Date: Tue, 8 Nov 2022 12:14:51 -0600 Subject: Finish the upvote/downvote implementation --- src/view/com/post-thread/PostThreadItem.tsx | 68 +++++++++++++++++++++-------- 1 file changed, 50 insertions(+), 18 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 17f37cb2e..a4b628101 100644 --- a/src/view/com/post-thread/PostThreadItem.tsx +++ b/src/view/com/post-thread/PostThreadItem.tsx @@ -28,7 +28,8 @@ export const PostThreadItem = observer(function PostThreadItem({ }) { const store = useStores() const record = item.record as unknown as PostType.Record - const hasEngagement = item.likeCount || item.repostCount + const hasEngagement = + item.upvoteCount || item.downvoteCount || item.repostCount const itemHref = useMemo(() => { const urip = new AtUri(item.uri) @@ -37,11 +38,16 @@ export const PostThreadItem = observer(function PostThreadItem({ const itemTitle = `Post by ${item.author.handle}` const authorHref = `/profile/${item.author.handle}` const authorTitle = item.author.handle - const likesHref = useMemo(() => { + const upvotesHref = useMemo(() => { const urip = new AtUri(item.uri) - return `/profile/${item.author.handle}/post/${urip.rkey}/liked-by` + return `/profile/${item.author.handle}/post/${urip.rkey}/upvoted-by` }, [item.uri, item.author.handle]) - const likesTitle = 'Likes on this post' + const upvotesTitle = 'Upvotes on this post' + const downvotesHref = useMemo(() => { + const urip = new AtUri(item.uri) + return `/profile/${item.author.handle}/post/${urip.rkey}/downvoted-by` + }, [item.uri, item.author.handle]) + const downvotesTitle = 'Downvotes on this post' const repostsHref = useMemo(() => { const urip = new AtUri(item.uri) return `/profile/${item.author.handle}/post/${urip.rkey}/reposted-by` @@ -59,10 +65,15 @@ export const PostThreadItem = observer(function PostThreadItem({ .toggleRepost() .catch(e => console.error('Failed to toggle repost', record, e)) } - const onPressToggleLike = () => { + const onPressToggleUpvote = () => { + item + .toggleUpvote() + .catch(e => console.error('Failed to toggle upvote', record, e)) + } + const onPressToggleDownvote = () => { item - .toggleLike() - .catch(e => console.error('Failed to toggle like', record, e)) + .toggleDownvote() + .catch(e => console.error('Failed to toggle downvote', record, e)) } if (item._isHighlightedPost) { @@ -135,16 +146,31 @@ export const PostThreadItem = observer(function PostThreadItem({ ) : ( <> )} - {item.likeCount ? ( + {item.upvoteCount ? ( + + + + {item.upvoteCount} + {' '} + {pluralize(item.upvoteCount, 'upvote')} + + + ) : ( + <> + )} + {item.downvoteCount ? ( + href={downvotesHref} + title={downvotesTitle}> - {item.likeCount} + {item.downvoteCount} {' '} - {pluralize(item.likeCount, 'like')} + {pluralize(item.downvoteCount, 'downvote')} ) : ( @@ -158,12 +184,15 @@ export const PostThreadItem = observer(function PostThreadItem({ @@ -260,12 +289,15 @@ export const PostThreadItem = observer(function PostThreadItem({ -- cgit 1.4.1