这是indexloc提供的服务,不要输入任何密码
Skip to content
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
22 changes: 13 additions & 9 deletions clients/search-component/src/utils/hooks/modal-context.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -154,9 +154,9 @@ const ModalProvider = ({
...onLoadProps,
});
const [query, setQuery] = useState("");
const [results, setResults] = useState<ChunkWithHighlights[] | GroupChunk[][]>(
[]
);
const [results, setResults] = useState<
ChunkWithHighlights[] | GroupChunk[][]
>([]);
const [requestID, setRequestID] = useState("");
const [loadingResults, setLoadingResults] = useState(false);
const [open, setOpen] = useState(props.open ?? false);
Expand All @@ -165,7 +165,7 @@ const ModalProvider = ({
const modalRef = useRef<HTMLDivElement>(null);
const [tagCounts, setTagCounts] = useState<CountChunkQueryResponseBody[]>([]);
const [currentTag, setCurrentTag] = useState(
props.tags?.find((t) => t.selected)?.tag || "all"
props.tags?.find((t) => t.selected)?.tag || "all",
);

const trieve = new TrieveSDK({
Expand All @@ -188,16 +188,20 @@ const ModalProvider = ({
// Use TAB to alternate modes
useEffect(() => {
const handleKeyDown = (e: KeyboardEvent) => {
if (open && e.key === "Tab") {
e.preventDefault();
if (
open &&
e.ctrlKey &&
e.key === "Tab" &&
props.allowSwitchingModes !== false
) {
setMode((prevMode) => (prevMode === "chat" ? "search" : "chat"));
}
};
window.addEventListener("keydown", handleKeyDown);
return () => {
window.removeEventListener("keydown", handleKeyDown);
};
}, [open]); // Only re-run if open state changes
}, [open, props.allowSwitchingModes]);

const search = async (abortController: AbortController) => {
if (!query) {
Expand Down Expand Up @@ -283,8 +287,8 @@ const ModalProvider = ({
trieve: trieve,
abortController,
...(tag.tag !== "all" && { tag: tag.tag }),
})
)
}),
),
);
setTagCounts(numberOfRecords);
} catch (e) {
Expand Down