mirror of
https://github.com/walkxcode/dashboard-icons.git
synced 2025-06-28 15:30:22 +08:00
fix(web): Adjust current page in IconSearch on pagination changes
This commit is contained in:
parent
e9fe6d3842
commit
f32b62009b
@ -227,6 +227,21 @@ export function IconSearch({ icons }: IconSearchProps) {
|
|||||||
[pathname, router, initialSort],
|
[pathname, router, initialSort],
|
||||||
)
|
)
|
||||||
|
|
||||||
|
// Validate currentPage when iconsPerPage or filteredIcons change
|
||||||
|
useEffect(() => {
|
||||||
|
// Calculate new total pages
|
||||||
|
const totalPages = Math.ceil(filteredIcons.length / iconsPerPage)
|
||||||
|
|
||||||
|
// If current page is out of bounds, adjust it
|
||||||
|
if (currentPage > totalPages && totalPages > 0) {
|
||||||
|
// Update current page state
|
||||||
|
setCurrentPage(totalPages)
|
||||||
|
|
||||||
|
// Update URL to reflect the adjusted page
|
||||||
|
updateResults(searchQuery, selectedCategories, sortOption, totalPages)
|
||||||
|
}
|
||||||
|
}, [iconsPerPage, filteredIcons.length, currentPage, searchQuery, selectedCategories, sortOption, updateResults])
|
||||||
|
|
||||||
const handleSearch = useCallback(
|
const handleSearch = useCallback(
|
||||||
(query: string) => {
|
(query: string) => {
|
||||||
setSearchQuery(query)
|
setSearchQuery(query)
|
||||||
|
Loading…
x
Reference in New Issue
Block a user