From 8859f46e5c140bd82876ec0dd98127735a7fc0ab Mon Sep 17 00:00:00 2001 From: infinite-persistence Date: Mon, 27 Sep 2021 15:05:59 +0800 Subject: [PATCH] doCommentReset: change param from uri to claimId This reduces one lookup as clients will always have the claimID ready, but might not have the full URI. It was using URI previously just to match the other APIs. --- ui/component/commentsList/index.js | 2 +- ui/component/commentsList/view.jsx | 7 +++++-- ui/redux/actions/comments.js | 13 +++---------- 3 files changed, 9 insertions(+), 13 deletions(-) diff --git a/ui/component/commentsList/index.js b/ui/component/commentsList/index.js index 8d15ab707..c83dae73b 100644 --- a/ui/component/commentsList/index.js +++ b/ui/component/commentsList/index.js @@ -48,7 +48,7 @@ const perform = (dispatch) => ({ fetchTopLevelComments: (uri, page, pageSize, sortBy) => dispatch(doCommentList(uri, '', page, pageSize, sortBy)), fetchComment: (commentId) => dispatch(doCommentById(commentId)), fetchReacts: (commentIds) => dispatch(doCommentReactList(commentIds)), - resetComments: (uri) => dispatch(doCommentReset(uri)), + resetComments: (claimId) => dispatch(doCommentReset(claimId)), }); export default connect(select, perform)(CommentsList); diff --git a/ui/component/commentsList/view.jsx b/ui/component/commentsList/view.jsx index 6a51fd42c..35525d19a 100644 --- a/ui/component/commentsList/view.jsx +++ b/ui/component/commentsList/view.jsx @@ -151,10 +151,13 @@ function CommentList(props: Props) { // Reset comments useEffect(() => { if (page === 0) { - resetComments(uri); + if (claim) { + resetComments(claim.claim_id); + } setPage(1); } - }, [page, uri, resetComments]); + // eslint-disable-next-line react-hooks/exhaustive-deps + }, [page, uri, resetComments]); // 'claim' is derived from 'uri' // Fetch top-level comments useEffect(() => { diff --git a/ui/redux/actions/comments.js b/ui/redux/actions/comments.js index 8196ef288..cdc9ce281 100644 --- a/ui/redux/actions/comments.js +++ b/ui/redux/actions/comments.js @@ -238,17 +238,10 @@ export function doCommentById(commentId: string, toastIfNotFound: boolean = true }; } -export function doCommentReset(uri: string) { - return (dispatch: Dispatch, getState: GetState) => { - const state = getState(); - const claim = selectClaimsByUri(state)[uri]; - const claimId = claim ? claim.claim_id : null; - +export function doCommentReset(claimId: string) { + return (dispatch: Dispatch) => { if (!claimId) { - dispatch({ - type: ACTIONS.COMMENT_LIST_FAILED, - data: 'unable to find claim for uri', - }); + console.error(`Failed to reset comments`); //eslint-disable-line return; }