Reactions: wait for previous fetch to complete before fetching again.

This was causing duplicate IDs to be fetched over and over again when scrolling quickly.
This commit is contained in:
infinite-persistence 2021-07-16 00:13:01 +08:00 committed by jessopb
parent a13708f4dd
commit ad7db1e939
2 changed files with 6 additions and 1 deletions

View file

@ -4,6 +4,7 @@ import {
makeSelectTopLevelCommentsForUri,
makeSelectTopLevelTotalPagesForUri,
selectIsFetchingComments,
selectIsFetchingReacts,
makeSelectTotalCommentsCountForUri,
selectOthersReactsById,
makeSelectCommentsDisabledForUri,
@ -24,6 +25,7 @@ const select = (state, props) => {
totalComments: makeSelectTotalCommentsCountForUri(props.uri)(state),
claimIsMine: makeSelectClaimIsMine(props.uri)(state),
isFetchingComments: selectIsFetchingComments(state),
isFetchingReacts: selectIsFetchingReacts(state),
commentingEnabled: IS_WEB ? Boolean(selectUserVerifiedEmail(state)) : true,
commentsDisabledBySettings: makeSelectCommentsDisabledForUri(props.uri)(state),
fetchingChannels: selectFetchingMyChannels(state),

View file

@ -37,6 +37,7 @@ type Props = {
claimIsMine: boolean,
myChannels: ?Array<ChannelClaim>,
isFetchingComments: boolean,
isFetchingReacts: boolean,
linkedCommentId?: string,
totalComments: number,
fetchingChannels: boolean,
@ -59,6 +60,7 @@ function CommentList(props: Props) {
claimIsMine,
myChannels,
isFetchingComments,
isFetchingReacts,
linkedCommentId,
totalComments,
fetchingChannels,
@ -122,7 +124,7 @@ function CommentList(props: Props) {
// Fetch reacts
useEffect(() => {
if (totalFetchedComments > 0 && ENABLE_COMMENT_REACTIONS && !fetchingChannels) {
if (totalFetchedComments > 0 && ENABLE_COMMENT_REACTIONS && !fetchingChannels && !isFetchingReacts) {
let idsForReactionFetch;
if (!othersReactsById || !myReactsByCommentId) {
@ -151,6 +153,7 @@ function CommentList(props: Props) {
uri,
activeChannelId,
fetchingChannels,
isFetchingReacts,
]);
// Scroll to linked-comment