Commit db5c6f82 authored by Jack Short's avatar Jack Short Committed by GitHub

fix: search rerender (#4640)

parent f161f961
...@@ -96,9 +96,8 @@ interface SearchBarDropdownProps { ...@@ -96,9 +96,8 @@ interface SearchBarDropdownProps {
export const SearchBarDropdown = ({ toggleOpen, tokens, collections, hasInput, isLoading }: SearchBarDropdownProps) => { export const SearchBarDropdown = ({ toggleOpen, tokens, collections, hasInput, isLoading }: SearchBarDropdownProps) => {
const [hoveredIndex, setHoveredIndex] = useState<number | undefined>(0) const [hoveredIndex, setHoveredIndex] = useState<number | undefined>(0)
const searchHistory = useSearchHistory( const searchHistory = useSearchHistory((state: { history: (FungibleToken | GenieCollection)[] }) => state.history)
(state: { history: (FungibleToken | GenieCollection)[] }) => state.history const shortenedHistory = useMemo(() => searchHistory.slice(0, 2), [searchHistory])
).slice(0, 2)
const { pathname } = useLocation() const { pathname } = useLocation()
const isNFTPage = pathname.includes('/nfts') const isNFTPage = pathname.includes('/nfts')
const isTokenPage = pathname.includes('/tokens') const isTokenPage = pathname.includes('/tokens')
...@@ -182,7 +181,7 @@ export const SearchBarDropdown = ({ toggleOpen, tokens, collections, hasInput, i ...@@ -182,7 +181,7 @@ export const SearchBarDropdown = ({ toggleOpen, tokens, collections, hasInput, i
const totalSuggestions = hasInput const totalSuggestions = hasInput
? tokens.length + collections.length ? tokens.length + collections.length
: Math.min(searchHistory.length, 2) + : Math.min(shortenedHistory.length, 2) +
(isNFTPage || !isTokenPage ? trendingCollections?.length ?? 0 : 0) + (isNFTPage || !isTokenPage ? trendingCollections?.length ?? 0 : 0) +
(isTokenPage || !isNFTPage ? trendingTokens?.length ?? 0 : 0) (isTokenPage || !isNFTPage ? trendingTokens?.length ?? 0 : 0)
...@@ -234,13 +233,13 @@ export const SearchBarDropdown = ({ toggleOpen, tokens, collections, hasInput, i ...@@ -234,13 +233,13 @@ export const SearchBarDropdown = ({ toggleOpen, tokens, collections, hasInput, i
) : ( ) : (
// Recent Searches, Trending Tokens, Trending Collections // Recent Searches, Trending Tokens, Trending Collections
<Column gap="20"> <Column gap="20">
{searchHistory.length > 0 && ( {shortenedHistory.length > 0 && (
<SearchBarDropdownSection <SearchBarDropdownSection
hoveredIndex={hoveredIndex} hoveredIndex={hoveredIndex}
startingIndex={0} startingIndex={0}
setHoveredIndex={setHoveredIndex} setHoveredIndex={setHoveredIndex}
toggleOpen={toggleOpen} toggleOpen={toggleOpen}
suggestions={searchHistory} suggestions={shortenedHistory}
header={<Trans>Recent searches</Trans>} header={<Trans>Recent searches</Trans>}
headerIcon={<ClockIcon />} headerIcon={<ClockIcon />}
/> />
...@@ -248,7 +247,7 @@ export const SearchBarDropdown = ({ toggleOpen, tokens, collections, hasInput, i ...@@ -248,7 +247,7 @@ export const SearchBarDropdown = ({ toggleOpen, tokens, collections, hasInput, i
{!isNFTPage && ( {!isNFTPage && (
<SearchBarDropdownSection <SearchBarDropdownSection
hoveredIndex={hoveredIndex} hoveredIndex={hoveredIndex}
startingIndex={searchHistory.length} startingIndex={shortenedHistory.length}
setHoveredIndex={setHoveredIndex} setHoveredIndex={setHoveredIndex}
toggleOpen={toggleOpen} toggleOpen={toggleOpen}
suggestions={trendingTokens} suggestions={trendingTokens}
...@@ -260,7 +259,7 @@ export const SearchBarDropdown = ({ toggleOpen, tokens, collections, hasInput, i ...@@ -260,7 +259,7 @@ export const SearchBarDropdown = ({ toggleOpen, tokens, collections, hasInput, i
{!isTokenPage && phase1Flag === NftVariant.Enabled && ( {!isTokenPage && phase1Flag === NftVariant.Enabled && (
<SearchBarDropdownSection <SearchBarDropdownSection
hoveredIndex={hoveredIndex} hoveredIndex={hoveredIndex}
startingIndex={searchHistory.length + (isNFTPage ? 0 : trendingTokens?.length ?? 0)} startingIndex={shortenedHistory.length + (isNFTPage ? 0 : trendingTokens?.length ?? 0)}
setHoveredIndex={setHoveredIndex} setHoveredIndex={setHoveredIndex}
toggleOpen={toggleOpen} toggleOpen={toggleOpen}
suggestions={trendingCollections as unknown as GenieCollection[]} suggestions={trendingCollections as unknown as GenieCollection[]}
...@@ -286,7 +285,7 @@ export const SearchBarDropdown = ({ toggleOpen, tokens, collections, hasInput, i ...@@ -286,7 +285,7 @@ export const SearchBarDropdown = ({ toggleOpen, tokens, collections, hasInput, i
hoveredIndex, hoveredIndex,
phase1Flag, phase1Flag,
toggleOpen, toggleOpen,
searchHistory, shortenedHistory,
hasInput, hasInput,
isNFTPage, isNFTPage,
isTokenPage, isTokenPage,
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment