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.
This commit is contained in:
infinite-persistence 2021-09-27 15:05:59 +08:00
parent 99b742ac3e
commit 5e26926122
No known key found for this signature in database
GPG key ID: B9C3252EDC3D0AA0
3 changed files with 9 additions and 13 deletions

View file

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

View file

@ -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(() => {

View file

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