refactor: migrate ChatInputGroup.tsx from useLLMPreferences hook to jotai atoms

This commit is contained in:
CREDO23 2025-12-10 10:54:41 +00:00
parent ce90672250
commit 1d0be3a640

View file

@ -28,10 +28,10 @@ import {
import { Tooltip, TooltipContent, TooltipProvider, TooltipTrigger } from "@/components/ui/tooltip";
import { getConnectorIcon } from "@/contracts/enums/connectorIcons";
import { Document } from "@/contracts/types/document.types";
import { useLLMPreferences } from "@/hooks/use-llm-configs";
import { useSearchSourceConnectors } from "@/hooks/use-search-source-connectors";
import { useAtomValue } from "jotai";
import { llmConfigsAtom, globalLLMConfigsAtom } from "@/atoms/llm-config/llm-config-query.atoms";
import { llmConfigsAtom, globalLLMConfigsAtom, llmPreferencesAtom } from "@/atoms/llm-config/llm-config-query.atoms";
import { updateLLMPreferencesMutationAtom } from "@/atoms/llm-config/llm-config-mutation.atoms";
const DocumentSelector = React.memo(
({
@ -543,11 +543,10 @@ const LLMSelector = React.memo(() => {
const { data: llmConfigs = [], isFetching: llmLoading, isError: error } = useAtomValue(llmConfigsAtom);
const { data: globalConfigs = [], isFetching: globalConfigsLoading, isError: globalConfigsError } = useAtomValue(globalLLMConfigsAtom);
const {
preferences,
updatePreferences,
loading: preferencesLoading,
} = useLLMPreferences(searchSpaceId);
// Replace useLLMPreferences with jotai atoms
const { data: preferences = {}, isFetching: preferencesLoading } = useAtomValue(llmPreferencesAtom);
const { mutateAsync: updatePreferences } = useAtomValue(updateLLMPreferencesMutationAtom);
const isLoading = llmLoading || preferencesLoading || globalConfigsLoading;
@ -580,9 +579,12 @@ const LLMSelector = React.memo(() => {
const handleValueChange = React.useCallback(
(value: string) => {
const llmId = value ? parseInt(value, 10) : undefined;
updatePreferences({ fast_llm_id: llmId });
updatePreferences({
search_space_id: searchSpaceId,
data: { fast_llm_id: llmId }
});
},
[updatePreferences]
[updatePreferences, searchSpaceId]
);
// Loading skeleton