Skip to content

Justinnn07/infinite scroll #164

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Open
wants to merge 9 commits into
base: NEW-UI
Choose a base branch
from
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
54 changes: 52 additions & 2 deletions src/components/Home/Home.js
Original file line number Diff line number Diff line change
Expand Up @@ -100,6 +100,31 @@ const Home = (props) => {
"Find By Pincode & Date(Slots for next 7 days)",
"Find By District & Date(Slots for next 7 days)",
]);
const [vaccinePerPage, setVaccinePerPage] = useState(3);
const [loadMore, setLoadMore] = useState(false);

const currentVaccine = vaccineData.slice(0, vaccinePerPage);

const onScroll = () => {
setLoadMore(true);
if (vaccineData.length < vaccinePerPage + 3) {
setLoadMore(false);
}
setTimeout(() => {
setVaccinePerPage(vaccinePerPage + 3);
setLoadMore(false);
}, 1000);
};

window.onscroll = () => {
if (
document.documentElement.clientHeight +
document.documentElement.scrollTop ===
document.documentElement.offsetHeight
) {
onScroll();
}
};

const GetFormattedDate = () => {
var month = selectedDate.getMonth() + 1;
Expand All @@ -125,13 +150,16 @@ const Home = (props) => {
setSelectedDate(date);
setVaccineData([]);
setDistrictCode("");
setLoadMore(false);
};

const onStateChange = async (e) => {
const stateCode = e.target.value;
setDistricts([]);
setVaccineData([]);
setPinCodeSearch(false);
setVaccinePerPage(3);
setLoadMore(false);

const url =
stateCode === "States"
Expand All @@ -150,6 +178,8 @@ const Home = (props) => {
const findByDistrict = async (e) => {
const districtCode = e.target.value;

setVaccinePerPage(3);

const url =
districtCode === "PLEASE SELECT A STATE FIRST"
? null
Expand Down Expand Up @@ -476,11 +506,31 @@ const Home = (props) => {
<CircularProgress />
</div>
) : (
<VaccineDataMain vaccineData={vaccineData} />
<>
{loadMore === true ? (
<>
<VaccineDataMain
vaccineData={vaccineData.slice(0, vaccinePerPage)}
/>
<div
style={{
display: "flex",
justifyContent: "center",
}}
>
<CircularProgress />
</div>
</>
) : (
<>
<VaccineDataMain vaccineData={currentVaccine} />
</>
)}
</>
)}
<NullState
toSearchValue={toSearchValue}
vaccineData={vaccineData}
vaccineData={currentVaccine}
districtCode={districtCode}
VaccineDataMain={VaccineDataMain}
pin={pin}
Expand Down