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

View file

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