Skip to content

Commit

Permalink
♻️ Refactor: fetch request
Browse files Browse the repository at this point in the history
  • Loading branch information
ilp-sys committed May 26, 2024
1 parent 98f8986 commit 8f2a1e0
Showing 1 changed file with 16 additions and 16 deletions.
32 changes: 16 additions & 16 deletions aeye/app/(nav)/cams/page.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -9,18 +9,17 @@ export default function Cams() {

useEffect(() => {
const fetchVideos = async () => {
try {
const response = await fetchWithInterception(
`https://api.a-eye.live/video?page=${page}&size=12`,
{
method: "GET",
}
);
const jsonData = await response.json();
setVideos((prevVideos) => [...prevVideos, ...jsonData.data.videos]);
} catch (error) {
console.error(error);
}
fetchWithInterception(
`https://api.a-eye.live/video?page=${page}&size=12`,
{
method: "GET",
}
)
.then((response) => response.json())
.then((jsonData) =>
setVideos((prevVideos) => [...prevVideos, ...jsonData.data.videos])
)
.catch((error) => console.error(error));
};

fetchVideos();
Expand All @@ -31,10 +30,11 @@ export default function Cams() {
}, [page]);

const handleScroll = () => {
if (
window.innerHeight + document.documentElement.scrollTop ===
document.documentElement.offsetHeight
) {
const threshold = 5;
const windowHeight = window.innerHeight;
const scrollTop = document.documentElement.scrollTop;
const docHeight = document.documentElement.offsetHeight;
if (windowHeight + scrollTop >= docHeight - threshold) {
setPage((prevPage) => prevPage + 1);
}
};
Expand Down

0 comments on commit 8f2a1e0

Please sign in to comment.