Make ClaimListDiscover retain results while searching
Ticket: 946 - Copied the functionality from ClaimTileDiscover. Tried to use the same variable names to help the future consolidation work. - Removed `excludeUris` from `ClaimList` as it makes the caching harder.
This commit is contained in:
parent
67a822d536
commit
5196468330
2 changed files with 34 additions and 14 deletions
|
@ -53,7 +53,6 @@ type Props = {
|
||||||
showNoSourceClaims?: boolean,
|
showNoSourceClaims?: boolean,
|
||||||
onClick?: (e: any, claim?: ?Claim, index?: number) => void,
|
onClick?: (e: any, claim?: ?Claim, index?: number) => void,
|
||||||
maxClaimRender?: number,
|
maxClaimRender?: number,
|
||||||
excludeUris?: Array<string>,
|
|
||||||
loadedCallback?: (number) => void,
|
loadedCallback?: (number) => void,
|
||||||
swipeLayout: boolean,
|
swipeLayout: boolean,
|
||||||
showEdit?: boolean,
|
showEdit?: boolean,
|
||||||
|
@ -93,7 +92,6 @@ export default function ClaimList(props: Props) {
|
||||||
showNoSourceClaims,
|
showNoSourceClaims,
|
||||||
onClick,
|
onClick,
|
||||||
maxClaimRender,
|
maxClaimRender,
|
||||||
excludeUris = [],
|
|
||||||
loadedCallback,
|
loadedCallback,
|
||||||
swipeLayout = false,
|
swipeLayout = false,
|
||||||
showEdit,
|
showEdit,
|
||||||
|
@ -115,10 +113,6 @@ export default function ClaimList(props: Props) {
|
||||||
|
|
||||||
let tileUris = (prefixUris || []).concat(uris || []);
|
let tileUris = (prefixUris || []).concat(uris || []);
|
||||||
|
|
||||||
if (excludeUris && excludeUris.length) {
|
|
||||||
tileUris = tileUris.filter((uri) => !excludeUris.includes(uri));
|
|
||||||
}
|
|
||||||
|
|
||||||
if (prefixUris && prefixUris.length) tileUris.splice(prefixUris.length * -1, prefixUris.length);
|
if (prefixUris && prefixUris.length) tileUris.splice(prefixUris.length * -1, prefixUris.length);
|
||||||
|
|
||||||
const totalLength = tileUris.length;
|
const totalLength = tileUris.length;
|
||||||
|
|
|
@ -184,6 +184,7 @@ function ClaimListDiscover(props: Props) {
|
||||||
} = props;
|
} = props;
|
||||||
const didNavigateForward = history.action === 'PUSH';
|
const didNavigateForward = history.action === 'PUSH';
|
||||||
const { search } = location;
|
const { search } = location;
|
||||||
|
const prevUris = React.useRef();
|
||||||
const [page, setPage] = React.useState(1);
|
const [page, setPage] = React.useState(1);
|
||||||
const [forceRefresh, setForceRefresh] = React.useState();
|
const [forceRefresh, setForceRefresh] = React.useState();
|
||||||
const isLargeScreen = useIsLargeScreen();
|
const isLargeScreen = useIsLargeScreen();
|
||||||
|
@ -434,6 +435,7 @@ function ClaimListDiscover(props: Props) {
|
||||||
const searchKey = createNormalizedClaimSearchKey(options);
|
const searchKey = createNormalizedClaimSearchKey(options);
|
||||||
const claimSearchResult = claimSearchByQuery[searchKey];
|
const claimSearchResult = claimSearchByQuery[searchKey];
|
||||||
const claimSearchResultLastPageReached = claimSearchByQueryLastPageReached[searchKey];
|
const claimSearchResultLastPageReached = claimSearchByQueryLastPageReached[searchKey];
|
||||||
|
const isUnfetchedClaimSearch = claimSearchResult === undefined;
|
||||||
|
|
||||||
// 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';
|
||||||
|
@ -515,8 +517,27 @@ function ClaimListDiscover(props: Props) {
|
||||||
</div>
|
</div>
|
||||||
);
|
);
|
||||||
|
|
||||||
const renderUris = uris || claimSearchResult;
|
// **************************************************************************
|
||||||
injectPinUrls(renderUris, orderParam, pins);
|
// **************************************************************************
|
||||||
|
|
||||||
|
let finalUris;
|
||||||
|
|
||||||
|
if (uris) {
|
||||||
|
// --- direct uris
|
||||||
|
finalUris = uris;
|
||||||
|
injectPinUrls(finalUris, orderParam, pins);
|
||||||
|
filterExcludedUris(finalUris, excludeUris);
|
||||||
|
} else {
|
||||||
|
// --- searched uris
|
||||||
|
if (isUnfetchedClaimSearch && prevUris.current) {
|
||||||
|
finalUris = prevUris.current;
|
||||||
|
} else {
|
||||||
|
finalUris = claimSearchResult;
|
||||||
|
injectPinUrls(finalUris, orderParam, pins);
|
||||||
|
filterExcludedUris(finalUris, excludeUris);
|
||||||
|
prevUris.current = finalUris;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
// **************************************************************************
|
// **************************************************************************
|
||||||
// Helpers
|
// Helpers
|
||||||
|
@ -609,12 +630,19 @@ function ClaimListDiscover(props: Props) {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
function filterExcludedUris(uris, excludeUris) {
|
||||||
|
if (uris && excludeUris && excludeUris.length) {
|
||||||
|
uris = uris.filter((uri) => !excludeUris.includes(uri));
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
// **************************************************************************
|
// **************************************************************************
|
||||||
// **************************************************************************
|
// **************************************************************************
|
||||||
useFetchViewCount(fetchViewCount, renderUris, claimsByUri, doFetchViewCount);
|
|
||||||
|
useFetchViewCount(fetchViewCount, finalUris, claimsByUri, doFetchViewCount);
|
||||||
|
|
||||||
const shouldFetchUserMemberships = true;
|
const shouldFetchUserMemberships = true;
|
||||||
const arrayOfContentUris = renderUris;
|
const arrayOfContentUris = finalUris;
|
||||||
const convertClaimUrlsToIds = claimsByUri;
|
const convertClaimUrlsToIds = claimsByUri;
|
||||||
|
|
||||||
useGetUserMemberships(shouldFetchUserMemberships, arrayOfContentUris, convertClaimUrlsToIds, doFetchUserMemberships);
|
useGetUserMemberships(shouldFetchUserMemberships, arrayOfContentUris, convertClaimUrlsToIds, doFetchUserMemberships);
|
||||||
|
@ -668,7 +696,7 @@ function ClaimListDiscover(props: Props) {
|
||||||
<ClaimList
|
<ClaimList
|
||||||
tileLayout
|
tileLayout
|
||||||
loading={loading}
|
loading={loading}
|
||||||
uris={renderUris}
|
uris={finalUris}
|
||||||
prefixUris={prefixUris}
|
prefixUris={prefixUris}
|
||||||
onScrollBottom={handleScrollBottom}
|
onScrollBottom={handleScrollBottom}
|
||||||
page={page}
|
page={page}
|
||||||
|
@ -682,7 +710,6 @@ function ClaimListDiscover(props: Props) {
|
||||||
showNoSourceClaims={showNoSourceClaims}
|
showNoSourceClaims={showNoSourceClaims}
|
||||||
empty={empty}
|
empty={empty}
|
||||||
maxClaimRender={maxClaimRender}
|
maxClaimRender={maxClaimRender}
|
||||||
excludeUris={excludeUris}
|
|
||||||
loadedCallback={loadedCallback}
|
loadedCallback={loadedCallback}
|
||||||
swipeLayout={swipeLayout}
|
swipeLayout={swipeLayout}
|
||||||
/>
|
/>
|
||||||
|
@ -709,7 +736,7 @@ function ClaimListDiscover(props: Props) {
|
||||||
<ClaimList
|
<ClaimList
|
||||||
type={type}
|
type={type}
|
||||||
loading={loading}
|
loading={loading}
|
||||||
uris={renderUris}
|
uris={finalUris}
|
||||||
prefixUris={prefixUris}
|
prefixUris={prefixUris}
|
||||||
onScrollBottom={handleScrollBottom}
|
onScrollBottom={handleScrollBottom}
|
||||||
page={page}
|
page={page}
|
||||||
|
@ -723,7 +750,6 @@ function ClaimListDiscover(props: Props) {
|
||||||
showNoSourceClaims={hasNoSource || showNoSourceClaims}
|
showNoSourceClaims={hasNoSource || showNoSourceClaims}
|
||||||
empty={empty}
|
empty={empty}
|
||||||
maxClaimRender={maxClaimRender}
|
maxClaimRender={maxClaimRender}
|
||||||
excludeUris={excludeUris}
|
|
||||||
loadedCallback={loadedCallback}
|
loadedCallback={loadedCallback}
|
||||||
swipeLayout={swipeLayout}
|
swipeLayout={swipeLayout}
|
||||||
/>
|
/>
|
||||||
|
|
Loading…
Reference in a new issue