refactor: simplify recent searches handling in MarketSearchBar
- Updated recent searches logic to directly manipulate the recentSearches value, improving clarity and reducing complexity. - Changed the filtering mechanism to use a more straightforward approach, enhancing maintainability. These changes streamline the recent searches functionality, contributing to a cleaner and more efficient MarketSearchBar component.
This commit is contained in:
parent
3d5f1230e7
commit
bdc74f9c90
1 changed files with 4 additions and 3 deletions
|
|
@ -338,14 +338,15 @@ const applyRecentSearch = (recent: string) => {
|
||||||
const addToRecentSearches = (query: string) => {
|
const addToRecentSearches = (query: string) => {
|
||||||
if (!props.showEnhancements) return
|
if (!props.showEnhancements) return
|
||||||
|
|
||||||
const searches = recentSearches.value.value.filter(s => s !== query)
|
const currentSearches = recentSearches.value as string[]
|
||||||
|
const searches = currentSearches.filter((s: string) => s !== query)
|
||||||
searches.unshift(query)
|
searches.unshift(query)
|
||||||
recentSearches.value.value = searches.slice(0, 10) // Keep only 10 recent searches
|
recentSearches.value = searches.slice(0, 10) as any // Keep only 10 recent searches
|
||||||
}
|
}
|
||||||
|
|
||||||
const clearRecentSearches = () => {
|
const clearRecentSearches = () => {
|
||||||
if (props.showEnhancements) {
|
if (props.showEnhancements) {
|
||||||
recentSearches.value.value = []
|
recentSearches.value = [] as any
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue