make sure claim_search is called every time the homepage is navigated to

This commit is contained in:
Sean Yesmunt 2020-01-22 09:48:00 -05:00
parent 1d4ef2cc43
commit 2c12b62133

View file

@ -39,6 +39,7 @@ function ClaimTilesDiscover(props: Props) {
claimType, claimType,
timestamp, timestamp,
} = props; } = props;
const [hasSearched, setHasSearched] = React.useState(false);
const options: { const options: {
page_size: number, page_size: number,
@ -77,7 +78,7 @@ function ClaimTilesDiscover(props: Props) {
const claimSearchCacheQuery = createNormalizedClaimSearchKey(options); const claimSearchCacheQuery = createNormalizedClaimSearchKey(options);
const uris = claimSearchByQuery[claimSearchCacheQuery] || []; const uris = claimSearchByQuery[claimSearchCacheQuery] || [];
const shouldPerformSearch = uris.length === 0 || (!loading && uris.length < pageSize); const shouldPerformSearch = (!hasSearched && uris.length === 0) || (!loading && uris.length < pageSize);
// Don't use the query from createNormalizedClaimSearchKey for the effect since that doesn't include page & release_time // Don't use the query from createNormalizedClaimSearchKey for the effect since that doesn't include page & release_time
const optionsStringForEffect = JSON.stringify(options); const optionsStringForEffect = JSON.stringify(options);
@ -85,8 +86,13 @@ function ClaimTilesDiscover(props: Props) {
if (shouldPerformSearch) { if (shouldPerformSearch) {
const searchOptions = JSON.parse(optionsStringForEffect); const searchOptions = JSON.parse(optionsStringForEffect);
doClaimSearch(searchOptions); doClaimSearch(searchOptions);
setHasSearched(true);
} }
}, [doClaimSearch, shouldPerformSearch, optionsStringForEffect]);
return () => {
setHasSearched(false);
};
}, [doClaimSearch, shouldPerformSearch, optionsStringForEffect, setHasSearched]);
return ( return (
<ul className="claim-grid"> <ul className="claim-grid">