add some comments for documentation
This commit is contained in:
parent
f24f6783d4
commit
af8d742b75
4 changed files with 20 additions and 1 deletions
|
@ -100,7 +100,9 @@ export default function ClaimList(props: Props) {
|
||||||
|
|
||||||
const [currentSort, setCurrentSort] = usePersistedState(persistedStorageKey, SORT_NEW);
|
const [currentSort, setCurrentSort] = usePersistedState(persistedStorageKey, SORT_NEW);
|
||||||
|
|
||||||
|
// reference to the claim-grid
|
||||||
const listRef = React.useRef();
|
const listRef = React.useRef();
|
||||||
|
// determine the index where the ad should be injected
|
||||||
const injectedIndex = useLastVisibleItem(injectedItem, listRef);
|
const injectedIndex = useLastVisibleItem(injectedItem, listRef);
|
||||||
|
|
||||||
// Exclude prefix uris in these results variables. We don't want to show
|
// Exclude prefix uris in these results variables. We don't want to show
|
||||||
|
@ -147,6 +149,7 @@ export default function ClaimList(props: Props) {
|
||||||
}, []);
|
}, []);
|
||||||
|
|
||||||
// @if process.env.NODE_ENV!='production'
|
// @if process.env.NODE_ENV!='production'
|
||||||
|
// code to enable replacing of a claim tile isn't available here yet
|
||||||
if (injectedItem && injectedItem.replace) {
|
if (injectedItem && injectedItem.replace) {
|
||||||
throw new Error('claimList: "injectedItem.replace" is not implemented yet');
|
throw new Error('claimList: "injectedItem.replace" is not implemented yet');
|
||||||
}
|
}
|
||||||
|
@ -198,6 +201,7 @@ export default function ClaimList(props: Props) {
|
||||||
/>
|
/>
|
||||||
);
|
);
|
||||||
|
|
||||||
|
// returns injected ad DOM when indexes match
|
||||||
const getInjectedItem = (index) => {
|
const getInjectedItem = (index) => {
|
||||||
if (injectedItem && injectedItem.node && injectedIndex === index) {
|
if (injectedItem && injectedItem.node && injectedIndex === index) {
|
||||||
return injectedItem.node;
|
return injectedItem.node;
|
||||||
|
@ -211,6 +215,7 @@ export default function ClaimList(props: Props) {
|
||||||
tileUris.map((uri, index) => (
|
tileUris.map((uri, index) => (
|
||||||
<React.Fragment key={uri}>
|
<React.Fragment key={uri}>
|
||||||
{getInjectedItem(index)}
|
{getInjectedItem(index)}
|
||||||
|
{/* inject ad node */}
|
||||||
<ClaimPreviewTile
|
<ClaimPreviewTile
|
||||||
uri={uri}
|
uri={uri}
|
||||||
showHiddenByUser={showHiddenByUser}
|
showHiddenByUser={showHiddenByUser}
|
||||||
|
|
|
@ -76,7 +76,9 @@ function ClaimTilesDiscover(props: Props) {
|
||||||
optionsStringified,
|
optionsStringified,
|
||||||
} = props;
|
} = props;
|
||||||
|
|
||||||
|
// reference to the claim-grid
|
||||||
const sectionRef = React.useRef();
|
const sectionRef = React.useRef();
|
||||||
|
// determine the index where the ad should be injected
|
||||||
const injectedIndex = useLastVisibleItem(injectedItem, sectionRef);
|
const injectedIndex = useLastVisibleItem(injectedItem, sectionRef);
|
||||||
|
|
||||||
const prevUris = React.useRef();
|
const prevUris = React.useRef();
|
||||||
|
@ -112,6 +114,7 @@ function ClaimTilesDiscover(props: Props) {
|
||||||
// --------------------------------------------------------------------------
|
// --------------------------------------------------------------------------
|
||||||
// --------------------------------------------------------------------------
|
// --------------------------------------------------------------------------
|
||||||
|
|
||||||
|
// populate the view counts for the current claim uris
|
||||||
useFetchViewCount(fetchViewCount, uris, claimsByUri, doFetchViewCount);
|
useFetchViewCount(fetchViewCount, uris, claimsByUri, doFetchViewCount);
|
||||||
|
|
||||||
// Run `doClaimSearch`
|
// Run `doClaimSearch`
|
||||||
|
@ -127,6 +130,7 @@ function ClaimTilesDiscover(props: Props) {
|
||||||
{finalUris && finalUris.length
|
{finalUris && finalUris.length
|
||||||
? finalUris.map((uri, i) => {
|
? finalUris.map((uri, i) => {
|
||||||
if (uri) {
|
if (uri) {
|
||||||
|
// if indexes match, inject ad in place of tile (aka replace it)
|
||||||
if (injectedIndex === i && injectedItem && injectedItem.replace) {
|
if (injectedIndex === i && injectedItem && injectedItem.replace) {
|
||||||
return <React.Fragment key={uri}>{injectedItem.node}</React.Fragment>;
|
return <React.Fragment key={uri}>{injectedItem.node}</React.Fragment>;
|
||||||
}
|
}
|
||||||
|
@ -134,6 +138,7 @@ function ClaimTilesDiscover(props: Props) {
|
||||||
return (
|
return (
|
||||||
<React.Fragment key={uri}>
|
<React.Fragment key={uri}>
|
||||||
{injectedIndex === i && injectedItem && injectedItem.node}
|
{injectedIndex === i && injectedItem && injectedItem.node}
|
||||||
|
{/* inject ad */}
|
||||||
<ClaimPreviewTile
|
<ClaimPreviewTile
|
||||||
showNoSourceClaims={hasNoSource || showNoSourceClaims}
|
showNoSourceClaims={hasNoSource || showNoSourceClaims}
|
||||||
uri={uri}
|
uri={uri}
|
||||||
|
|
|
@ -4,6 +4,12 @@ import type { Node } from 'react';
|
||||||
|
|
||||||
type InjectedItem = { node: Node, index?: number, replace?: boolean };
|
type InjectedItem = { node: Node, index?: number, replace?: boolean };
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Returns the index indicating where in the claim-grid to inject the ad element
|
||||||
|
* @param injectedItem
|
||||||
|
* @param listRef - A reference to the claim-grid
|
||||||
|
* @returns {number}
|
||||||
|
*/
|
||||||
export default function useLastVisibleItem(injectedItem: ?InjectedItem, listRef: any) {
|
export default function useLastVisibleItem(injectedItem: ?InjectedItem, listRef: any) {
|
||||||
const [injectedIndex, setInjectedIndex] = React.useState(injectedItem?.index);
|
const [injectedIndex, setInjectedIndex] = React.useState(injectedItem?.index);
|
||||||
|
|
||||||
|
@ -18,8 +24,11 @@ export default function useLastVisibleItem(injectedItem: ?InjectedItem, listRef:
|
||||||
const timer = setTimeout(() => {
|
const timer = setTimeout(() => {
|
||||||
if (listRef.current) {
|
if (listRef.current) {
|
||||||
const screenBottom = window.innerHeight;
|
const screenBottom = window.innerHeight;
|
||||||
|
|
||||||
|
// claim preview tiles
|
||||||
const items = listRef.current.children;
|
const items = listRef.current.children;
|
||||||
|
|
||||||
|
// algo to return index of item, where ad will be injected before it
|
||||||
if (items.length) {
|
if (items.length) {
|
||||||
let i = 2; // Start from 2, so that the min possible is index-1
|
let i = 2; // Start from 2, so that the min possible is index-1
|
||||||
for (; i < items.length; ++i) {
|
for (; i < items.length; ++i) {
|
||||||
|
|
|
@ -121,7 +121,7 @@ function Ads(props: Props) {
|
||||||
return (
|
return (
|
||||||
<div
|
<div
|
||||||
className={classnames('ads ads__claim-item', className, {
|
className={classnames('ads ads__claim-item', className, {
|
||||||
'ads__claim-item--tile': tileLayout,
|
'ads__claim-item--tile': tileLayout, // with no tileLayout it indicates sidebar ad
|
||||||
})}
|
})}
|
||||||
>
|
>
|
||||||
<div className="ad__container">
|
<div className="ad__container">
|
||||||
|
|
Loading…
Reference in a new issue