mirror of
https://github.com/danny-avila/LibreChat.git
synced 2025-12-20 02:10:15 +01:00
fix: convos correctly delete
This commit is contained in:
parent
17c01aa252
commit
f2b092545f
8 changed files with 28 additions and 19 deletions
|
|
@ -10,7 +10,7 @@ const askBing = async ({ text, progressCallback, convo }) => {
|
||||||
// If the above doesn't work, provide all your cookies as a string instead
|
// If the above doesn't work, provide all your cookies as a string instead
|
||||||
// cookies: '',
|
// cookies: '',
|
||||||
debug: false,
|
debug: false,
|
||||||
store: new KeyvFile({ filename: './api/data/cache.json' })
|
store: new KeyvFile({ filename: './data/cache.json' })
|
||||||
});
|
});
|
||||||
|
|
||||||
let options = {
|
let options = {
|
||||||
|
|
|
||||||
|
|
@ -12,7 +12,7 @@ const browserClient = async ({ text, progressCallback, convo }) => {
|
||||||
const { ChatGPTBrowserClient } = await import('@waylaidwanderer/chatgpt-api');
|
const { ChatGPTBrowserClient } = await import('@waylaidwanderer/chatgpt-api');
|
||||||
|
|
||||||
const store = {
|
const store = {
|
||||||
store: new KeyvFile({ filename: './api/data/cache.json' })
|
store: new KeyvFile({ filename: './data/cache.json' })
|
||||||
};
|
};
|
||||||
|
|
||||||
const client = new ChatGPTBrowserClient(clientOptions, store);
|
const client = new ChatGPTBrowserClient(clientOptions, store);
|
||||||
|
|
|
||||||
|
|
@ -11,7 +11,7 @@ const clientOptions = {
|
||||||
const askClient = async ({ text, progressCallback, convo }) => {
|
const askClient = async ({ text, progressCallback, convo }) => {
|
||||||
const ChatGPTClient = (await import('@waylaidwanderer/chatgpt-api')).default;
|
const ChatGPTClient = (await import('@waylaidwanderer/chatgpt-api')).default;
|
||||||
const store = {
|
const store = {
|
||||||
store: new KeyvFile({ filename: './api/data/cache.json' })
|
store: new KeyvFile({ filename: './data/cache.json' })
|
||||||
};
|
};
|
||||||
|
|
||||||
const client = new ChatGPTClient(process.env.OPENAI_KEY, clientOptions, store);
|
const client = new ChatGPTClient(process.env.OPENAI_KEY, clientOptions, store);
|
||||||
|
|
|
||||||
|
|
@ -11,7 +11,7 @@ const clientOptions = {
|
||||||
const customClient = async ({ text, progressCallback, convo, promptPrefix, chatGptLabel }) => {
|
const customClient = async ({ text, progressCallback, convo, promptPrefix, chatGptLabel }) => {
|
||||||
const ChatGPTClient = (await import('@waylaidwanderer/chatgpt-api')).default;
|
const ChatGPTClient = (await import('@waylaidwanderer/chatgpt-api')).default;
|
||||||
const store = {
|
const store = {
|
||||||
store: new KeyvFile({ filename: './api/data/cache.json' })
|
store: new KeyvFile({ filename: './data/cache.json' })
|
||||||
};
|
};
|
||||||
|
|
||||||
clientOptions.chatGptLabel = chatGptLabel;
|
clientOptions.chatGptLabel = chatGptLabel;
|
||||||
|
|
|
||||||
|
|
@ -16,7 +16,7 @@ export default function Conversation({
|
||||||
title = 'New conversation',
|
title = 'New conversation',
|
||||||
bingData,
|
bingData,
|
||||||
chatGptLabel = null,
|
chatGptLabel = null,
|
||||||
promptPrefix = null
|
promptPrefix = null,
|
||||||
}) {
|
}) {
|
||||||
const [renaming, setRenaming] = useState(false);
|
const [renaming, setRenaming] = useState(false);
|
||||||
const [titleInput, setTitleInput] = useState(title);
|
const [titleInput, setTitleInput] = useState(title);
|
||||||
|
|
@ -97,7 +97,7 @@ export default function Conversation({
|
||||||
rename.trigger({ conversationId, title: titleInput });
|
rename.trigger({ conversationId, title: titleInput });
|
||||||
};
|
};
|
||||||
|
|
||||||
const handleKeyPress = (e) => {
|
const handleKeyDown = (e) => {
|
||||||
if (e.key === 'Enter') {
|
if (e.key === 'Enter') {
|
||||||
onRename(e);
|
onRename(e);
|
||||||
}
|
}
|
||||||
|
|
@ -128,7 +128,7 @@ export default function Conversation({
|
||||||
value={titleInput}
|
value={titleInput}
|
||||||
onChange={(e) => setTitleInput(e.target.value)}
|
onChange={(e) => setTitleInput(e.target.value)}
|
||||||
onBlur={onRename}
|
onBlur={onRename}
|
||||||
onKeyPress={handleKeyPress}
|
onKeyDown={handleKeyDown}
|
||||||
/>
|
/>
|
||||||
) : (
|
) : (
|
||||||
titleInput
|
titleInput
|
||||||
|
|
|
||||||
|
|
@ -3,7 +3,7 @@ import TrashIcon from '../svg/TrashIcon';
|
||||||
import CrossIcon from '../svg/CrossIcon';
|
import CrossIcon from '../svg/CrossIcon';
|
||||||
import manualSWR from '~/utils/fetchers';
|
import manualSWR from '~/utils/fetchers';
|
||||||
import { useDispatch } from 'react-redux';
|
import { useDispatch } from 'react-redux';
|
||||||
import { setConversation } from '~/store/convoSlice';
|
import { setConversation, removeConvo } from '~/store/convoSlice';
|
||||||
import { setMessages } from '~/store/messageSlice';
|
import { setMessages } from '~/store/messageSlice';
|
||||||
|
|
||||||
export default function DeleteButton({ conversationId, renaming, cancelHandler }) {
|
export default function DeleteButton({ conversationId, renaming, cancelHandler }) {
|
||||||
|
|
@ -13,6 +13,7 @@ export default function DeleteButton({ conversationId, renaming, cancelHandler }
|
||||||
'post',
|
'post',
|
||||||
() => {
|
() => {
|
||||||
dispatch(setMessages([]));
|
dispatch(setMessages([]));
|
||||||
|
dispatch(removeConvo(conversationId));
|
||||||
dispatch(setConversation({ title: 'New chat', conversationId: null, parentMessageId: null }));
|
dispatch(setConversation({ title: 'New chat', conversationId: null, parentMessageId: null }));
|
||||||
}
|
}
|
||||||
);
|
);
|
||||||
|
|
|
||||||
|
|
@ -17,17 +17,20 @@ export default function Nav() {
|
||||||
};
|
};
|
||||||
|
|
||||||
const { data, isLoading, mutate } = swr(
|
const { data, isLoading, mutate } = swr(
|
||||||
`http://localhost:3080/api/convos?pageNumber=${pageNumber}`
|
`http://localhost:3080/api/convos?pageNumber=${pageNumber}`,
|
||||||
, onSuccess);
|
onSuccess
|
||||||
|
);
|
||||||
const containerRef = useRef(null);
|
const containerRef = useRef(null);
|
||||||
const scrollPositionRef = useRef(null);
|
const scrollPositionRef = useRef(null);
|
||||||
|
|
||||||
const showMore = async () => {
|
const showMore = async (increment = true) => {
|
||||||
|
if (increment) {
|
||||||
const container = containerRef.current;
|
const container = containerRef.current;
|
||||||
if (container) {
|
if (container) {
|
||||||
scrollPositionRef.current = container.scrollTop;
|
scrollPositionRef.current = container.scrollTop;
|
||||||
}
|
}
|
||||||
dispatch(incrementPage());
|
dispatch(incrementPage());
|
||||||
|
}
|
||||||
await mutate();
|
await mutate();
|
||||||
};
|
};
|
||||||
|
|
||||||
|
|
@ -44,7 +47,8 @@ export default function Nav() {
|
||||||
}
|
}
|
||||||
}, [data]);
|
}, [data]);
|
||||||
|
|
||||||
const containerClasses = isLoading && pageNumber === 1
|
const containerClasses =
|
||||||
|
isLoading && pageNumber === 1
|
||||||
? 'flex flex-col gap-2 text-gray-100 text-sm h-full justify-center items-center'
|
? 'flex flex-col gap-2 text-gray-100 text-sm h-full justify-center items-center'
|
||||||
: 'flex flex-col gap-2 text-gray-100 text-sm';
|
: 'flex flex-col gap-2 text-gray-100 text-sm';
|
||||||
|
|
||||||
|
|
|
||||||
|
|
@ -35,10 +35,14 @@ const currentSlice = createSlice({
|
||||||
state.convos = [...state.convos, ...newConvos].sort(
|
state.convos = [...state.convos, ...newConvos].sort(
|
||||||
(a, b) => new Date(b.created) - new Date(a.created)
|
(a, b) => new Date(b.created) - new Date(a.created)
|
||||||
);
|
);
|
||||||
|
},
|
||||||
|
removeConvo: (state, action) => {
|
||||||
|
state.convos = state.convos.filter((convo) => convo.conversationId !== action.payload);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
|
|
||||||
export const { setConversation, setConvos, setError, incrementPage } = currentSlice.actions;
|
export const { setConversation, setConvos, setError, incrementPage, removeConvo } =
|
||||||
|
currentSlice.actions;
|
||||||
|
|
||||||
export default currentSlice.reducer;
|
export default currentSlice.reducer;
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue