Skip to content

Commit 5bd4fee

Browse files
keikarimiko
andauthored
Improve comment notifications to a content that was loaded already at (#3430)
somepoint Co-authored-by: miko <sauce47@posteo.net>
1 parent 6664ee2 commit 5bd4fee

File tree

2 files changed

+20
-12
lines changed

2 files changed

+20
-12
lines changed

ui/component/comment/view.jsx

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -195,6 +195,14 @@ function CommentView(props: Props & StateProps & DispatchProps) {
195195
const [page, setPage] = useState(showRepliesOnMount ? 1 : 0);
196196
const [advancedEditor] = usePersistedState('comment-editor-mode', false);
197197
const [displayDeadComment, setDisplayDeadComment] = React.useState(forceDisplayDeadComment);
198+
199+
// Expand replies when linked comment ancestors arrive after mount (e.g. notification navigation)
200+
React.useEffect(() => {
201+
if (isInLinkedCommentChain) {
202+
setShowReplies(true);
203+
setPage((prev) => prev || 1);
204+
}
205+
}, [isInLinkedCommentChain]);
198206
const likesCount = (othersReacts && othersReacts.like) || 0;
199207
const dislikesCount = (othersReacts && othersReacts.dislike) || 0;
200208
const totalLikesAndDislikes = likesCount + dislikesCount;

ui/component/commentsList/view.jsx

Lines changed: 12 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -273,6 +273,16 @@ export default function CommentList(props: Props & StateProps & DispatchProps) {
273273
// eslint-disable-next-line react-hooks/exhaustive-deps -- Only on uri change
274274
}, [uri]);
275275

276+
// Fetch linked/thread comment independently of pagination state
277+
useEffect(() => {
278+
if (threadCommentId) {
279+
fetchComment(threadCommentId);
280+
}
281+
if (linkedCommentId) {
282+
fetchComment(linkedCommentId);
283+
}
284+
}, [fetchComment, linkedCommentId, threadCommentId]);
285+
276286
// Fetch top-level comments
277287
useEffect(() => {
278288
const isInitialFetch = currentFetchedPage === 0;
@@ -282,18 +292,9 @@ export default function CommentList(props: Props & StateProps & DispatchProps) {
282292
const hasRightFetchPage = Number(isInitialFetch) ^ Number(isNewPage);
283293

284294
if (page !== 0 && hasRightFetchPage) {
285-
if (page === 1) {
286-
if (threadCommentId) {
287-
fetchComment(threadCommentId);
288-
}
289-
if (linkedCommentId) {
290-
fetchComment(linkedCommentId);
291-
}
292-
}
293-
294295
fetchTopLevelComments(uri, undefined, page, COMMENT_PAGE_SIZE_TOP_LEVEL, sort, false);
295296
}
296-
}, [currentFetchedPage, fetchComment, fetchTopLevelComments, linkedCommentId, page, sort, threadCommentId, uri]);
297+
}, [currentFetchedPage, fetchTopLevelComments, page, sort, uri]);
297298

298299
React.useEffect(() => {
299300
if (threadCommentId) {
@@ -342,8 +343,7 @@ export default function CommentList(props: Props & StateProps & DispatchProps) {
342343
} else {
343344
delete window.pendingLinkedCommentScroll;
344345
}
345-
// eslint-disable-next-line react-hooks/exhaustive-deps
346-
}, []);
346+
}, [linkedCommentId, threadCommentId]);
347347

348348
// Infinite scroll
349349
useEffect(() => {

0 commit comments

Comments
 (0)