-
Notifications
You must be signed in to change notification settings - Fork 47
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #2116 from ever-co/feat/pagination
feat: pagination of Tasks on Profile page
- Loading branch information
Showing
6 changed files
with
70 additions
and
4 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,37 @@ | ||
'use client'; | ||
|
||
import React from 'react'; | ||
|
||
export const getPartData = ({ offset = 0, limit = 10, arr = [] }: { offset?: number; limit?: number; arr: any[] }) => | ||
arr.slice(0, offset * limit + limit); | ||
|
||
export const useInfinityScrolling = (arr: any) => { | ||
const [offset, setOffset] = React.useState(0); | ||
const [data, setData] = React.useState<any[]>(arr); | ||
|
||
const getSomeTasks = React.useCallback( | ||
(offset: number) => { | ||
setData(getPartData({ arr, limit: 10, offset })); | ||
}, | ||
[arr] | ||
); | ||
|
||
const nextOffset = React.useCallback(() => { | ||
setOffset((prev) => prev + 1); | ||
setData((prev) => getPartData({ arr: prev, limit: 10, offset })); | ||
}, [offset]); | ||
|
||
React.useEffect(() => { | ||
console.log({ offset }); | ||
getSomeTasks(offset); | ||
// eslint-disable-next-line react-hooks/exhaustive-deps | ||
}, [offset]); | ||
|
||
return { | ||
offset, | ||
setOffset, | ||
getSomeTasks, | ||
nextOffset, | ||
data | ||
}; | ||
}; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,22 @@ | ||
import React from 'react'; | ||
|
||
export const ObserverComponent = ({ isLast, getNextData }: { isLast: boolean; getNextData: () => any }) => { | ||
const cardRef = React.useRef<HTMLDivElement>(); | ||
|
||
React.useEffect(() => { | ||
if (!cardRef?.current) return; | ||
|
||
const observer = new IntersectionObserver(([entry]) => { | ||
if (isLast && entry.isIntersecting) { | ||
// fetch with new Entry | ||
console.log('IN OBSERVER'); | ||
getNextData(); | ||
observer.unobserve(entry.target); | ||
} | ||
}); | ||
|
||
observer.observe(cardRef.current); | ||
}, [isLast, getNextData]); | ||
// @ts-expect-error | ||
return <div ref={cardRef} className="-z-10 h-2 bg-transparent " />; | ||
}; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters