MCPcopy Create free account
hub / github.com/triggerdotdev/jsonhero-web / SearchPalette

Function SearchPalette

app/components/SearchPalette.tsx:30–210  ·  view source on GitHub ↗
({
  onSelect,
  onClose,
}: {
  onSelect?: (entry: string) => void;
  onClose?: () => void;
})

Source from the content-addressed store, hash-verified

28import { Match } from "@jsonhero/fuzzy-json-search/lib/fuzzyScoring";
29
30export function SearchPalette({
31 onSelect,
32 onClose,
33}: {
34 onSelect?: (entry: string) => void;
35 onClose?: () => void;
36}) {
37 const searchState = useJsonSearchState();
38 const searchApi = useJsonSearchApi();
39
40 useHotkeys(
41 "esc",
42 (e) => {
43 e.preventDefault();
44 searchApi.reset();
45 onClose?.();
46 },
47 [onClose]
48 );
49
50 const listRef = useRef<HTMLElement>(null);
51
52 const rowVirtualizer = useVirtual({
53 size: (searchState.results ?? []).length,
54 parentRef: listRef,
55 estimateSize: useCallback(() => 70, []),
56 overscan: 6,
57 });
58
59 function comboboxReducer(
60 state: UseComboboxState<SearchResult<string>>,
61 actionAndChanges: UseComboboxStateChangeOptions<SearchResult<string>>
62 ): Partial<UseComboboxState<SearchResult<string>>> {
63 const { changes, ...action } = actionAndChanges;
64
65 // Don't update the input field when selecting an item
66 switch (action.type) {
67 case useCombobox.stateChangeTypes.ItemClick:
68 case useCombobox.stateChangeTypes.InputKeyDownEnter: {
69 return {
70 ...changes,
71 inputValue: state.inputValue,
72 };
73 }
74 default:
75 return changes;
76 }
77 }
78
79 const cb = useCombobox({
80 items: searchState.results ?? [],
81 stateReducer: comboboxReducer,
82 circularNavigation: false,
83 scrollIntoView: () => {},
84 onSelectedItemChange: ({ selectedItem }) => {
85 if (selectedItem) {
86 onSelect?.(selectedItem.item);
87 searchApi.reset();

Callers

nothing calls this directly

Calls 2

useJsonSearchStateFunction · 0.90
useJsonSearchApiFunction · 0.90

Tested by

no test coverage detected