Skip to content
This repository has been archived by the owner on Apr 14, 2022. It is now read-only.

Commit

Permalink
reset offset to 0 when getads is clicked. (#23)
Browse files Browse the repository at this point in the history
  • Loading branch information
macpd authored May 22, 2020
1 parent 4ee0d3d commit 6daa8c4
Showing 1 changed file with 7 additions and 1 deletion.
8 changes: 7 additions & 1 deletion src/App.js
Original file line number Diff line number Diff line change
Expand Up @@ -90,6 +90,7 @@ const AdScreener = (params) => {
const [orderDirection, setOrderDirection] = useState({ selectedOption: params.orderDirections[0] });
const numResultsToRequest = 20;
const resultsOffset = useRef(0);
const resetOffset = () => { resultsOffset.current = 0 };
const incermentOffset = (i) => { resultsOffset.current = resultsOffset.current + i };
const decermentOffset = (i) => { if (resultsOffset.current >= i) {resultsOffset.current = resultsOffset.current - i }};
const [showModal, setShowModal] = useState(false);
Expand Down Expand Up @@ -151,6 +152,11 @@ const AdScreener = (params) => {
getAds();
};

const getFirstPageOfAds = () => {
resetOffset();
getAds();
};

return (
<div className="App">
<header className="App-header">
Expand Down Expand Up @@ -219,7 +225,7 @@ const AdScreener = (params) => {
endDate={endDate}
setEndDate={setEndDate}
/>
<Button variant="primary" onClick={getAds}>Get Ads</Button>
<Button variant="primary" onClick={getFirstPageOfAds}>Get Ads</Button>
</div>
<div className="App-ad-pane">
{ads.map((ad) => (
Expand Down

0 comments on commit 6daa8c4

Please sign in to comment.