Closed armandocodecr closed 1 week ago
I just realized that I created a utils folder to export the file named "truncateText.ts" when you already have a "utils" file in the "lib" folder. An apology for the oversight.
If you wish I can make the change to export the "truncateText" function from the "utils" file in the "lib" folder, and then create a commit and include it in the pull request changes.
@saimeunt It is a pleasure to have contributed to this issue. I remain at your disposal to collaborate again for a v2 of the search box. 🤝
Implement Search Box v1: Block, Transaction, and Address Search
Description
This Pull Request implements the
Search Box v1
feature, allowing users to search by block number, transaction hash, or address within the application. The functionality is integrated into the navbar's search input and provides a dropdown with categorized results. Below is a detailed breakdown of the changes made:Changes
Create
useSearch
Custom Hook:hooks/useSearch.ts
useSearch
to handle search logic for blocks, transactions, and addresses.handleBlockSearch
,handleTransactionSearch
, andhandleAddressSearch
handle specific searches and update results based on the input.updateSearchResult
updates the search results state by category.searchResult
,selectedCategory
, andshowResult
.Integrate
useSearch
intoSearch
Component:components/Search.tsx
Search
component with theuseSearch
hook.onQueryChanged
from the hook to handle input changes and update search results.SearchResultDropDown
to display results in a categorized dropdown menu.Search
component now effectively manages the input for search queries and displays results dynamically.Implement
SearchResultDropDown
Component:components/search-result-dropdown.tsx
SearchResultDropDown
to display search results below the input field.showResult
state fromuseSearch
.Add
CategoryListDropdown
andCategoryValuesList
Components:components/category-list-dropdown.tsx
,components/category-values-list.tsx
CategoryListDropdown
:CategoryValuesList
:truncateText
to format and shorten long strings in the results.Add Basic Pages for
/block/:number
and/address/:address
:pages/block/[number].tsx
,pages/address/[address].tsx
<h1>
element for now, serving as placeholders for future detailed views.Add
truncateText
Utility Function:utils/truncateText.ts
truncateText
to shorten long strings for display.CategoryValuesList
to show abbreviated versions of block numbers, transaction hashes, and addresses while preserving their beginning and ending characters.Add
SearchInputResult
Interface:interfaces/index.ts
SearchInputResult
interface to define the structure of search result objects.Add Styles for Dropdown and Scrollbar:
styles/global.css
(or relevant CSS file).card
class to style the dropdown with a blurred background and rounded corners..custom-scroll
classes to match the application's theme, including a customized thumb color.Detailed Code Explanations
Debounce Implementation in
useSearch
:useRef
andsetTimeout
. This ensures that the API call to fetch search results is delayed by 500ms after the user stops typing. It helps to reduce the number of API requests, enhancing performance and user experience.Dynamic Search Handling:
handleBlockSearch
,handleTransactionSearch
, andhandleAddressSearch
encapsulate the logic for fetching data from the blockchain based on the type of input. Each function validates the input type and fetches corresponding data using thel2PublicClient
methods.Dropdown and Scrollbar Styling:
.card
) to ensure a consistent look with a blurred background effect..custom-scroll
) for better integration with the overall theme of the application, ensuring it remains visually appealing and user-friendly.Testing
Video Demo
Watch the video demo to see how the search box works:![Search Box Demo](https://img.youtube.com/vi/lEXUEnVASZU/0.jpg)
Linked Issues