@@ -17,6 +17,11 @@ import { type ColumnDef } from "@tanstack/react-table";
1717import { useEffect , useState } from "react" ;
1818
1919export default function TeamsIdeasTable ( ) {
20+ const [ cursorHistory , setCursorHistory ] = useState < string [ ] > ( [ ] ) ;
21+ const [ currentCursor , setCurrentCursor ] = useState < string | undefined > (
22+ undefined ,
23+ ) ;
24+
2025 const [ pageLimit , setPageLimit ] = useState ( 10 ) ;
2126 const [ searchTerm , setSearchTerm ] = useState ( "" ) ;
2227 const [ currentPage , setCurrentPage ] = useState ( 0 ) ;
@@ -35,7 +40,21 @@ export default function TeamsIdeasTable() {
3540 cursorId : undefined ,
3641 } ) ,
3742 } ) ;
43+ const handleNextPage = ( ) => {
44+ if ( ideasData ?. nextCursor ) {
45+ console . log ( "yes cursor available" ) ;
46+ setCursorHistory ( ( prev ) => [ ...prev , currentCursor ?? "" ] ) ; // Store current cursor
47+ setCurrentCursor ( ideasData . nextCursor ) ; // Move to the next page
48+ }
49+ } ;
3850
51+ const handlePrevPage = ( ) => {
52+ if ( cursorHistory . length > 0 ) {
53+ const prevCursor = cursorHistory [ cursorHistory . length - 1 ] ; // Get last cursor
54+ setCursorHistory ( ( prev ) => prev . slice ( 0 , - 1 ) ) ; // Remove last cursor from history
55+ setCurrentCursor ( prevCursor ?? undefined ) ; // Move to previous page
56+ }
57+ } ;
3958 const columns : ColumnDef < ideaType , unknown > [ ] = [
4059 {
4160 accessorKey : "numberOfPeople" ,
@@ -137,8 +156,8 @@ export default function TeamsIdeasTable() {
137156 < DataTable
138157 columns = { columns }
139158 data = { ideasData ?. idea }
140- handleNextPage = { ( ) => setCurrentPage ( ( prev ) => prev + 1 ) }
141- handlePrevPage = { ( ) => setCurrentPage ( ( prev ) => prev - 1 ) }
159+ handleNextPage = { handleNextPage }
160+ handlePrevPage = { handlePrevPage }
142161 setPageLimit = { setPageLimit }
143162 pageLimit = { pageLimit }
144163 />
0 commit comments