mirror of
https://github.com/danny-avila/LibreChat.git
synced 2025-12-17 17:00:15 +01:00
add new reducer to ensure conversations are renewed on model change
This commit is contained in:
parent
30936573ac
commit
0ba92c4c03
7 changed files with 53 additions and 24 deletions
|
|
@ -3,7 +3,7 @@ import TrashIcon from '../svg/TrashIcon';
|
|||
import CrossIcon from '../svg/CrossIcon';
|
||||
import manualSWR from '~/utils/fetchers';
|
||||
import { useDispatch } from 'react-redux';
|
||||
import { setConversation, removeConvo } from '~/store/convoSlice';
|
||||
import { setNewConvo, removeConvo } from '~/store/convoSlice';
|
||||
import { setMessages } from '~/store/messageSlice';
|
||||
|
||||
export default function DeleteButton({ conversationId, renaming, cancelHandler }) {
|
||||
|
|
@ -14,7 +14,8 @@ export default function DeleteButton({ conversationId, renaming, cancelHandler }
|
|||
() => {
|
||||
dispatch(setMessages([]));
|
||||
dispatch(removeConvo(conversationId));
|
||||
dispatch(setConversation({ title: 'New chat', conversationId: null, parentMessageId: null }));
|
||||
// dispatch(setConversation({ title: 'New chat', conversationId: null, parentMessageId: null }));
|
||||
dispatch(setNewConvo());
|
||||
}
|
||||
);
|
||||
|
||||
|
|
|
|||
|
|
@ -2,6 +2,7 @@ import React, { useState, useRef } from 'react';
|
|||
import TextareaAutosize from 'react-textarea-autosize';
|
||||
import { useSelector, useDispatch } from 'react-redux';
|
||||
import { setModel, setCustomGpt } from '~/store/submitSlice';
|
||||
import { setNewConvo } from '~/store/convoSlice';
|
||||
import manualSWR from '~/utils/fetchers';
|
||||
import { Button } from '../ui/Button.tsx';
|
||||
import { Input } from '../ui/Input.tsx';
|
||||
|
|
@ -36,6 +37,16 @@ export default function ModelDialog({ mutate, setModelSave, handleSaveState }) {
|
|||
dispatch(setCustomGpt({ chatGptLabel, promptPrefix }));
|
||||
dispatch(setModel('chatgptCustom'));
|
||||
handleSaveState(chatGptLabel.toLowerCase());
|
||||
// Set new conversation
|
||||
dispatch(setNewConvo());
|
||||
// dispatch(
|
||||
// setConversation({
|
||||
// title: 'New Chat',
|
||||
// error: false,
|
||||
// conversationId: null,
|
||||
// parentMessageId: null
|
||||
// })
|
||||
// );
|
||||
// dispatch(setDisabled(false));
|
||||
};
|
||||
|
||||
|
|
|
|||
|
|
@ -1,7 +1,7 @@
|
|||
import React, { useState, useEffect } from 'react';
|
||||
import { useSelector, useDispatch } from 'react-redux';
|
||||
import { setModel, setDisabled, setCustomGpt, setCustomModel } from '~/store/submitSlice';
|
||||
import { setConversation } from '~/store/convoSlice';
|
||||
import { setNewConvo } from '~/store/convoSlice';
|
||||
import ModelDialog from './ModelDialog';
|
||||
import MenuItems from './MenuItems';
|
||||
import manualSWR from '~/utils/fetchers';
|
||||
|
|
@ -76,14 +76,15 @@ export default function ModelMenu() {
|
|||
}
|
||||
|
||||
// Set new conversation
|
||||
dispatch(
|
||||
setConversation({
|
||||
title: 'New Chat',
|
||||
error: false,
|
||||
conversationId: null,
|
||||
parentMessageId: null
|
||||
})
|
||||
);
|
||||
dispatch(setNewConvo());
|
||||
// dispatch(
|
||||
// setConversation({
|
||||
// title: 'New Chat',
|
||||
// error: false,
|
||||
// conversationId: null,
|
||||
// parentMessageId: null
|
||||
// })
|
||||
// );
|
||||
};
|
||||
|
||||
const onOpenChange = (open) => {
|
||||
|
|
|
|||
|
|
@ -3,7 +3,7 @@ import TrashIcon from '../svg/TrashIcon';
|
|||
import { useSWRConfig } from 'swr';
|
||||
import manualSWR from '~/utils/fetchers';
|
||||
import { useDispatch } from 'react-redux';
|
||||
import { setConversation, removeAll } from '~/store/convoSlice';
|
||||
import { setNewConvo, removeAll } from '~/store/convoSlice';
|
||||
import { setMessages } from '~/store/messageSlice';
|
||||
|
||||
export default function ClearConvos() {
|
||||
|
|
@ -12,14 +12,15 @@ export default function ClearConvos() {
|
|||
|
||||
const { trigger } = manualSWR(`http://localhost:3080/api/convos/clear`, 'post', () => {
|
||||
dispatch(setMessages([]));
|
||||
dispatch(
|
||||
setConversation({
|
||||
error: false,
|
||||
title: 'New chat',
|
||||
conversationId: null,
|
||||
parentMessageId: null
|
||||
})
|
||||
);
|
||||
dispatch(setNewConvo());
|
||||
// dispatch(
|
||||
// setConversation({
|
||||
// error: false,
|
||||
// title: 'New chat',
|
||||
// conversationId: null,
|
||||
// parentMessageId: null
|
||||
// })
|
||||
// );
|
||||
mutate(`http://localhost:3080/api/convos`);
|
||||
});
|
||||
|
||||
|
|
|
|||
|
|
@ -1,6 +1,6 @@
|
|||
import React from 'react';
|
||||
import { useDispatch } from 'react-redux';
|
||||
import { setConversation } from '~/store/convoSlice';
|
||||
import { setNewConvo } from '~/store/convoSlice';
|
||||
import { setMessages } from '~/store/messageSlice';
|
||||
import { setText } from '~/store/textSlice';
|
||||
|
||||
|
|
@ -10,7 +10,8 @@ export default function NewChat() {
|
|||
const clickHandler = () => {
|
||||
dispatch(setText(''));
|
||||
dispatch(setMessages([]));
|
||||
dispatch(setConversation({ title: 'New Chat', error: false, conversationId: null, parentMessageId: null }));
|
||||
dispatch(setNewConvo());
|
||||
// dispatch(setConversation({ title: 'New Chat', error: false, conversationId: null, parentMessageId: null }));
|
||||
};
|
||||
|
||||
return (
|
||||
|
|
|
|||
|
|
@ -29,6 +29,20 @@ const currentSlice = createSlice({
|
|||
incrementPage: (state) => {
|
||||
state.pageNumber = state.pageNumber + 1;
|
||||
},
|
||||
setNewConvo: (state) => {
|
||||
state.error = false;
|
||||
state.title = 'New Chat';
|
||||
state.conversationId = null;
|
||||
state.parentMessageId = null;
|
||||
state.jailbreakConversationId = null;
|
||||
state.conversationSignature = null;
|
||||
state.clientId = null;
|
||||
state.invocationId = null;
|
||||
state.chatGptLabel = null;
|
||||
state.promptPrefix = null;
|
||||
state.convosLoading = false;
|
||||
state.pageNumber = 1;
|
||||
},
|
||||
setConvos: (state, action) => {
|
||||
const newConvos = action.payload.filter((convo) => {
|
||||
return !state.convos.some((c) => c.conversationId === convo.conversationId);
|
||||
|
|
@ -46,7 +60,7 @@ const currentSlice = createSlice({
|
|||
}
|
||||
});
|
||||
|
||||
export const { setConversation, setConvos, setError, incrementPage, removeConvo, removeAll } =
|
||||
export const { setConversation, setConvos, setNewConvo, setError, incrementPage, removeConvo, removeAll } =
|
||||
currentSlice.actions;
|
||||
|
||||
export default currentSlice.reducer;
|
||||
|
|
|
|||
|
|
@ -25,7 +25,7 @@
|
|||
|
||||
p > small {
|
||||
opacity: 0;
|
||||
animation: fadein 2s forwards;
|
||||
animation: fadein 3s forwards;
|
||||
}
|
||||
|
||||
@keyframes fadein {
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue