rename clearSearchHistory function and adjust code structure

This commit is contained in:
starknt
2024-01-05 14:49:01 +08:00
parent 0b27a0cc87
commit 8263304bfc
2 changed files with 9 additions and 9 deletions

View File

@@ -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>

View File

@@ -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([]))
}