Skip to content
Open
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
5 changes: 4 additions & 1 deletion .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -47,4 +47,7 @@ webapp.xml
.idea/

# Figma MCP
figma-images/
figma-images/

# Node compile cache
node-compile-cache/
37 changes: 26 additions & 11 deletions packages/shared/src/components/post/PostEngagements.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@ import {
import usePersistentContext from '../../hooks/usePersistentContext';
import { PostContentShare } from './common/PostContentShare';
import { SourceType } from '../../graphql/sources';
import { useActions } from '../../hooks';
import { useActions, useViewSize, ViewSize } from '../../hooks';
import { ActionType } from '../../graphql/actions';
import { AdAsComment } from '../comments/AdAsComment';
import { Typography, TypographyType } from '../typography/Typography';
Expand Down Expand Up @@ -63,7 +63,9 @@ function PostEngagements({
useSettingsContext();
const { user, showLogin } = useAuthContext();
const { isPlus } = usePlusSubscription();
const isMobile = !useViewSize(ViewSize.Tablet);
const commentRef = useRef<NewCommentRef>();
const commentsContainerRef = useRef<HTMLDivElement>(null);
const [authorOnboarding, setAuthorOnboarding] = useState(false);
const [permissionNotificationCommentId, setPermissionNotificationCommentId] =
useState<string>();
Expand Down Expand Up @@ -100,6 +102,17 @@ function PostEngagements({
if (post.source?.type === SourceType.Squad) {
completeAction(ActionType.SquadFirstComment);
}

// On mobile, scroll to show the newly added comment
if (isMobile && commentsContainerRef.current) {
// Use setTimeout to ensure the comment is rendered before scrolling
setTimeout(() => {
commentsContainerRef.current?.scrollIntoView({
behavior: 'smooth',
block: 'start',
});
}, 100);
}
};

useEffect(() => {
Expand Down Expand Up @@ -160,16 +173,18 @@ function PostEngagements({
CommentInputOrModal={CommentInputOrModal}
/>
{!isPlus && <AdAsComment postId={post.id} />}
<PostComments
post={post}
sortBy={sortBy}
origin={logOrigin}
onShare={(comment) => openShareComment(comment, post)}
onClickUpvote={(id, count) => onShowUpvoted(id, count, 'comment')}
permissionNotificationCommentId={permissionNotificationCommentId}
joinNotificationCommentId={joinNotificationCommentId}
onCommented={onCommented}
/>
<div ref={commentsContainerRef}>
<PostComments
post={post}
sortBy={sortBy}
origin={logOrigin}
onShare={(comment) => openShareComment(comment, post)}
onClickUpvote={(id, count) => onShowUpvoted(id, count, 'comment')}
permissionNotificationCommentId={permissionNotificationCommentId}
joinNotificationCommentId={joinNotificationCommentId}
onCommented={onCommented}
/>
</div>
{authorOnboarding && (
<AuthorOnboarding
onSignUp={
Expand Down