mirror of
https://github.com/binaricat/Netcatty.git
synced 2026-11-27 11:56:20 +00:00
fix(search): subscribe remaining search consumers to pinyin dictionary readiness
Addresses Codex P2 review finding on PR #4481: - Wire usePinyinMatcherVersion into CreateWorkspaceDialog, AddToWorkspaceDialog, SettingsSearchControl, and useSessionHistorySearch so initial pinyin queries refresh automatically once lazy pinyin-pro finishes loading
This commit is contained in:
1 parent
5f2d1e501e
commit
e307332232
4 files changed
+32
-9
No files matched your search
@@ -4,6 +4,7 @@ import {
|
||||
createSessionHistorySearch,
|
||||
type SessionHistorySearchScan,
|
||||
} from './sessionHistorySearch';
|
||||
import { usePinyinMatcherVersion } from './usePinyinMatcherVersion';
|
||||
|
||||
/** Search outside rendering, yielding between bounded slices for input/paint. */
|
||||
export function useSessionHistorySearch<T extends SessionHistorySearchTarget>(
|
||||
@@ -12,10 +13,12 @@ export function useSessionHistorySearch<T extends SessionHistorySearchTarget>(
|
||||
untitledLabel: string,
|
||||
): { filteredSessions: readonly T[]; isSearching: boolean } {
|
||||
const search = useMemo(() => createSessionHistorySearch(), []);
|
||||
const pinyinMatcherVersion = usePinyinMatcherVersion();
|
||||
const latest = useRef({ sessions, query, untitledLabel });
|
||||
const work = useRef<{
|
||||
query: string;
|
||||
untitledLabel: string;
|
||||
pinyinMatcherVersion: number;
|
||||
scan: SessionHistorySearchScan<T>;
|
||||
} | null>(null);
|
||||
const timer = useRef<ReturnType<typeof setTimeout> | null>(null);
|
||||
@@ -44,9 +47,21 @@ export function useSessionHistorySearch<T extends SessionHistorySearchTarget>(
|
||||
search.filterSessionHistory(sessions, '');
|
||||
return;
|
||||
}
|
||||
if (work.current?.query !== query || work.current.untitledLabel !== untitledLabel) {
|
||||
if (
|
||||
work.current?.query !== query
|
||||
|| work.current.untitledLabel !== untitledLabel
|
||||
|| work.current.pinyinMatcherVersion !== pinyinMatcherVersion
|
||||
) {
|
||||
if (work.current && work.current.pinyinMatcherVersion !== pinyinMatcherVersion) {
|
||||
search.clearSessionHistorySearchCache();
|
||||
}
|
||||
cancel();
|
||||
work.current = { query, untitledLabel, scan: search.createScan<T>(query, { untitledLabel }) };
|
||||
work.current = {
|
||||
query,
|
||||
untitledLabel,
|
||||
pinyinMatcherVersion,
|
||||
scan: search.createScan<T>(query, { untitledLabel }),
|
||||
};
|
||||
}
|
||||
if (timer.current !== null) return;
|
||||
const job = work.current;
|
||||
@@ -65,7 +80,7 @@ export function useSessionHistorySearch<T extends SessionHistorySearchTarget>(
|
||||
// Session updates reuse the in-flight query's match decisions, so one
|
||||
// streaming session cannot restart and starve a large history search.
|
||||
timer.current = setTimeout(run, 0);
|
||||
}, [sessions, query, untitledLabel, search]);
|
||||
}, [sessions, query, untitledLabel, search, pinyinMatcherVersion]);
|
||||
|
||||
useEffect(() => () => {
|
||||
if (timer.current !== null) clearTimeout(timer.current);
|
||||
|
||||
@@ -1,6 +1,7 @@
|
||||
import { Search } from 'lucide-react';
|
||||
import React, { useMemo, useState, useEffect, useCallback } from 'react';
|
||||
import { useI18n } from '../application/i18n/I18nProvider';
|
||||
import { usePinyinMatcherVersion } from '../application/state/usePinyinMatcherVersion';
|
||||
import { matchesWorkspaceHostPickerQuery } from '../domain/searchMatcher';
|
||||
import { Host } from '../types';
|
||||
import { DistroAvatar } from './DistroAvatar';
|
||||
@@ -29,12 +30,14 @@ export const CreateWorkspaceDialog: React.FC<CreateWorkspaceDialogProps> = ({
|
||||
const [name, setName] = useState('');
|
||||
const [search, setSearch] = useState('');
|
||||
const [selectedHostIds, setSelectedHostIds] = useState<Set<string>>(new Set());
|
||||
const pinyinMatcherVersion = usePinyinMatcherVersion();
|
||||
|
||||
const filteredHosts = useMemo(() => {
|
||||
void pinyinMatcherVersion;
|
||||
const term = search.trim();
|
||||
if (!term) return hosts;
|
||||
return hosts.filter((host) => matchesWorkspaceHostPickerQuery(term, host));
|
||||
}, [hosts, search]);
|
||||
}, [hosts, search, pinyinMatcherVersion]);
|
||||
|
||||
const toggleHost = useCallback((hostId: string) => {
|
||||
setSelectedHostIds(prev => {
|
||||
|
||||
@@ -1,6 +1,7 @@
|
||||
import { Search, X } from "lucide-react";
|
||||
import React, { useCallback, useEffect, useId, useMemo, useRef, useState } from "react";
|
||||
import { useI18n } from "../../application/i18n/I18nProvider";
|
||||
import { usePinyinMatcherVersion } from "../../application/state/usePinyinMatcherVersion";
|
||||
import { filterSettingsSearchCatalog, type SettingsSearchHit } from "../../domain/settingsSearch";
|
||||
import { cn } from "../../lib/utils";
|
||||
import { Input } from "../ui/input";
|
||||
@@ -26,11 +27,12 @@ export function SettingsSearchControl({
|
||||
const [query, setQuery] = useState("");
|
||||
const [activeIndex, setActiveIndex] = useState(0);
|
||||
const [restoreOpenFocus, setRestoreOpenFocus] = useState(false);
|
||||
const pinyinMatcherVersion = usePinyinMatcherVersion();
|
||||
|
||||
const hits = useMemo(
|
||||
() => filterSettingsSearchCatalog(query, t, { includePlugins, limit: 12 }),
|
||||
[query, t, includePlugins],
|
||||
);
|
||||
const hits = useMemo(() => {
|
||||
void pinyinMatcherVersion;
|
||||
return filterSettingsSearchCatalog(query, t, { includePlugins, limit: 12 });
|
||||
}, [query, t, includePlugins, pinyinMatcherVersion]);
|
||||
|
||||
const collapseSearch = useCallback((restoreFocus = false) => {
|
||||
setExpanded(false);
|
||||
|
||||
@@ -6,6 +6,7 @@
|
||||
*/
|
||||
import { Check, Search, Terminal } from 'lucide-react';
|
||||
import React, { useCallback, useEffect, useMemo, useRef, useState } from 'react';
|
||||
import { usePinyinMatcherVersion } from '../../application/state/usePinyinMatcherVersion';
|
||||
import { matchesWorkspaceHostPickerQuery } from '../../domain/searchMatcher';
|
||||
import { Host } from '../../types';
|
||||
import { DistroAvatar } from '../DistroAvatar';
|
||||
@@ -112,11 +113,13 @@ export const AddToWorkspaceDialog: React.FC<AddToWorkspaceDialogProps> = ({
|
||||
return 'local terminal localhost'.includes(term);
|
||||
}, [query]);
|
||||
|
||||
const pinyinMatcherVersion = usePinyinMatcherVersion();
|
||||
const filteredHosts = useMemo(() => {
|
||||
void pinyinMatcherVersion;
|
||||
const term = query.trim();
|
||||
if (!term) return selectableHosts;
|
||||
return selectableHosts.filter((host) => matchesWorkspaceHostPickerQuery(term, host));
|
||||
}, [selectableHosts, query]);
|
||||
}, [selectableHosts, query, pinyinMatcherVersion]);
|
||||
|
||||
const { items, visualRows, itemIndexToVisualIndex } = useMemo(() => {
|
||||
const list: Item[] = [];
|
||||
|
||||
Reference in new issue
Block a user