Skip to content
Projects
Groups
Snippets
Help
Loading...
Help
Support
Submit feedback
Contribute to GitLab
Sign in
Toggle navigation
I
interface
Project
Project
Details
Activity
Releases
Cycle Analytics
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Charts
Issues
0
Issues
0
List
Boards
Labels
Milestones
Merge Requests
0
Merge Requests
0
CI / CD
CI / CD
Pipelines
Jobs
Schedules
Charts
Wiki
Wiki
Snippets
Snippets
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Charts
Create a new issue
Jobs
Commits
Issue Boards
Open sidebar
LuckySwap
interface
Commits
a75e239f
Unverified
Commit
a75e239f
authored
Oct 10, 2022
by
Zach Pomerantz
Committed by
GitHub
Oct 10, 2022
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
fix: keep search history synced with trending (#4854)
parent
a663482d
Changes
2
Hide whitespace changes
Inline
Side-by-side
Showing
2 changed files
with
15 additions
and
2 deletions
+15
-2
SearchBarDropdown.tsx
src/components/NavBar/SearchBarDropdown.tsx
+4
-2
useSearchHistory.ts
src/nft/hooks/useSearchHistory.ts
+11
-0
No files found.
src/components/NavBar/SearchBarDropdown.tsx
View file @
a75e239f
...
@@ -106,7 +106,7 @@ interface SearchBarDropdownProps {
...
@@ -106,7 +106,7 @@ 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
((
state
:
{
history
:
(
FungibleToken
|
GenieCollection
)[]
})
=>
state
.
history
)
const
{
history
:
searchHistory
,
updateItem
:
updateSearchHistory
}
=
useSearchHistory
(
)
const
shortenedHistory
=
useMemo
(()
=>
searchHistory
.
slice
(
0
,
2
),
[
searchHistory
])
const
shortenedHistory
=
useMemo
(()
=>
searchHistory
.
slice
(
0
,
2
),
[
searchHistory
])
const
{
pathname
}
=
useLocation
()
const
{
pathname
}
=
useLocation
()
const
isNFTPage
=
pathname
.
includes
(
'
/nfts
'
)
const
isNFTPage
=
pathname
.
includes
(
'
/nfts
'
)
...
@@ -146,9 +146,11 @@ export const SearchBarDropdown = ({ toggleOpen, tokens, collections, hasInput, i
...
@@ -146,9 +146,11 @@ export const SearchBarDropdown = ({ toggleOpen, tokens, collections, hasInput, i
refetchOnReconnect
:
false
,
refetchOnReconnect
:
false
,
}
}
)
)
useEffect
(()
=>
{
trendingTokenResults
?.
forEach
(
updateSearchHistory
)
},
[
trendingTokenResults
,
updateSearchHistory
])
const
trendingTokensLength
=
phase1Flag
===
NftVariant
.
Enabled
?
(
isTokenPage
?
3
:
2
)
:
4
const
trendingTokensLength
=
phase1Flag
===
NftVariant
.
Enabled
?
(
isTokenPage
?
3
:
2
)
:
4
const
trendingTokens
=
useMemo
(
const
trendingTokens
=
useMemo
(
()
=>
()
=>
trendingTokenResults
trendingTokenResults
...
...
src/nft/hooks/useSearchHistory.ts
View file @
a75e239f
...
@@ -5,6 +5,7 @@ import { devtools, persist } from 'zustand/middleware'
...
@@ -5,6 +5,7 @@ import { devtools, persist } from 'zustand/middleware'
interface
SearchHistoryProps
{
interface
SearchHistoryProps
{
history
:
(
FungibleToken
|
GenieCollection
)[]
history
:
(
FungibleToken
|
GenieCollection
)[]
addItem
:
(
item
:
FungibleToken
|
GenieCollection
)
=>
void
addItem
:
(
item
:
FungibleToken
|
GenieCollection
)
=>
void
updateItem
:
(
update
:
FungibleToken
|
GenieCollection
)
=>
void
}
}
export
const
useSearchHistory
=
create
<
SearchHistoryProps
>
()(
export
const
useSearchHistory
=
create
<
SearchHistoryProps
>
()(
...
@@ -18,6 +19,16 @@ export const useSearchHistory = create<SearchHistoryProps>()(
...
@@ -18,6 +19,16 @@ export const useSearchHistory = create<SearchHistoryProps>()(
return
{
history
:
historyCopy
}
return
{
history
:
historyCopy
}
})
})
},
},
updateItem
:
(
update
:
FungibleToken
|
GenieCollection
)
=>
{
set
(({
history
})
=>
{
const
index
=
history
.
findIndex
((
item
)
=>
item
.
address
===
update
.
address
)
if
(
index
===
-
1
)
return
{
history
}
const
historyCopy
=
[...
history
]
historyCopy
[
index
]
=
update
return
{
history
:
historyCopy
}
})
},
})),
})),
{
name
:
'
useSearchHistory
'
}
{
name
:
'
useSearchHistory
'
}
)
)
...
...
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment