[Fix] Focus the comment thread when opened after dismissing (#6437)

This commit is contained in:
Rishabh Saxena 2021-08-06 17:48:58 +05:30 committed by GitHub
parent e3b141fbef
commit 61820cc180
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
2 changed files with 16 additions and 3 deletions

View File

@ -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));
}

View File

@ -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"}