mirror of
https://github.com/danny-avila/LibreChat.git
synced 2025-12-17 00:40:14 +01:00
🐞 fix: Prevent Type Error in Successful Bookmark Deletion (#9014)
This commit is contained in:
parent
4799593e1a
commit
9dbf153489
1 changed files with 39 additions and 25 deletions
|
|
@ -388,43 +388,57 @@ export const useDeleteTagInConversations = () => {
|
||||||
QueryKeys.allConversations,
|
QueryKeys.allConversations,
|
||||||
]);
|
]);
|
||||||
|
|
||||||
|
// If there is no conversations cache yet, nothing to update
|
||||||
|
if (!data || !Array.isArray(data.pages) || data.pages.length === 0) {
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
const conversationIdsWithTag: string[] = [];
|
const conversationIdsWithTag: string[] = [];
|
||||||
|
|
||||||
// Remove deleted tag from conversations
|
// Create an updated copy of the infinite query data without mutating the cache directly
|
||||||
const newData = JSON.parse(JSON.stringify(data)) as InfiniteData<ConversationListResponse>;
|
const updatedData: InfiniteData<ConversationListResponse> = {
|
||||||
for (let pageIndex = 0; pageIndex < newData.pages.length; pageIndex++) {
|
pageParams: Array.isArray(data.pageParams) ? [...data.pageParams] : [],
|
||||||
const page = newData.pages[pageIndex];
|
pages: data.pages.map((page) => ({
|
||||||
page.conversations = page.conversations.map((conversation) => {
|
...page,
|
||||||
if (
|
conversations: page.conversations.map((conversation) => {
|
||||||
conversation.conversationId &&
|
if (
|
||||||
'tags' in conversation &&
|
conversation.conversationId &&
|
||||||
Array.isArray(conversation.tags) &&
|
'tags' in conversation &&
|
||||||
conversation.tags.includes(deletedTag)
|
Array.isArray((conversation as unknown as { tags?: string[] }).tags) &&
|
||||||
) {
|
(conversation as unknown as { tags: string[] }).tags.includes(deletedTag)
|
||||||
conversationIdsWithTag.push(conversation.conversationId);
|
) {
|
||||||
conversation.tags = conversation.tags.filter((tag: string) => tag !== deletedTag);
|
conversationIdsWithTag.push(conversation.conversationId);
|
||||||
}
|
return {
|
||||||
return conversation;
|
...conversation,
|
||||||
});
|
tags: (conversation as unknown as { tags: string[] }).tags.filter(
|
||||||
}
|
(tag: string) => tag !== deletedTag,
|
||||||
|
),
|
||||||
|
} as t.TConversation;
|
||||||
|
}
|
||||||
|
return conversation as t.TConversation;
|
||||||
|
}),
|
||||||
|
})),
|
||||||
|
};
|
||||||
|
|
||||||
queryClient.setQueryData<InfiniteData<ConversationListResponse>>(
|
queryClient.setQueryData<InfiniteData<ConversationListResponse>>(
|
||||||
[QueryKeys.allConversations],
|
[QueryKeys.allConversations],
|
||||||
newData,
|
updatedData,
|
||||||
);
|
);
|
||||||
|
|
||||||
// Remove the deleted tag from the cache of each conversation
|
// Remove the deleted tag from the cache of each individual conversation
|
||||||
for (let i = 0; i < conversationIdsWithTag.length; i++) {
|
for (let i = 0; i < conversationIdsWithTag.length; i++) {
|
||||||
const conversationId = conversationIdsWithTag[i];
|
const conversationId = conversationIdsWithTag[i];
|
||||||
const conversationData = queryClient.getQueryData<t.TConversation>([
|
const conversationData = queryClient.getQueryData<t.TConversation>([
|
||||||
QueryKeys.conversation,
|
QueryKeys.conversation,
|
||||||
conversationId,
|
conversationId,
|
||||||
]);
|
]);
|
||||||
if (conversationData && 'tags' in conversationData && Array.isArray(conversationData.tags)) {
|
if (conversationData && Array.isArray((conversationData as { tags?: string[] }).tags)) {
|
||||||
conversationData.tags = conversationData.tags.filter((tag: string) => tag !== deletedTag);
|
queryClient.setQueryData<t.TConversation>([QueryKeys.conversation, conversationId], {
|
||||||
queryClient.setQueryData<t.TConversation>(
|
...conversationData,
|
||||||
[QueryKeys.conversation, conversationId],
|
tags: (conversationData as { tags: string[] }).tags.filter(
|
||||||
conversationData,
|
(tag: string) => tag !== deletedTag,
|
||||||
);
|
),
|
||||||
|
});
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue