Skip to content
Draft
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 4 additions & 0 deletions apps/insights/src/components/PriceComponentsCard/index.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -160,6 +160,7 @@ export const ResolvedPriceComponentsCard = <
numResults,
numPages,
mkPageLink,
isPending,
} = useQueryParamFilterPagination(
componentsFilteredByStatus,
(component, search) => filter.contains(component.nameAsString, search),
Expand Down Expand Up @@ -314,6 +315,7 @@ export const ResolvedPriceComponentsCard = <
onStatusChange={updateStatus}
showQuality={showQuality}
setShowQuality={updateShowQuality}
isPending={isPending}
{...props}
/>
);
Expand Down Expand Up @@ -354,6 +356,7 @@ type PriceComponentsCardProps<
showQuality: boolean;
setShowQuality: (newValue: boolean) => void;
rows: (RowConfig<string> & { nameAsString: string })[];
isPending: boolean;
}
);

Expand Down Expand Up @@ -421,6 +424,7 @@ export const PriceComponentsCardContents = <
: {
value: props.search,
onChange: props.onSearchChange,
isPending: props.isPending,
})}
/>
</div>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -81,6 +81,7 @@ const ResolvedPriceFeedsCard = ({ priceFeeds, ...props }: Props) => {
numResults,
numPages,
mkPageLink,
isPending,
} = useQueryParamFilterPagination(
feedsFilteredByAssetClass,
() => true,
Expand Down Expand Up @@ -188,6 +189,7 @@ const ResolvedPriceFeedsCard = ({ priceFeeds, ...props }: Props) => {
onPageChange={updatePage}
mkPageLink={mkPageLink}
rows={rows}
isPending={isPending}
{...props}
/>
);
Expand Down Expand Up @@ -221,6 +223,7 @@ type PriceFeedsCardContents = Pick<Props, "id"> &
| "exponent"
| "numPublishers"
> & { textValue: string })[];
isPending: boolean;
}
);

Expand Down Expand Up @@ -252,6 +255,7 @@ const PriceFeedsCardContents = ({ id, ...props }: PriceFeedsCardContents) => (
: {
value: props.search,
onChange: props.onSearchChange,
isPending: props.isPending,
})}
/>
<Select
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ import {
createSerializer,
} from "@pythnetwork/react-hooks/nuqs";
import { usePathname } from "next/navigation";
import { useCallback, useMemo } from "react";
import { useCallback, useDeferredValue, useMemo } from "react";

import type { SortDescriptor } from "../unstyled/Table";
import { useLogger } from "../useLogger";
Expand Down Expand Up @@ -42,6 +42,9 @@ export const useQueryParamFilterPagination = <T>(
const [{ search, page, pageSize, sort, descending }, setQuery] =
useQueryStates(queryParams);

const deferredSearch = useDeferredValue(search);
const isPending = search !== deferredSearch;

const sortDescriptor = useMemo(
(): SortDescriptor => ({
column: sort,
Expand Down Expand Up @@ -93,8 +96,10 @@ export const useQueryParamFilterPagination = <T>(

const filteredItems = useMemo(
() =>
search === "" ? items : items.filter((item) => predicate(item, search)),
[items, search, predicate],
deferredSearch === ""
? items
: items.filter((item) => predicate(item, deferredSearch)),
[items, deferredSearch, predicate],
);

const sortedItems = useMemo(
Expand All @@ -103,8 +108,8 @@ export const useQueryParamFilterPagination = <T>(
);

const mutatedItems = useMemo(() => {
return doMutate(sortedItems, search);
}, [doMutate, sortedItems, search]);
return doMutate(sortedItems, deferredSearch);
}, [doMutate, sortedItems, deferredSearch]);

const paginatedItems = useMemo(
() => mutatedItems.slice((page - 1) * pageSize, page * pageSize),
Expand Down Expand Up @@ -139,5 +144,6 @@ export const useQueryParamFilterPagination = <T>(
numPages,
mkPageLink,
numResults: mutatedItems.length,
isPending,
};
};
Loading