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:
parent
135982e9d0
commit
8859f46e5c
3 changed files with 9 additions and 13 deletions
|
@ -48,7 +48,7 @@ const perform = (dispatch) => ({
|
||||||
fetchTopLevelComments: (uri, page, pageSize, sortBy) => dispatch(doCommentList(uri, '', page, pageSize, sortBy)),
|
fetchTopLevelComments: (uri, page, pageSize, sortBy) => dispatch(doCommentList(uri, '', page, pageSize, sortBy)),
|
||||||
fetchComment: (commentId) => dispatch(doCommentById(commentId)),
|
fetchComment: (commentId) => dispatch(doCommentById(commentId)),
|
||||||
fetchReacts: (commentIds) => dispatch(doCommentReactList(commentIds)),
|
fetchReacts: (commentIds) => dispatch(doCommentReactList(commentIds)),
|
||||||
resetComments: (uri) => dispatch(doCommentReset(uri)),
|
resetComments: (claimId) => dispatch(doCommentReset(claimId)),
|
||||||
});
|
});
|
||||||
|
|
||||||
export default connect(select, perform)(CommentsList);
|
export default connect(select, perform)(CommentsList);
|
||||||
|
|
|
@ -151,10 +151,13 @@ function CommentList(props: Props) {
|
||||||
// Reset comments
|
// Reset comments
|
||||||
useEffect(() => {
|
useEffect(() => {
|
||||||
if (page === 0) {
|
if (page === 0) {
|
||||||
resetComments(uri);
|
if (claim) {
|
||||||
|
resetComments(claim.claim_id);
|
||||||
|
}
|
||||||
setPage(1);
|
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
|
// Fetch top-level comments
|
||||||
useEffect(() => {
|
useEffect(() => {
|
||||||
|
|
|
@ -238,17 +238,10 @@ export function doCommentById(commentId: string, toastIfNotFound: boolean = true
|
||||||
};
|
};
|
||||||
}
|
}
|
||||||
|
|
||||||
export function doCommentReset(uri: string) {
|
export function doCommentReset(claimId: string) {
|
||||||
return (dispatch: Dispatch, getState: GetState) => {
|
return (dispatch: Dispatch) => {
|
||||||
const state = getState();
|
|
||||||
const claim = selectClaimsByUri(state)[uri];
|
|
||||||
const claimId = claim ? claim.claim_id : null;
|
|
||||||
|
|
||||||
if (!claimId) {
|
if (!claimId) {
|
||||||
dispatch({
|
console.error(`Failed to reset comments`); //eslint-disable-line
|
||||||
type: ACTIONS.COMMENT_LIST_FAILED,
|
|
||||||
data: 'unable to find claim for uri',
|
|
||||||
});
|
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
Loading…
Add table
Reference in a new issue