From 61820cc1802fb624fedb9503ca1ae70eb49fca4e Mon Sep 17 00:00:00 2001 From: Rishabh Saxena Date: Fri, 6 Aug 2021 17:48:58 +0530 Subject: [PATCH] [Fix] Focus the comment thread when opened after dismissing (#6437) --- .../src/comments/CommentCard/CommentCard.tsx | 3 --- .../comments/inlineComments/InlineCommentPin.tsx | 16 ++++++++++++++++ 2 files changed, 16 insertions(+), 3 deletions(-) diff --git a/app/client/src/comments/CommentCard/CommentCard.tsx b/app/client/src/comments/CommentCard/CommentCard.tsx index cfeba4da8c..adc6fb6ecf 100644 --- a/app/client/src/comments/CommentCard/CommentCard.tsx +++ b/app/client/src/comments/CommentCard/CommentCard.tsx @@ -44,7 +44,6 @@ import { deleteCommentThreadRequest, addCommentReaction, removeCommentReaction, - setVisibleThread, } from "actions/commentActions"; import { useDispatch, useSelector } from "react-redux"; import { commentThreadsSelector } from "selectors/commentsSelectors"; @@ -384,8 +383,6 @@ function CommentCard({ `${commentThreadURL.pathname}${commentThreadURL.search}${commentThreadURL.hash}`, ); - dispatch(setVisibleThread(commentThreadId)); - if (!commentThread.isViewed) { dispatch(markThreadAsReadRequest(commentThreadId)); } diff --git a/app/client/src/comments/inlineComments/InlineCommentPin.tsx b/app/client/src/comments/inlineComments/InlineCommentPin.tsx index b66070ed1b..b02301fe14 100644 --- a/app/client/src/comments/inlineComments/InlineCommentPin.tsx +++ b/app/client/src/comments/inlineComments/InlineCommentPin.tsx @@ -21,6 +21,7 @@ import "@blueprintjs/popover2/lib/css/blueprint-popover2.css"; import { Popover2 } from "@blueprintjs/popover2"; import { getPosition, getShouldPositionAbsolutely } from "comments/utils"; +import history from "utils/history"; /** * The relavent pixel position is bottom right for the comment cursor @@ -120,6 +121,20 @@ const focusThread = (commentThreadId: string) => { } }; +const resetCommentThreadIdInURL = (commentThreadId: string) => { + if (!window.location.href) return; + const currentURL = new URL(window.location.href); + const searchParams = currentURL.searchParams; + if (searchParams.get("commentThreadId") === commentThreadId) { + searchParams.delete("commentThreadId"); + + history.replace({ + ...window.location, + search: searchParams.toString(), + }); + } +}; + /** * Comment pins that toggle comment thread popover visibility on click * They position themselves using position absolute based on top and left values (in percent) @@ -214,6 +229,7 @@ function InlineCommentPin({ dispatch(setVisibleThread(commentThreadId)); } else { dispatch(resetVisibleThread(commentThreadId)); + resetCommentThreadIdInURL(commentThreadId); } }} placement={"right-start"}