mirror of
https://github.com/ItzCrazyKns/Perplexica.git
synced 2026-01-03 01:56:56 +00:00
feat(chat-hook): prevent duplicate blocks
This commit is contained in:
@@ -570,6 +570,20 @@ export const ChatProvider = ({ children }: { children: React.ReactNode }) => {
|
|||||||
setMessages((prev) =>
|
setMessages((prev) =>
|
||||||
prev.map((msg) => {
|
prev.map((msg) => {
|
||||||
if (msg.messageId === messageId) {
|
if (msg.messageId === messageId) {
|
||||||
|
const exists = msg.responseBlocks.findIndex(
|
||||||
|
(b) => b.id === data.block.id,
|
||||||
|
);
|
||||||
|
|
||||||
|
if (exists !== -1) {
|
||||||
|
const existingBlocks = [...msg.responseBlocks];
|
||||||
|
existingBlocks[exists] = data.block;
|
||||||
|
|
||||||
|
return {
|
||||||
|
...msg,
|
||||||
|
responseBlocks: existingBlocks,
|
||||||
|
};
|
||||||
|
}
|
||||||
|
|
||||||
return {
|
return {
|
||||||
...msg,
|
...msg,
|
||||||
responseBlocks: [...msg.responseBlocks, data.block],
|
responseBlocks: [...msg.responseBlocks, data.block],
|
||||||
|
|||||||
Reference in New Issue
Block a user