Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
60 changes: 0 additions & 60 deletions packages/extension/src/companion/CompanionEngagements.spec.tsx

This file was deleted.

23 changes: 1 addition & 22 deletions packages/extension/src/companion/CompanionEngagements.tsx
Original file line number Diff line number Diff line change
@@ -1,15 +1,10 @@
import type { ReactElement } from 'react';
import React from 'react';
import type { PostBootData } from '@dailydotdev/shared/src/lib/boot';
import { UserVote } from '@dailydotdev/shared/src/graphql/posts';
import { ClickableText } from '@dailydotdev/shared/src/components/buttons/ClickableText';
import { useAuthContext } from '@dailydotdev/shared/src/contexts/AuthContext';
import { useQueryClient } from '@tanstack/react-query';
import { useRawBackgroundRequest } from '@dailydotdev/shared/src/hooks/companion';
import { useConditionalFeature } from '@dailydotdev/shared/src/hooks/useConditionalFeature';
import { largeNumberFormat } from '@dailydotdev/shared/src/lib';
import { featureUpvoteCountThreshold } from '@dailydotdev/shared/src/lib/featureManagement';
import { getUpvoteCountDisplay } from '@dailydotdev/shared/src/lib/post';

interface CompanionEngagementsProps {
post: PostBootData;
Expand All @@ -20,8 +15,6 @@ export function CompanionEngagements({
post,
onUpvotesClick,
}: CompanionEngagementsProps): ReactElement | null {
const { user } = useAuthContext();
const isLoggedIn = !!user;
const client = useQueryClient();
useRawBackgroundRequest(({ res, key }) => {
if (!Array.isArray(key)) {
Expand All @@ -35,34 +28,20 @@ export function CompanionEngagements({
client.setQueryData(key, res);
});

const { value: upvoteThresholdConfig } = useConditionalFeature({
feature: featureUpvoteCountThreshold,
shouldEvaluate: isLoggedIn,
});

if (!post) {
return null;
}

const upvotes = post.numUpvotes ?? 0;
const comments = post.numComments ?? 0;
const userHasUpvoted = post.userState?.vote === UserVote.Up;
const { showCount } = getUpvoteCountDisplay(
upvotes,
upvoteThresholdConfig.threshold,
upvoteThresholdConfig.belowThresholdLabel,
userHasUpvoted,
post.createdAt,
upvoteThresholdConfig.newWindowHours,
);

return (
<div
className="flex items-center gap-x-4 py-1 text-text-tertiary typo-callout"
data-testid="statsBar"
>
{upvotes <= 0 && <span>Be the first to upvote</span>}
{showCount && (
{upvotes > 0 && (
<ClickableText onClick={onUpvotesClick}>
{largeNumberFormat(upvotes)} Upvote
{upvotes > 1 ? 's' : ''}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,43 +3,19 @@ import React from 'react';
import classNames from 'classnames';
import { separatorCharacter } from '../common/common';
import { largeNumberFormat } from '../../../lib';
import { useConditionalFeature } from '../../../hooks/useConditionalFeature';
import { featureUpvoteCountThreshold } from '../../../lib/featureManagement';
import { getUpvoteCountDisplay } from '../../../lib/post';

interface PostEngagementCountsProps {
upvotes: number;
comments: number;
createdAt?: string;
className?: string;
userHasUpvoted?: boolean;
shouldEvaluateFeature?: boolean;
}

export function PostEngagementCounts({
upvotes,
comments,
createdAt,
className,
userHasUpvoted = false,
shouldEvaluateFeature = false,
}: PostEngagementCountsProps): ReactElement {
const { value: upvoteThresholdConfig } = useConditionalFeature({
feature: featureUpvoteCountThreshold,
shouldEvaluate: shouldEvaluateFeature,
});
const { showCount, belowThresholdLabel } = getUpvoteCountDisplay(
upvotes,
upvoteThresholdConfig.threshold,
upvoteThresholdConfig.belowThresholdLabel,
userHasUpvoted,
createdAt,
upvoteThresholdConfig.newWindowHours,
);

const upvoteText = showCount
? `${largeNumberFormat(upvotes)} Upvotes`
: belowThresholdLabel || '';
const upvoteText = upvotes > 0 ? `${largeNumberFormat(upvotes)} Upvotes` : '';
const hasUpvoteText = !!upvoteText;

return (
Expand Down
34 changes: 1 addition & 33 deletions packages/shared/src/components/cards/common/ActionButtons.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -11,9 +11,6 @@ import {
} from '../../icons';
import { ButtonColor, ButtonSize, ButtonVariant } from '../../buttons/Button';
import { useFeedPreviewMode } from '../../../hooks';
import { useConditionalFeature } from '../../../hooks/useConditionalFeature';
import { featureUpvoteCountThreshold } from '../../../lib/featureManagement';
import { getUpvoteCountDisplay } from '../../../lib/post';
import { UpvoteButtonIcon } from './UpvoteButtonIcon';
import { BookmarkButton } from '../../buttons';
import { IconSize } from '../../Icon';
Expand All @@ -22,7 +19,6 @@ import PostAwardAction from '../../post/PostAwardAction';
import ConditionalWrapper from '../../ConditionalWrapper';
import { PostTagsPanel } from '../../post/block/PostTagsPanel';
import { LinkWithTooltip } from '../../tooltips/LinkWithTooltip';
import { useAuthContext } from '../../../contexts/AuthContext';
import { useCardActions } from '../../../hooks/cards/useCardActions';

export type ActionButtonsVariant = 'grid' | 'list' | 'signal';
Expand Down Expand Up @@ -79,8 +75,6 @@ const ActionButtons = ({
}: ActionButtonsProps): ReactElement | null => {
const config = variantConfig[variant];
const isFeedPreview = useFeedPreviewMode();
const { user } = useAuthContext();
const isLoggedIn = !!user;

const {
isUpvoteActive,
Expand All @@ -99,28 +93,13 @@ const ActionButtons = ({
closeTagsPanelOnUpvote: variant === 'list',
});

const { value: upvoteThresholdConfig } = useConditionalFeature({
feature: featureUpvoteCountThreshold,
shouldEvaluate: isLoggedIn,
});

if (isFeedPreview) {
return null;
}

const commentCount = post.numComments ?? 0;
const upvoteCount = post.numUpvotes ?? 0;

const { showCount: showUpvoteCount, belowThresholdLabel: upvoteLabel } =
getUpvoteCountDisplay(
upvoteCount,
upvoteThresholdConfig.threshold,
upvoteThresholdConfig.belowThresholdLabel,
isUpvoteActive,
post.createdAt,
upvoteThresholdConfig.newWindowHours,
);

const commentButton = config.useCommentLink ? (
<LinkWithTooltip
tooltip={{ content: 'Comment' }}
Expand Down Expand Up @@ -200,25 +179,14 @@ const ActionButtons = ({
/>
}
>
{showUpvoteCount ? (
{upvoteCount > 0 && (
<InteractionCounter
className={classNames(
'tabular-nums',
variant === 'grid' && 'typo-footnote',
)}
value={upvoteCount}
/>
) : (
!!upvoteLabel && (
<span
className={classNames(
'tabular-nums',
variant === 'grid' && 'typo-footnote',
)}
>
{upvoteLabel}
</span>
)
)}
</QuaternaryButton>
</Tooltip>
Expand Down
59 changes: 0 additions & 59 deletions packages/shared/src/components/cards/common/PostMetadata.spec.tsx

This file was deleted.

33 changes: 1 addition & 32 deletions packages/shared/src/components/cards/common/PostMetadata.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -6,10 +6,6 @@ import { Separator } from './common';
import type { Post } from '../../../graphql/posts';
import { formatReadTime, DateFormat } from '../../utilities';
import { largeNumberFormat } from '../../../lib';
import { useAuthContext } from '../../../contexts/AuthContext';
import { useConditionalFeature } from '../../../hooks/useConditionalFeature';
import { featureUpvoteCountThreshold } from '../../../lib/featureManagement';
import { getUpvoteCountDisplay } from '../../../lib/post';
import { useFeedCardContext } from '../../../features/posts/FeedCardContext';
import { Tooltip } from '../../tooltip/Tooltip';
import type { PollMetadataProps } from './PollMetadata';
Expand All @@ -24,8 +20,6 @@ interface PostMetadataProps
isVideoType?: boolean;
domain?: ReactNode;
pollMetadata?: PollMetadataProps;
userHasUpvoted?: boolean;
showBelowThresholdLabel?: boolean;
}

export default function PostMetadata({
Expand All @@ -38,31 +32,13 @@ export default function PostMetadata({
isVideoType,
domain,
pollMetadata,
userHasUpvoted = false,
showBelowThresholdLabel = true,
}: PostMetadataProps): ReactElement {
const hasUpvoteCount = typeof numUpvotes === 'number';
const upvoteCount = numUpvotes ?? 0;
const readTimeValue = readTime ?? 0;
const timeActionContent = isVideoType ? 'watch' : 'read';
const showReadTime = isVideoType ? Number.isInteger(readTime) : !!readTime;
const { boostedBy } = useFeedCardContext();
const { user } = useAuthContext();
const isLoggedIn = !!user;

const { value: upvoteThresholdConfig } = useConditionalFeature({
feature: featureUpvoteCountThreshold,
shouldEvaluate: isLoggedIn,
});
const { showCount: showUpvoteCount, belowThresholdLabel: upvoteLabel } =
getUpvoteCountDisplay(
upvoteCount,
upvoteThresholdConfig.threshold,
upvoteThresholdConfig.belowThresholdLabel,
userHasUpvoted,
createdAt,
upvoteThresholdConfig.newWindowHours,
);

const promotedText = useScrambler('Promoted');
const promotedByTooltip = useScrambler(
Expand Down Expand Up @@ -98,21 +74,14 @@ export default function PostMetadata({
},
!!showReadTime && domain && { key: 'domain', node: domain },
hasUpvoteCount &&
showUpvoteCount && {
upvoteCount > 0 && {
key: 'upvotes',
node: (
<span data-testid="numUpvotes">
{largeNumberFormat(upvoteCount)} upvote{upvoteCount > 1 ? 's' : ''}
</span>
),
},
hasUpvoteCount &&
!showUpvoteCount &&
!!upvoteLabel &&
showBelowThresholdLabel && {
key: 'upvotes',
node: <span data-testid="numUpvotes">{upvoteLabel}</span>,
},
].filter(Boolean) as { key: string; node: ReactNode }[];

return (
Expand Down
Loading
Loading