mirror of
https://github.com/danny-avila/LibreChat.git
synced 2025-12-19 18:00:15 +01:00
🚧 refactor: Attempt Default Preset Fix & Other Changes (#2342)
* fix(useTextarea): trigger SendButton re-render on undo and clearing text * refactor(PresetItems): show pin icon for default preset * fix(ChatRoute): do not use conversation.model for useEffect, do not set default Preset if real model list is not yet fetched
This commit is contained in:
parent
476767355b
commit
334b603247
4 changed files with 23 additions and 15 deletions
|
|
@ -2,9 +2,9 @@ import filenamify from 'filenamify';
|
|||
import exportFromJSON from 'export-from-json';
|
||||
import { useCallback, useEffect, useRef } from 'react';
|
||||
import { useQueryClient } from '@tanstack/react-query';
|
||||
import { QueryKeys, modularEndpoints, EModelEndpoint } from 'librechat-data-provider';
|
||||
import { useRecoilState, useSetRecoilState, useRecoilValue } from 'recoil';
|
||||
import { useCreatePresetMutation } from 'librechat-data-provider/react-query';
|
||||
import { QueryKeys, modularEndpoints, EModelEndpoint } from 'librechat-data-provider';
|
||||
import { useCreatePresetMutation, useGetModelsQuery } from 'librechat-data-provider/react-query';
|
||||
import type { TPreset, TEndpointsConfig } from 'librechat-data-provider';
|
||||
import {
|
||||
useUpdatePresetMutation,
|
||||
|
|
@ -17,6 +17,7 @@ import useDefaultConvo from '~/hooks/useDefaultConvo';
|
|||
import { useAuthContext } from '~/hooks/AuthContext';
|
||||
import { NotificationSeverity } from '~/common';
|
||||
import useLocalize from '~/hooks/useLocalize';
|
||||
import useNewConvo from '~/hooks/useNewConvo';
|
||||
import store from '~/store';
|
||||
|
||||
export default function usePresets() {
|
||||
|
|
@ -27,12 +28,18 @@ export default function usePresets() {
|
|||
const { user, isAuthenticated } = useAuthContext();
|
||||
|
||||
const modularChat = useRecoilValue(store.modularChat);
|
||||
const [_defaultPreset, setDefaultPreset] = useRecoilState(store.defaultPreset);
|
||||
const setPresetModalVisible = useSetRecoilState(store.presetModalVisible);
|
||||
const { preset, conversation, newConversation, setPreset } = useChatContext();
|
||||
const [_defaultPreset, setDefaultPreset] = useRecoilState(store.defaultPreset);
|
||||
const presetsQuery = useGetPresetsQuery({ enabled: !!user && isAuthenticated });
|
||||
const { preset, conversation, index, setPreset } = useChatContext();
|
||||
const { data: modelsData } = useGetModelsQuery();
|
||||
const { newConversation } = useNewConvo(index);
|
||||
|
||||
useEffect(() => {
|
||||
if (modelsData?.initial) {
|
||||
return;
|
||||
}
|
||||
|
||||
const { data: presets } = presetsQuery;
|
||||
if (_defaultPreset || !presets || hasLoaded.current) {
|
||||
return;
|
||||
|
|
@ -50,12 +57,12 @@ export default function usePresets() {
|
|||
}
|
||||
setDefaultPreset(defaultPreset);
|
||||
if (!conversation?.conversationId || conversation.conversationId === 'new') {
|
||||
newConversation({ preset: defaultPreset });
|
||||
newConversation({ preset: defaultPreset, modelsData });
|
||||
}
|
||||
hasLoaded.current = true;
|
||||
// dependencies are stable and only needed once
|
||||
// eslint-disable-next-line react-hooks/exhaustive-deps
|
||||
}, [presetsQuery.data, user]);
|
||||
}, [presetsQuery.data, user, modelsData]);
|
||||
|
||||
const setPresets = useCallback(
|
||||
(presets: TPreset[]) => {
|
||||
|
|
|
|||
|
|
@ -160,9 +160,11 @@ export default function useTextarea({
|
|||
const isUndo = e.key === 'z' && (e.ctrlKey || e.metaKey);
|
||||
if (isUndo && target.value.trim() === '') {
|
||||
textAreaRef.current?.setRangeText('', 0, textAreaRef.current?.value?.length, 'end');
|
||||
setValue('text', '', { shouldValidate: true });
|
||||
forceResize(textAreaRef);
|
||||
} else if (isUndo) {
|
||||
trimUndoneRange(textAreaRef);
|
||||
setValue('text', '', { shouldValidate: true });
|
||||
forceResize(textAreaRef);
|
||||
}
|
||||
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue