Skip to content

Commit

Permalink
fix: pagination not reseting after filter changes
Browse files Browse the repository at this point in the history
  • Loading branch information
ytkimirti committed May 3, 2024
1 parent 893eecc commit fd2b867
Show file tree
Hide file tree
Showing 2 changed files with 8 additions and 1 deletion.
Original file line number Diff line number Diff line change
Expand Up @@ -44,10 +44,12 @@ export function Sidebar({ onDataKeyChange, selectedDataKey }: Props) {
direction,
handleSearch,
refreshSearch,
resetPagination,
searchInputRef,
} = useFetchPaginatedKeys(selectedDataType);

const handleDataTypeChange = (dataType?: RedisDataTypeUnion) => {
resetPagination();
setSelectedDataType(dataType);
};

Expand Down
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
import { queryClient } from "@/lib/clients";
import { useDatabrowser } from "@/store";
import { RedisDataTypes, type RedisDataTypeUnion } from "@/types";
import { useCallback, useMemo, useRef, useState } from "react";
import { useCallback, useRef, useState } from "react";
import { useQuery } from "@tanstack/react-query";
import { useDebounce } from "./useDebounce";
import type { Redis } from "@upstash/redis";
Expand Down Expand Up @@ -192,6 +192,10 @@ export const useFetchPaginatedKeys = (dataType?: RedisDataTypeUnion) => {
[currentPage],
);

const resetPagination = () => {
setCurrentPage(0);
};

// If user doesn't pass any asterisk we add two of them to end and start
const handleSearch = (query: string) => {
setSearchTerm(!query.includes("*") ? `*${query}*` : query);
Expand All @@ -215,6 +219,7 @@ export const useFetchPaginatedKeys = (dataType?: RedisDataTypeUnion) => {
isLoading,
error,
data: data?.keys,
resetPagination,
handlePageChange,
handleSearch,
refreshSearch,
Expand Down

0 comments on commit fd2b867

Please sign in to comment.