mirror of
https://github.com/BewlyBewly/BewlyBewly.git
synced 2025-04-14 13:15:29 +00:00
rename clearSearchHistory function and adjust code structure
This commit is contained in:
@@ -2,7 +2,7 @@
|
||||
import type { HistoryItem, SuggestionItem, SuggestionResponse } from './searchHistoryProvider'
|
||||
import {
|
||||
addSearchHistory,
|
||||
clearSearchHistory,
|
||||
clearAllSearchHistory,
|
||||
getSearchHistory,
|
||||
removeSearchHistory,
|
||||
} from './searchHistoryProvider'
|
||||
@@ -21,6 +21,12 @@ const searchHistory = shallowRef<HistoryItem[]>([])
|
||||
const historyItemRef = ref<HTMLElement[]>([])
|
||||
const suggestionItemRef = ref<HTMLElement[]>([])
|
||||
|
||||
watch(isFocus, async (focus) => {
|
||||
// 延后加载搜索历史
|
||||
if (focus)
|
||||
searchHistory.value = getSearchHistory()
|
||||
})
|
||||
|
||||
function handleInput() {
|
||||
selectedIndex.value = -1
|
||||
if (keyword.value.length > 0) {
|
||||
@@ -124,15 +130,9 @@ function handleKeyDown() {
|
||||
}
|
||||
|
||||
function handleClearSearchHistory() {
|
||||
clearSearchHistory()
|
||||
clearAllSearchHistory()
|
||||
searchHistory.value = []
|
||||
}
|
||||
|
||||
watch(isFocus, async (focus) => {
|
||||
// 延后加载搜索历史
|
||||
if (focus)
|
||||
searchHistory.value = getSearchHistory()
|
||||
})
|
||||
</script>
|
||||
|
||||
<template>
|
||||
|
||||
@@ -66,6 +66,6 @@ export function removeSearchHistory(value: string) {
|
||||
localStorage.setItem(SEARCH_HISTORY_KEY, JSON.stringify(history))
|
||||
}
|
||||
|
||||
export function clearSearchHistory() {
|
||||
export function clearAllSearchHistory() {
|
||||
localStorage.setItem(SEARCH_HISTORY_KEY, JSON.stringify([]))
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user