Skip to content

Commit f25ef08

Browse files
Merge pull request #597 from ResearchHub/reply_button_fixes
Bug Fix: Reply/Comment buttons not showing on feed items/comments/peer reviews
2 parents a81bb5c + ad863da commit f25ef08

File tree

5 files changed

+23
-4
lines changed

5 files changed

+23
-4
lines changed

components/Feed/BaseFeedItem.tsx

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,7 @@ import {
77
FeedPostContent,
88
mapFeedContentTypeToContentType,
99
} from '@/types/feed';
10+
import { shouldShowCommentButton } from '@/components/Feed/lib/feedUtils';
1011
import { FeedItemHeader } from '@/components/Feed/FeedItemHeader';
1112
import { FeedItemActions } from '@/components/Feed/FeedItemActions';
1213
import { CardWrapper } from './CardWrapper';
@@ -417,7 +418,7 @@ export const BaseFeedItem: FC<BaseFeedItemProps> = ({
417418
onFeedItemClick={onFeedItemClick}
418419
bounties={showBountyInfo ? undefined : content.bounties}
419420
hideReportButton={hideReportButton}
420-
hideCommentButton={(entry.metrics?.comments ?? 0) === 0}
421+
hideCommentButton={!shouldShowCommentButton(entry.metrics, Boolean(href))}
421422
/>
422423
</div>
423424
)}

components/Feed/FeedItemActions.tsx

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -422,7 +422,7 @@ export const FeedItemActions: FC<FeedItemActionsProps> = ({
422422
return (
423423
<>
424424
<div className="flex items-center justify-between w-full">
425-
<div className="flex items-center space-x-3 md:space-x-4 flex-nowrap overflow-x-auto">
425+
<div className="flex items-center space-x-3 md:space-x-4 flex-nowrap overflow-visible">
426426
<div
427427
className={cn(
428428
'flex items-center h-8 border rounded-full bg-white transition-all',

components/Feed/items/FeedItemBountyComment.tsx

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,7 @@
22

33
import { FC, useState } from 'react';
44
import { FeedEntry, FeedBountyContent } from '@/types/feed';
5+
import { shouldShowCommentButton } from '@/components/Feed/lib/feedUtils';
56
import { Topic } from '@/types/topic';
67
import { FeedItemHeader } from '@/components/Feed/FeedItemHeader';
78
import { FeedItemActions } from '@/components/Feed/FeedItemActions';
@@ -424,7 +425,7 @@ export const FeedItemBountyComment: FC<FeedItemBountyCommentProps> = ({
424425
entry.relatedWork?.unifiedDocumentId?.toString() || undefined
425426
}
426427
onFeedItemClick={onFeedItemClick}
427-
hideCommentButton={(entry.metrics?.comments ?? 0) === 0}
428+
hideCommentButton={!shouldShowCommentButton(entry.metrics, Boolean(onReply))}
428429
/>
429430
</div>
430431
)}

components/Feed/items/FeedItemComment.tsx

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,7 @@
33
import { FC, useState } from 'react';
44
import React from 'react';
55
import { FeedEntry, FeedCommentContent, ParentCommentPreview } from '@/types/feed';
6+
import { shouldShowCommentButton } from '@/components/Feed/lib/feedUtils';
67
import { FeedItemHeader } from '@/components/Feed/FeedItemHeader';
78
import { FeedItemActions } from '@/components/Feed/FeedItemActions';
89
import { CommentReadOnly } from '@/components/Comment/CommentReadOnly';
@@ -255,7 +256,7 @@ export const FeedItemComment: FC<FeedItemCommentProps> = ({
255256
tips={entry.tips}
256257
relatedDocumentTopics={entry.relatedWork?.topics}
257258
onFeedItemClick={onFeedItemClick}
258-
hideCommentButton={(entry.metrics?.comments ?? 0) === 0}
259+
hideCommentButton={!shouldShowCommentButton(entry.metrics, Boolean(onReply))}
259260
/>
260261
</div>
261262
</div>

components/Feed/lib/feedUtils.ts

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,16 @@
1+
import { ContentMetrics } from '@/types/metrics';
2+
3+
/**
4+
* Determines if the comment/reply button should be shown.
5+
* Show the button if there are comments to view OR the user can add one.
6+
*
7+
* @param metrics - The content metrics containing comment count
8+
* @param hasCommentAction - Whether the user has a way to comment (via callback or navigation)
9+
*/
10+
export function shouldShowCommentButton(
11+
metrics: ContentMetrics | undefined,
12+
hasCommentAction: boolean
13+
): boolean {
14+
const hasComments = (metrics?.comments ?? 0) > 0;
15+
return hasComments || hasCommentAction;
16+
}

0 commit comments

Comments
 (0)