From 766657da83dbb8247af9661fa792364b933d6875 Mon Sep 17 00:00:00 2001 From: Danny Avila Date: Sat, 4 Jan 2025 12:01:13 -0500 Subject: [PATCH] =?UTF-8?q?=F0=9F=94=96=20fix:=20Remove=20Local=20State=20?= =?UTF-8?q?from=20Bookmark=20Menu=20(#5181)?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit * chore: remove redundant * fix: bookmark menu statefulness by removing local state --- .../components/Chat/Input/HeaderOptions.tsx | 4 +-- .../components/Chat/Menus/BookmarkMenu.tsx | 32 ++++++++++--------- .../components/SidePanel/Parameters/Panel.tsx | 4 +-- client/src/components/ui/DropdownPopup.tsx | 4 ++- packages/data-provider/src/schemas.ts | 6 ---- 5 files changed, 24 insertions(+), 26 deletions(-) diff --git a/client/src/components/Chat/Input/HeaderOptions.tsx b/client/src/components/Chat/Input/HeaderOptions.tsx index 1696dd63e37..3a7749c181e 100644 --- a/client/src/components/Chat/Input/HeaderOptions.tsx +++ b/client/src/components/Chat/Input/HeaderOptions.tsx @@ -2,7 +2,7 @@ import { useRecoilState } from 'recoil'; import { Settings2 } from 'lucide-react'; import { Root, Anchor } from '@radix-ui/react-popover'; import { useState, useEffect, useMemo } from 'react'; -import { tPresetUpdateSchema, EModelEndpoint, isParamEndpoint } from 'librechat-data-provider'; +import { tConvoUpdateSchema, EModelEndpoint, isParamEndpoint } from 'librechat-data-provider'; import type { TPreset, TInterfaceConfig } from 'librechat-data-provider'; import { EndpointSettings, SaveAsPresetDialog, AlternativeSettings } from '~/components/Endpoints'; import { PluginStoreDialog, TooltipAnchor } from '~/components'; @@ -123,7 +123,7 @@ export default function HeaderOptions({ open={saveAsDialogShow} onOpenChange={setSaveAsDialogShow} preset={ - tPresetUpdateSchema.parse({ + tConvoUpdateSchema.parse({ ...conversation, }) as TPreset } diff --git a/client/src/components/Chat/Menus/BookmarkMenu.tsx b/client/src/components/Chat/Menus/BookmarkMenu.tsx index c0d626de942..f4b804f5e86 100644 --- a/client/src/components/Chat/Menus/BookmarkMenu.tsx +++ b/client/src/components/Chat/Menus/BookmarkMenu.tsx @@ -27,15 +27,14 @@ const BookmarkMenu: FC = () => { const conversation = useRecoilValue(store.conversationByIndex(0)) || undefined; const conversationId = conversation?.conversationId ?? ''; const updateConvoTags = useBookmarkSuccess(conversationId); + const tags = conversation?.tags; const menuId = useId(); const [isMenuOpen, setIsMenuOpen] = useState(false); const [isDialogOpen, setIsDialogOpen] = useState(false); - const [tags, setTags] = useState(conversation?.tags || []); const mutation = useTagConversationMutation(conversationId, { onSuccess: (newTags: string[], vars) => { - setTags(newTags); updateConvoTags(newTags); const tagElement = document.getElementById(vars.tag); console.log('tagElement', tagElement); @@ -82,12 +81,13 @@ const BookmarkMenu: FC = () => { const allTags = queryClient.getQueryData([QueryKeys.conversationTags]) ?? []; const existingTags = allTags.map((t) => t.tag); - const filteredTags = tags.filter((t) => existingTags.includes(t)); + const filteredTags = tags?.filter((t) => existingTags.includes(t)); logger.log('tag_mutation', 'BookmarkMenu - handleSubmit: tags after filtering', filteredTags); - const newTags = filteredTags.includes(tag) - ? filteredTags.filter((t) => t !== tag) - : [...filteredTags, tag]; + const newTags = + filteredTags?.includes(tag) === true + ? filteredTags.filter((t) => t !== tag) + : [...(filteredTags ?? []), tag]; logger.log('tag_mutation', 'BookmarkMenu - handleSubmit: tags after', newTags); mutation.mutate({ @@ -115,16 +115,17 @@ const BookmarkMenu: FC = () => { if (data) { for (const tag of data) { - const isSelected = tags.includes(tag.tag); + const isSelected = tags?.includes(tag.tag); items.push({ id: tag.tag, - hideOnClick: false, label: tag.tag, - icon: isSelected ? ( - - ) : ( - - ), + hideOnClick: false, + icon: + isSelected === true ? ( + + ) : ( + + ), onClick: () => handleSubmit(tag.tag), disabled: mutation.isLoading, }); @@ -142,7 +143,7 @@ const BookmarkMenu: FC = () => { if (mutation.isLoading) { return ; } - if (tags.length > 0) { + if ((tags?.length ?? 0) > 0) { return ; } return ; @@ -155,6 +156,7 @@ const BookmarkMenu: FC = () => { menuId={menuId} isOpen={isMenuOpen} setIsOpen={setIsMenuOpen} + keyPrefix={`${conversationId}-bookmark-`} trigger={ { /> { - const newPreset = tPresetUpdateSchema.parse({ + const newPreset = tConvoUpdateSchema.parse({ ...conversation, }) as TPreset; setPreset(newPreset); diff --git a/client/src/components/ui/DropdownPopup.tsx b/client/src/components/ui/DropdownPopup.tsx index 788e3be32d8..8645d597364 100644 --- a/client/src/components/ui/DropdownPopup.tsx +++ b/client/src/components/ui/DropdownPopup.tsx @@ -4,6 +4,7 @@ import type * as t from '~/common'; import { cn } from '~/utils'; interface DropdownProps { + keyPrefix?: string; trigger: React.ReactNode; items: t.MenuItemProps[]; isOpen: boolean; @@ -20,6 +21,7 @@ interface DropdownProps { } const DropdownPopup: React.FC = ({ + keyPrefix, trigger, items, isOpen, @@ -53,7 +55,7 @@ const DropdownPopup: React.FC = ({ } return ( ; export type TSetOption = (