11import { redirect , Link } from '@tanstack/react-router'
2- import { useQuery , useMutation } from 'convex/react'
2+ import {
3+ useQuery as useConvexQuery ,
4+ useMutation as useConvexMutation ,
5+ useConvex ,
6+ } from 'convex/react'
7+ import { useQuery , useMutation , keepPreviousData } from '@tanstack/react-query'
38import { api } from 'convex/_generated/api'
49import { useState , useMemo , useCallback } from 'react'
510import {
@@ -18,6 +23,7 @@ import {
1823 flexRender ,
1924 type ColumnDef ,
2025} from '@tanstack/react-table'
26+ import { convexQuery } from '@convex-dev/react-query'
2127
2228// User type for table
2329type User = {
@@ -37,15 +43,20 @@ function UsersPage() {
3743 const [ cursors , setCursors ] = useState < string [ ] > ( [ '' ] ) // Track cursor history for navigation
3844 const [ currentPageIndex , setCurrentPageIndex ] = useState ( 0 )
3945
40- const user = useQuery ( api . auth . getCurrentUser )
41- const usersQuery = useQuery ( api . users . listUsers , {
42- pagination : {
43- limit : 10 ,
44- cursor : cursors [ currentPageIndex ] || null ,
45- } ,
46+ const user = useConvexQuery ( api . auth . getCurrentUser )
47+ const usersQuery = useQuery ( {
48+ ...convexQuery ( api . users . listUsers , {
49+ pagination : {
50+ limit : 10 ,
51+ cursor : cursors [ currentPageIndex ] || null ,
52+ } ,
53+ } ) ,
54+ placeholderData : keepPreviousData ,
4655 } )
4756
48- const updateUserCapabilities = useMutation ( api . users . updateUserCapabilities )
57+ const updateUserCapabilities = useConvexMutation (
58+ api . users . updateUserCapabilities
59+ )
4960
5061 const availableCapabilities = useMemo (
5162 ( ) => [ 'admin' , 'disableAds' , 'builder' ] ,
@@ -210,12 +221,12 @@ function UsersPage() {
210221
211222 // Pagination handlers
212223 const goToNextPage = ( ) => {
213- if ( usersQuery ?. continueCursor ) {
224+ if ( usersQuery ?. data ?. continueCursor ) {
214225 const newPageIndex = currentPageIndex + 1
215226
216227 // Add new cursor to history if we don't have it
217228 if ( cursors . length <= newPageIndex ) {
218- setCursors ( ( prev ) => [ ...prev , usersQuery . continueCursor ! ] )
229+ setCursors ( ( prev ) => [ ...prev , usersQuery . data . continueCursor ! ] )
219230 }
220231
221232 setCurrentPageIndex ( newPageIndex )
@@ -229,11 +240,11 @@ function UsersPage() {
229240 }
230241
231242 const canGoPrevious = currentPageIndex > 0
232- const canGoNext = ! usersQuery ?. isDone
243+ const canGoNext = ! usersQuery ?. data ?. isDone
233244
234245 // Create table instance
235246 const table = useReactTable ( {
236- data : usersQuery ?. page || [ ] ,
247+ data : usersQuery ?. data ?. page || [ ] ,
237248 columns,
238249 getCoreRowModel : getCoreRowModel ( ) ,
239250 manualPagination : true ,
@@ -352,7 +363,7 @@ function UsersPage() {
352363 </ table >
353364 </ div >
354365
355- { ( ! usersQuery || usersQuery . page . length === 0 ) && (
366+ { ( ! usersQuery || usersQuery . data ?. page . length === 0 ) && (
356367 < div className = "text-center py-12" >
357368 < FaUser className = "mx-auto h-12 w-12 text-gray-400" />
358369 < h3 className = "mt-2 text-sm font-medium text-gray-900 dark:text-white" >
@@ -369,7 +380,7 @@ function UsersPage() {
369380 < div className = "mt-6 flex items-center justify-between" >
370381 < div className = "text-sm text-gray-500 dark:text-gray-400" >
371382 Page { currentPageIndex + 1 }
372- { usersQuery && < span > • { usersQuery . page . length } users</ span > }
383+ { usersQuery && < span > • { usersQuery . data ?. page . length } users</ span > }
373384 </ div >
374385 < div className = "flex space-x-2" >
375386 < button
0 commit comments