From ffaade32d6b53c0e27592ad93409045db853b3a8 Mon Sep 17 00:00:00 2001 From: shafi54 <108669266+shafi-aviz@users.noreply.github.com> Date: Wed, 4 Mar 2026 01:12:43 +0530 Subject: [PATCH] enh --- apps/fallback-ui/src/routes/user-connect.tsx | 189 ++++++++++++++++--- 1 file changed, 158 insertions(+), 31 deletions(-) diff --git a/apps/fallback-ui/src/routes/user-connect.tsx b/apps/fallback-ui/src/routes/user-connect.tsx index f8e93e0..93073d2 100644 --- a/apps/fallback-ui/src/routes/user-connect.tsx +++ b/apps/fallback-ui/src/routes/user-connect.tsx @@ -1,31 +1,61 @@ -import { useState } from 'react' +import { useState, useCallback } from 'react' import { trpc } from '@/trpc/client' export function UserConnectRoute() { const [search, setSearch] = useState('') const [searchInput, setSearchInput] = useState('') - const [cursor, setCursor] = useState(undefined) + const [currentPage, setCurrentPage] = useState(1) + const [visitedCursors, setVisitedCursors] = useState<(number | undefined)[]>([undefined]) + const [itemsPerPage, setItemsPerPage] = useState(50) + + const cursor = visitedCursors[currentPage - 1] const { data, isLoading, error } = trpc.admin.user.getAllUsers.useQuery({ - limit: 50, + limit: itemsPerPage, cursor, search, }) const handleSearch = () => { setSearch(searchInput) - setCursor(undefined) + setCurrentPage(1) + setVisitedCursors([undefined]) } const handleNextPage = () => { if (data?.nextCursor) { - setCursor(data.nextCursor) - } + const newCursors = [...visitedCursors] + newCursors[currentPage] = data.nextCursor + setVisitedCursors(newCursors) + setCurrentPage(currentPage + 1) + } } const handlePrevPage = () => { - setCursor(undefined) + if (currentPage > 1) { + setCurrentPage(currentPage - 1) } + } + + const handlePageSelect = (page: number) => { + setCurrentPage(page) + } + + const handleClearSearch = () => { + setSearch('') + setSearchInput('') + setCurrentPage(1) + setVisitedCursors([undefined]) + } + + const handleItemsPerPageChange = (newLimit: number) => { + setItemsPerPage(newLimit) + setCurrentPage(1) + setVisitedCursors([undefined]) + } + + const totalPages = Math.min(currentPage + (data?.hasMore ? 3 : 0), 20) + const pageNumbers = Array.from({ length: totalPages }, (_, i) => i + 1) if (isLoading) { return ( @@ -76,11 +106,7 @@ export function UserConnectRoute() { {search && ( + + {pageNumbers.map((page) => ( + + ))} + + {data?.hasMore && currentPage >= totalPages - 2 && ( + ... + )} + + + + )} + + +
@@ -147,25 +242,57 @@ export function UserConnectRoute() {
-

- Showing {data?.users.length || 0} users -

-
- {cursor !== undefined && ( - - )} - {data?.hasMore && ( - +
+

+ Page {currentPage} • Showing {data?.users.length || 0} users +

+
+ +
+ {pageNumbers.length > 1 && ( + <> + + + {pageNumbers.map((page) => ( + + ))} + + {data?.hasMore && currentPage >= totalPages - 2 && ( + ... + )} + + + )}