From dd5636c2b383d14428e3883f9f6c59be3245b86b Mon Sep 17 00:00:00 2001 From: Sean Yesmunt Date: Fri, 11 Sep 2020 15:48:23 -0400 Subject: [PATCH] prevent multiple claim_search's happening on the homepage --- ui/component/claimTilesDiscover/index.js | 4 ++-- ui/component/claimTilesDiscover/view.jsx | 11 +++++++---- ui/redux/reducers/comments.js | 1 - 3 files changed, 9 insertions(+), 7 deletions(-) diff --git a/ui/component/claimTilesDiscover/index.js b/ui/component/claimTilesDiscover/index.js index a549c5010..76ec66d9e 100644 --- a/ui/component/claimTilesDiscover/index.js +++ b/ui/component/claimTilesDiscover/index.js @@ -1,5 +1,5 @@ import { connect } from 'react-redux'; -import { doClaimSearch, selectClaimSearchByQuery, selectFetchingClaimSearch, SETTINGS } from 'lbry-redux'; +import { doClaimSearch, selectClaimSearchByQuery, selectFetchingClaimSearchByQuery, SETTINGS } from 'lbry-redux'; import { selectBlockedChannels } from 'redux/selectors/blocked'; import { doToggleTagFollowDesktop } from 'redux/actions/tags'; import { makeSelectClientSetting } from 'redux/selectors/settings'; @@ -7,7 +7,7 @@ import ClaimListDiscover from './view'; const select = state => ({ claimSearchByQuery: selectClaimSearchByQuery(state), - loading: selectFetchingClaimSearch(state), + fetchingClaimSearchByQuery: selectFetchingClaimSearchByQuery(state), showNsfw: makeSelectClientSetting(SETTINGS.SHOW_MATURE)(state), hideReposts: makeSelectClientSetting(SETTINGS.HIDE_REPOSTS)(state), hiddenUris: selectBlockedChannels(state), diff --git a/ui/component/claimTilesDiscover/view.jsx b/ui/component/claimTilesDiscover/view.jsx index c632a7351..d62f223da 100644 --- a/ui/component/claimTilesDiscover/view.jsx +++ b/ui/component/claimTilesDiscover/view.jsx @@ -14,6 +14,9 @@ type Props = { claimSearchByQuery: { [string]: Array, }, + fetchingClaimSearchByQuery: { + [string]: boolean, + }, // claim search options are below tags: Array, hiddenUris: Array, @@ -49,12 +52,12 @@ function ClaimTilesDiscover(props: Props) { timestamp, feeAmount, limitClaimsPerChannel, + fetchingClaimSearchByQuery, } = props; const { location } = useHistory(); const urlParams = new URLSearchParams(location.search); const feeAmountInUrl = urlParams.get('fee_amount'); const feeAmountParam = feeAmountInUrl || feeAmount; - const [hasSearched, setHasSearched] = React.useState(false); const options: { page_size: number, no_totals: boolean, @@ -118,17 +121,17 @@ function ClaimTilesDiscover(props: Props) { const claimSearchCacheQuery = createNormalizedClaimSearchKey(options); const uris = (prefixUris || []).concat(claimSearchByQuery[claimSearchCacheQuery] || []); - const shouldPerformSearch = !hasSearched || uris.length === 0; // Don't use the query from createNormalizedClaimSearchKey for the effect since that doesn't include page & release_time const optionsStringForEffect = JSON.stringify(options); + const isLoading = fetchingClaimSearchByQuery[claimSearchCacheQuery]; + const shouldPerformSearch = !isLoading && uris.length === 0; React.useEffect(() => { if (shouldPerformSearch) { const searchOptions = JSON.parse(optionsStringForEffect); doClaimSearch(searchOptions); - setHasSearched(true); } - }, [doClaimSearch, shouldPerformSearch, optionsStringForEffect, hasSearched]); + }, [doClaimSearch, shouldPerformSearch, optionsStringForEffect]); return (
    diff --git a/ui/redux/reducers/comments.js b/ui/redux/reducers/comments.js index c158d438f..cba7c76d8 100644 --- a/ui/redux/reducers/comments.js +++ b/ui/redux/reducers/comments.js @@ -34,7 +34,6 @@ export default handleActions( const commentsByUri = Object.assign({}, state.commentsByUri); const comments = byId[claimId] || []; const newCommentIds = comments.slice(); - const commentsByUri = Object.assign({}, state.commentsByUri); // add the comment by its ID commentById[comment.comment_id] = comment;