mirror of
https://github.com/ItzCrazyKns/Perplexica.git
synced 2025-06-19 16:28:42 +00:00
Compare commits
3 Commits
feat/model
...
33c61333d3
Author | SHA1 | Date | |
---|---|---|---|
33c61333d3 | |||
80ac0c92ba | |||
5ed8fb47aa |
@ -397,6 +397,8 @@ const ChatWindow = ({ id }: { id?: string }) => {
|
||||
|
||||
const [isMessagesLoaded, setIsMessagesLoaded] = useState(false);
|
||||
|
||||
const [pendingRewrite, setPendingRewrite] = useState<{ content: string; messageId: string } | null>(null);
|
||||
|
||||
const [notFound, setNotFound] = useState(false);
|
||||
|
||||
const [isSettingsOpen, setIsSettingsOpen] = useState(false);
|
||||
@ -436,6 +438,12 @@ const ChatWindow = ({ id }: { id?: string }) => {
|
||||
// eslint-disable-next-line react-hooks/exhaustive-deps
|
||||
}, []);
|
||||
|
||||
const chatHistoryRef = useRef<[string, string][]>([]);
|
||||
|
||||
useEffect(() => {
|
||||
chatHistoryRef.current = chatHistory;
|
||||
}, [chatHistory]);
|
||||
|
||||
const messagesRef = useRef<Message[]>([]);
|
||||
|
||||
useEffect(() => {
|
||||
@ -478,7 +486,7 @@ const ChatWindow = ({ id }: { id?: string }) => {
|
||||
files: fileIds,
|
||||
focusMode: focusMode,
|
||||
optimizationMode: optimizationMode,
|
||||
history: [...chatHistory, ['human', message]],
|
||||
history: [...chatHistoryRef.current],
|
||||
}),
|
||||
);
|
||||
|
||||
@ -604,15 +612,22 @@ const ChatWindow = ({ id }: { id?: string }) => {
|
||||
const message = messages[index - 1];
|
||||
|
||||
setMessages((prev) => {
|
||||
return [...prev.slice(0, messages.length > 2 ? index - 1 : 0)];
|
||||
return [...prev.slice(0, messages.length >= 2 ? index - 1 : 0)];
|
||||
});
|
||||
setChatHistory((prev) => {
|
||||
return [...prev.slice(0, messages.length > 2 ? index - 1 : 0)];
|
||||
return [...prev.slice(0, messages.length >= 2 ? index - 1 : 0)];
|
||||
});
|
||||
|
||||
sendMessage(message.content, message.messageId);
|
||||
setPendingRewrite({content: message.content, messageId: message.messageId});
|
||||
};
|
||||
|
||||
useEffect(() => {
|
||||
if (pendingRewrite) {
|
||||
sendMessage(pendingRewrite.content, pendingRewrite.messageId);
|
||||
setPendingRewrite(null);
|
||||
}
|
||||
}, [pendingRewrite]);
|
||||
|
||||
useEffect(() => {
|
||||
if (isReady && initialMessage && ws?.readyState === 1) {
|
||||
sendMessage(initialMessage);
|
||||
|
Reference in New Issue
Block a user