Skip to content

Commit

Permalink
[feat] don't show downvotes if disabled on instance
Browse files Browse the repository at this point in the history
  • Loading branch information
gkasdorf committed Nov 3, 2023
1 parent eb96c50 commit 5ad55cb
Show file tree
Hide file tree
Showing 4 changed files with 52 additions and 29 deletions.
32 changes: 20 additions & 12 deletions src/components/Comment/components/CommentMetrics.tsx
Original file line number Diff line number Diff line change
@@ -1,5 +1,9 @@
import React, { useMemo } from 'react';
import { useCommentPublished, useShowTotalScore } from '@src/state';
import {
useCommentPublished,
useDownvotesAllowed,
useShowTotalScore,
} from '@src/state';
import { Text, XStack } from 'tamagui';
import ScoreIcon from '@components/Common/Icons/ScoreIcon';
import { ArrowDown, ArrowUp, Clock } from '@tamagui/lucide-icons';
Expand All @@ -12,6 +16,8 @@ interface IProps {
}

function CommentMetrics({ itemId }: IProps): React.JSX.Element {
const downvotesAllowed = useDownvotesAllowed();

const commentPublished = useCommentPublished(itemId);
const voting = useCommentVoting(itemId, true);
const showTotalScore = useShowTotalScore();
Expand Down Expand Up @@ -56,17 +62,19 @@ function CommentMetrics({ itemId }: IProps): React.JSX.Element {
{voting.upvotes}
</Text>
</XStack>
<XStack
space="$1"
onPress={voting.downvote}
hitSlop={3}
alignItems="center"
>
<ArrowDown size={14} color={metricsColors.downvoteColor} />
<Text fontSize="$2" color={metricsColors.downvoteColor}>
{voting.downvotes}
</Text>
</XStack>
{downvotesAllowed && (
<XStack
space="$1"
onPress={voting.downvote}
hitSlop={3}
alignItems="center"
>
<ArrowDown size={14} color={metricsColors.downvoteColor} />
<Text fontSize="$2" color={metricsColors.downvoteColor}>
{voting.downvotes}
</Text>
</XStack>
)}
<XStack space="$1.5" alignItems="center">
<Clock size={14} color="$secondary" />
<Text fontSize="$2" color="$secondary">
Expand Down
17 changes: 11 additions & 6 deletions src/components/Common/PostCard/PostMetrics.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@ import {
MessageSquare,
} from '@tamagui/lucide-icons';
import {
useDownvotesAllowed,
usePostCommentCount,
usePostCounts,
usePostMyVote,
Expand All @@ -23,6 +24,8 @@ interface IProps {
function PostMetrics({ itemId }: IProps): React.JSX.Element {
const showTotalScore = useSettingsStore((state) => state.totalScore);

const downvotesAllowed = useDownvotesAllowed();

const postCounts = usePostCounts(itemId);
const postCommentCount = usePostCommentCount(itemId);
const postMyVote = usePostMyVote(itemId);
Expand Down Expand Up @@ -65,12 +68,14 @@ function PostMetrics({ itemId }: IProps): React.JSX.Element {
{postCounts?.upvotes}
</Text>
</XStack>
<XStack space="$1" alignItems="center">
<ArrowDown size={14} color={downvoteColor} />
<Text color={downvoteColor} fontSize="$2">
{postCounts?.downvotes}
</Text>
</XStack>
{downvotesAllowed && (
<XStack space="$1" alignItems="center">
<ArrowDown size={14} color={downvoteColor} />
<Text color={downvoteColor} fontSize="$2">
{postCounts?.downvotes}
</Text>
</XStack>
)}
</XStack>
)}

Expand Down
27 changes: 16 additions & 11 deletions src/components/Inbox/components/InboxReplyMetrics.tsx
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
import React, { useMemo } from 'react';
import {
useDownvotesAllowed,
useMentionPublished,
useReplyPublished,
useSettingsStore,
Expand All @@ -21,6 +22,8 @@ function InboxReplyMetrics({
commentId,
type,
}: IProps): React.JSX.Element {
const downvotesAllowed = useDownvotesAllowed();

const voting = useInboxReplyVoting(itemId, commentId, type);

const published =
Expand Down Expand Up @@ -83,17 +86,19 @@ function InboxReplyMetrics({
{voting.upvotes}
</Text>
</XStack>
<XStack
space="$1"
onPress={voting.downvote}
hitSlop={3}
alignItems="center"
>
<ArrowDown size={14} color={downvoteColor} />
<Text fontSize="$2" color={downvoteColor}>
{voting.downvotes}
</Text>
</XStack>
{downvotesAllowed && (
<XStack
space="$1"
onPress={voting.downvote}
hitSlop={3}
alignItems="center"
>
<ArrowDown size={14} color={downvoteColor} />
<Text fontSize="$2" color={downvoteColor}>
{voting.downvotes}
</Text>
</XStack>
)}
<XStack space="$1.5" alignItems="center">
<Clock size={14} color="$secondary" />
<Text fontSize="$2" color="$secondary">
Expand Down
5 changes: 5 additions & 0 deletions src/state/data/site/selectors.ts
Original file line number Diff line number Diff line change
Expand Up @@ -39,3 +39,8 @@ export const useBlockedPersons = (): PersonBlockView[] | undefined =>

export const useBlockedCommunities = (): CommunityBlockView[] | undefined =>
useDataStore((state) => state.site.site?.my_user?.community_blocks);

export const useDownvotesAllowed = (): boolean =>
useDataStore(
(state) => state.site.site?.site_view.local_site.enable_downvotes ?? false,
);

0 comments on commit 5ad55cb

Please sign in to comment.