Files
gitmost/client/src/features/comment/utils.ts
Philipinho 4cb7a56f65 feat: comments
* create comment
* reply to comment thread
* edit comment
* delete comment
* resolve comment
2023-11-09 16:52:34 +00:00

20 lines
656 B
TypeScript

export function scrollToComment(commentId) {
const selector = `div[data-comment-id="${commentId}"]`;
const commentElement = document.querySelector(selector);
if (commentElement) {
commentElement.scrollIntoView({ behavior: 'smooth' });
}
}
export const scrollToCommentInScrollArea = (commentId, scrollAreaRef) => {
const commentElement = scrollAreaRef.current.querySelector(`[data-comment-id="${commentId}"]`);
if (commentElement) {
const scrollArea = scrollAreaRef.current;
const commentTop = commentElement.offsetTop;
const scrollAreaTop = scrollArea.offsetTop;
scrollArea.scrollTop = commentTop - scrollAreaTop;
}
};