⏪ ClaimListDiscover: revert and cleanup
## Revert - Removed the 'finalUris' stuff that was meant to "pause" visual changes when fetching. I think it'll be cleaner to use React.memo to achieve that. ## Alterations - Added `renderUri` to make it clear which array that this component will render. - Re-do the way we fetch view counts now that 'finalUris' is gone. Not the best method, but at least correct for now.
This commit is contained in:
parent
78491e71f6
commit
af7345b3cd
1 changed files with 8 additions and 43 deletions
|
@ -376,9 +376,9 @@ function ClaimListDiscover(props: Props) {
|
||||||
|
|
||||||
const hasMatureTags = tagsParam && tagsParam.split(',').some((t) => MATURE_TAGS.includes(t));
|
const hasMatureTags = tagsParam && tagsParam.split(',').some((t) => MATURE_TAGS.includes(t));
|
||||||
|
|
||||||
const mainSearchKey = createNormalizedClaimSearchKey(options);
|
const searchKey = createNormalizedClaimSearchKey(options);
|
||||||
let claimSearchResult = claimSearchByQuery[mainSearchKey];
|
const claimSearchResult = claimSearchByQuery[searchKey];
|
||||||
const claimSearchResultLastPageReached = claimSearchByQueryLastPageReached[mainSearchKey];
|
const claimSearchResultLastPageReached = claimSearchByQueryLastPageReached[searchKey];
|
||||||
|
|
||||||
// uncomment to fix an item on a page
|
// uncomment to fix an item on a page
|
||||||
// const fixUri = 'lbry://@corbettreport#0/lbryodysee#5';
|
// const fixUri = 'lbry://@corbettreport#0/lbryodysee#5';
|
||||||
|
@ -396,9 +396,6 @@ function ClaimListDiscover(props: Props) {
|
||||||
// claimSearchResult.splice(2, 0, fixUri);
|
// claimSearchResult.splice(2, 0, fixUri);
|
||||||
// }
|
// }
|
||||||
|
|
||||||
const [finalUris, setFinalUris] = React.useState(
|
|
||||||
getFinalUrisInitialState(history.action === 'POP', claimSearchResult)
|
|
||||||
);
|
|
||||||
const [prevOptions, setPrevOptions] = React.useState(null);
|
const [prevOptions, setPrevOptions] = React.useState(null);
|
||||||
|
|
||||||
if (!isJustScrollingToNewPage(prevOptions, options)) {
|
if (!isJustScrollingToNewPage(prevOptions, options)) {
|
||||||
|
@ -460,6 +457,8 @@ function ClaimListDiscover(props: Props) {
|
||||||
</div>
|
</div>
|
||||||
);
|
);
|
||||||
|
|
||||||
|
const renderUris = uris || claimSearchResult;
|
||||||
|
|
||||||
// **************************************************************************
|
// **************************************************************************
|
||||||
// Helpers
|
// Helpers
|
||||||
// **************************************************************************
|
// **************************************************************************
|
||||||
|
@ -505,25 +504,6 @@ function ClaimListDiscover(props: Props) {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
function urisEqual(prev: Array<string>, next: Array<string>) {
|
|
||||||
if (!prev || !next) {
|
|
||||||
// From 'ClaimList', "null" and "undefined" have special meaning,
|
|
||||||
// so we can't just compare array length here.
|
|
||||||
// - null = "timed out"
|
|
||||||
// - undefined = "no result".
|
|
||||||
return prev === next;
|
|
||||||
}
|
|
||||||
return prev.length === next.length && prev.every((value, index) => value === next[index]);
|
|
||||||
}
|
|
||||||
|
|
||||||
function getFinalUrisInitialState(isNavigatingBack, claimSearchResult) {
|
|
||||||
if (isNavigatingBack && claimSearchResult && claimSearchResult.length > 0) {
|
|
||||||
return claimSearchResult;
|
|
||||||
} else {
|
|
||||||
return [];
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
function resolveOrderByOption(orderBy: string | Array<string>, sortBy: string | Array<string>) {
|
function resolveOrderByOption(orderBy: string | Array<string>, sortBy: string | Array<string>) {
|
||||||
const order_by =
|
const order_by =
|
||||||
orderBy === CS.ORDER_BY_TRENDING
|
orderBy === CS.ORDER_BY_TRENDING
|
||||||
|
@ -542,7 +522,7 @@ function ClaimListDiscover(props: Props) {
|
||||||
// **************************************************************************
|
// **************************************************************************
|
||||||
// **************************************************************************
|
// **************************************************************************
|
||||||
|
|
||||||
useFetchViewCount(fetchViewCount, finalUris, claimsByUri, doFetchViewCount);
|
useFetchViewCount(fetchViewCount, renderUris, claimsByUri, doFetchViewCount);
|
||||||
|
|
||||||
React.useEffect(() => {
|
React.useEffect(() => {
|
||||||
if (shouldPerformSearch) {
|
if (shouldPerformSearch) {
|
||||||
|
@ -551,21 +531,6 @@ function ClaimListDiscover(props: Props) {
|
||||||
}
|
}
|
||||||
}, [doClaimSearch, shouldPerformSearch, optionsStringForEffect, forceRefresh]);
|
}, [doClaimSearch, shouldPerformSearch, optionsStringForEffect, forceRefresh]);
|
||||||
|
|
||||||
// Resolve 'finalUri'
|
|
||||||
React.useEffect(() => {
|
|
||||||
if (uris) {
|
|
||||||
if (!urisEqual(uris, finalUris)) {
|
|
||||||
setFinalUris(uris);
|
|
||||||
}
|
|
||||||
} else {
|
|
||||||
// Wait until all queries are done before updating the uris to avoid layout shifts.
|
|
||||||
const pending = claimSearchResult === undefined;
|
|
||||||
if (!pending && !urisEqual(claimSearchResult, finalUris)) {
|
|
||||||
setFinalUris(claimSearchResult);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}, [uris, claimSearchResult, finalUris, setFinalUris]);
|
|
||||||
|
|
||||||
const headerToUse = header || (
|
const headerToUse = header || (
|
||||||
<ClaimListHeader
|
<ClaimListHeader
|
||||||
channelIds={channelIds}
|
channelIds={channelIds}
|
||||||
|
@ -603,7 +568,7 @@ function ClaimListDiscover(props: Props) {
|
||||||
<ClaimList
|
<ClaimList
|
||||||
tileLayout
|
tileLayout
|
||||||
loading={loading}
|
loading={loading}
|
||||||
uris={finalUris}
|
uris={renderUris}
|
||||||
onScrollBottom={handleScrollBottom}
|
onScrollBottom={handleScrollBottom}
|
||||||
page={page}
|
page={page}
|
||||||
pageSize={dynamicPageSize}
|
pageSize={dynamicPageSize}
|
||||||
|
@ -635,7 +600,7 @@ function ClaimListDiscover(props: Props) {
|
||||||
<ClaimList
|
<ClaimList
|
||||||
type={type}
|
type={type}
|
||||||
loading={loading}
|
loading={loading}
|
||||||
uris={finalUris}
|
uris={renderUris}
|
||||||
onScrollBottom={handleScrollBottom}
|
onScrollBottom={handleScrollBottom}
|
||||||
page={page}
|
page={page}
|
||||||
pageSize={dynamicPageSize}
|
pageSize={dynamicPageSize}
|
||||||
|
|
Loading…
Add table
Reference in a new issue