mirror of
https://wget.la/https://github.com/Wxw-Gu/WechatExplorer
synced 2026-10-08 07:21:19 +08:00
test: 测试用例
This commit is contained in:
@@ -1,12 +1,11 @@
|
|||||||
import { useEffect, useRef, useState, type Dispatch, type SetStateAction } from 'react'
|
import { useEffect, useRef, useState, type Dispatch, type SetStateAction } from 'react'
|
||||||
import { aiSearchRangeStart, inferAiSearchTimeRange } from '../../../../../shared/ai-search'
|
import { aiSearchRangeStart } from '../../../../../shared/ai-search'
|
||||||
import type { AiSearchTimeRange } from '../../../../../shared/ai-search'
|
import type { AiSearchTimeRange } from '../../../../../shared/ai-search'
|
||||||
import {
|
import {
|
||||||
RANGE_LABELS,
|
RANGE_LABELS,
|
||||||
SEARCH_ACTIVE_RESULT_KEY,
|
SEARCH_ACTIVE_RESULT_KEY,
|
||||||
SEARCH_CACHE_KEY,
|
SEARCH_CACHE_KEY,
|
||||||
SEARCH_HISTORY_KEY,
|
SEARCH_HISTORY_KEY,
|
||||||
buildSearchCacheKey,
|
|
||||||
parseSearchCacheKey,
|
parseSearchCacheKey,
|
||||||
readSearchCache,
|
readSearchCache,
|
||||||
writeSearchCache
|
writeSearchCache
|
||||||
@@ -59,9 +58,9 @@ type PersistSearchResultInput = {
|
|||||||
|
|
||||||
export function useSearchHistory({
|
export function useSearchHistory({
|
||||||
query,
|
query,
|
||||||
scope,
|
scope: _scope,
|
||||||
range,
|
range: _range,
|
||||||
conversationContactMd5,
|
conversationContactMd5: _conversationContactMd5,
|
||||||
evidencePageSize = DEFAULT_EVIDENCE_PAGE_SIZE,
|
evidencePageSize = DEFAULT_EVIDENCE_PAGE_SIZE,
|
||||||
setQuery,
|
setQuery,
|
||||||
setScope,
|
setScope,
|
||||||
@@ -177,15 +176,18 @@ export function useSearchHistory({
|
|||||||
setQuery(historyQuery)
|
setQuery(historyQuery)
|
||||||
setSelectedEvidence(0)
|
setSelectedEvidence(0)
|
||||||
setHistoryOpen(false)
|
setHistoryOpen(false)
|
||||||
const resolvedTimeRange = inferAiSearchTimeRange(historyQuery, range, new Date())
|
// History entries can originate from a different scope/range than the
|
||||||
const cacheKey = buildSearchCacheKey(
|
// current composer state. Find by normalized query first, then restore the
|
||||||
scope,
|
// cache key's authoritative scope and range below.
|
||||||
scope === 'conversation' ? conversationContactMd5 : '',
|
let cached: AISearchCacheRecord | null = null
|
||||||
range,
|
try {
|
||||||
historyQuery,
|
const records = JSON.parse(localStorage.getItem(SEARCH_CACHE_KEY) || '[]') as AISearchCacheRecord[]
|
||||||
resolvedTimeRange
|
cached = records
|
||||||
)
|
.filter((record) => typeof record?.key === 'string' && parseSearchCacheKey(record.key)?.query === historyQuery.trim().toLowerCase())
|
||||||
const cached = readSearchCache(cacheKey)
|
.sort((a, b) => b.createdAt - a.createdAt)[0] || null
|
||||||
|
} catch {
|
||||||
|
cached = null
|
||||||
|
}
|
||||||
if (!cached) {
|
if (!cached) {
|
||||||
setAnswer('')
|
setAnswer('')
|
||||||
setEvidence([])
|
setEvidence([])
|
||||||
|
|||||||
Reference in New Issue
Block a user