Skip to content

Commit

Permalink
fix search param handling
Browse files Browse the repository at this point in the history
  • Loading branch information
jeremy-babylonlabs committed Dec 12, 2024
1 parent 70d93cf commit 8e126d6
Show file tree
Hide file tree
Showing 4 changed files with 19 additions and 19 deletions.
4 changes: 2 additions & 2 deletions package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "simple-staking",
"version": "0.3.21",
"version": "0.3.22",
"private": true,
"scripts": {
"dev": "next dev",
Expand Down
Original file line number Diff line number Diff line change
@@ -1,30 +1,20 @@
import { useDebounce } from "@uidotdev/usehooks";
import { useSearchParams } from "next/navigation";
import React, { useEffect, useState } from "react";
import { FiSearch } from "react-icons/fi";

interface FinalityProviderSearchProps {
onSearch: (searchTerm: string) => void;
initialSearchTerm: string;
}

export const FinalityProviderSearch: React.FC<FinalityProviderSearchProps> = ({
onSearch,
initialSearchTerm,
}) => {
// Get the finality provider from the search params
const searchParams = useSearchParams();
const initialSearchFp = searchParams.get("fp");

const [searchTerm, setSearchTerm] = useState(initialSearchFp || "");
const [searchTerm, setSearchTerm] = useState(initialSearchTerm);
const debouncedSearchTerm = useDebounce(searchTerm, 300);

// Effect for handling initial search
useEffect(() => {
if (initialSearchFp) {
onSearch(initialSearchFp);
}
}, [initialSearchFp, onSearch]);

// Effect for handling subsequent searches
// Effect for handling searches
useEffect(() => {
onSearch(debouncedSearchTerm);
}, [debouncedSearchTerm, onSearch]);
Expand Down
14 changes: 12 additions & 2 deletions src/app/components/Staking/FinalityProviders/FinalityProviders.tsx
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
import { useInfiniteQuery } from "@tanstack/react-query";
import { useSearchParams } from "next/navigation";
import { useEffect } from "react";
import InfiniteScroll from "react-infinite-scroll-component";

Expand All @@ -23,6 +24,9 @@ export const FinalityProviders: React.FC<FinalityProvidersProps> = ({
onFinalityProviderChange,
onFinalityProvidersLoad,
}) => {
const searchParams = useSearchParams();
const initialSearchFp = searchParams.get("fp");

const { isErrorOpen, showError, handleError } = useError();
const {
data: fps,
Expand Down Expand Up @@ -59,8 +63,11 @@ export const FinalityProviders: React.FC<FinalityProvidersProps> = ({
});

useEffect(() => {
if (fps?.finalityProviders && initialSearchFp) {
handleSearch(initialSearchFp);
}
fps?.finalityProviders && onFinalityProvidersLoad(fps.finalityProviders);
}, [fps, onFinalityProvidersLoad]);
}, [fps, onFinalityProvidersLoad, initialSearchFp]);

useEffect(() => {
if (
Expand Down Expand Up @@ -106,7 +113,10 @@ export const FinalityProviders: React.FC<FinalityProvidersProps> = ({
<strong>Step-1:</strong> Select a finality provider
</p>
<div className="flex gap-3">
<FinalityProviderSearch onSearch={handleSearch} />
<FinalityProviderSearch
onSearch={handleSearch}
initialSearchTerm={initialSearchFp || ""}
/>
</div>
<div className="hidden gap-2 px-4 lg:grid lg:grid-cols-stakingFinalityProvidersDesktop">
<p>Finality Provider</p>
Expand Down

0 comments on commit 8e126d6

Please sign in to comment.