mirror of
https://github.com/danny-avila/LibreChat.git
synced 2025-12-20 02:10:15 +01:00
🔖 fix: Agent Marketplace Bookmark and New Chat buttons (#9549)
* don't require conversation for bookmark button * wrap marketplace component so it can correctly use context hooks * chore: re-order import statement for MarketplaceProvider --------- Co-authored-by: Danny Avila <danacordially@gmail.com>
This commit is contained in:
parent
04c3a5a861
commit
31445e391a
4 changed files with 203 additions and 214 deletions
|
|
@ -11,7 +11,6 @@ import { useDocumentTitle, useHasAccess, useLocalize, TranslationKeys } from '~/
|
||||||
import { useGetEndpointsQuery, useGetAgentCategoriesQuery } from '~/data-provider';
|
import { useGetEndpointsQuery, useGetAgentCategoriesQuery } from '~/data-provider';
|
||||||
import MarketplaceAdminSettings from './MarketplaceAdminSettings';
|
import MarketplaceAdminSettings from './MarketplaceAdminSettings';
|
||||||
import { SidePanelProvider, useChatContext } from '~/Providers';
|
import { SidePanelProvider, useChatContext } from '~/Providers';
|
||||||
import { MarketplaceProvider } from './MarketplaceContext';
|
|
||||||
import { SidePanelGroup } from '~/components/SidePanel';
|
import { SidePanelGroup } from '~/components/SidePanel';
|
||||||
import { OpenSidebar } from '~/components/Chat/Menus';
|
import { OpenSidebar } from '~/components/Chat/Menus';
|
||||||
import CategoryTabs from './CategoryTabs';
|
import CategoryTabs from './CategoryTabs';
|
||||||
|
|
@ -272,7 +271,6 @@ const AgentMarketplace: React.FC<AgentMarketplaceProps> = ({ className = '' }) =
|
||||||
}
|
}
|
||||||
return (
|
return (
|
||||||
<div className={`relative flex w-full grow overflow-hidden bg-presentation ${className}`}>
|
<div className={`relative flex w-full grow overflow-hidden bg-presentation ${className}`}>
|
||||||
<MarketplaceProvider>
|
|
||||||
<SidePanelProvider>
|
<SidePanelProvider>
|
||||||
<SidePanelGroup
|
<SidePanelGroup
|
||||||
defaultLayout={defaultLayout}
|
defaultLayout={defaultLayout}
|
||||||
|
|
@ -404,8 +402,7 @@ const AgentMarketplace: React.FC<AgentMarketplaceProps> = ({ className = '' }) =
|
||||||
// Fallback for unknown categories
|
// Fallback for unknown categories
|
||||||
return {
|
return {
|
||||||
name:
|
name:
|
||||||
displayCategory.charAt(0).toUpperCase() +
|
displayCategory.charAt(0).toUpperCase() + displayCategory.slice(1),
|
||||||
displayCategory.slice(1),
|
|
||||||
description: '',
|
description: '',
|
||||||
};
|
};
|
||||||
};
|
};
|
||||||
|
|
@ -475,9 +472,7 @@ const AgentMarketplace: React.FC<AgentMarketplaceProps> = ({ className = '' }) =
|
||||||
: categoryData.label,
|
: categoryData.label,
|
||||||
description: categoryData.description?.startsWith('com_')
|
description: categoryData.description?.startsWith('com_')
|
||||||
? localize(
|
? localize(
|
||||||
categoryData.description as Parameters<
|
categoryData.description as Parameters<typeof localize>[0],
|
||||||
typeof localize
|
|
||||||
>[0],
|
|
||||||
)
|
)
|
||||||
: categoryData.description || '',
|
: categoryData.description || '',
|
||||||
};
|
};
|
||||||
|
|
@ -532,7 +527,6 @@ const AgentMarketplace: React.FC<AgentMarketplaceProps> = ({ className = '' }) =
|
||||||
</main>
|
</main>
|
||||||
</SidePanelGroup>
|
</SidePanelGroup>
|
||||||
</SidePanelProvider>
|
</SidePanelProvider>
|
||||||
</MarketplaceProvider>
|
|
||||||
</div>
|
</div>
|
||||||
);
|
);
|
||||||
};
|
};
|
||||||
|
|
|
||||||
|
|
@ -1,6 +1,5 @@
|
||||||
import { useMemo } from 'react';
|
import { useMemo } from 'react';
|
||||||
import type { FC } from 'react';
|
import type { FC } from 'react';
|
||||||
import { useRecoilValue } from 'recoil';
|
|
||||||
import { TooltipAnchor } from '@librechat/client';
|
import { TooltipAnchor } from '@librechat/client';
|
||||||
import { Menu, MenuButton, MenuItems } from '@headlessui/react';
|
import { Menu, MenuButton, MenuItems } from '@headlessui/react';
|
||||||
import { BookmarkFilledIcon, BookmarkIcon } from '@radix-ui/react-icons';
|
import { BookmarkFilledIcon, BookmarkIcon } from '@radix-ui/react-icons';
|
||||||
|
|
@ -9,7 +8,6 @@ import { useGetConversationTags } from '~/data-provider';
|
||||||
import BookmarkNavItems from './BookmarkNavItems';
|
import BookmarkNavItems from './BookmarkNavItems';
|
||||||
import { useLocalize } from '~/hooks';
|
import { useLocalize } from '~/hooks';
|
||||||
import { cn } from '~/utils';
|
import { cn } from '~/utils';
|
||||||
import store from '~/store';
|
|
||||||
|
|
||||||
type BookmarkNavProps = {
|
type BookmarkNavProps = {
|
||||||
tags: string[];
|
tags: string[];
|
||||||
|
|
@ -20,7 +18,6 @@ type BookmarkNavProps = {
|
||||||
const BookmarkNav: FC<BookmarkNavProps> = ({ tags, setTags, isSmallScreen }: BookmarkNavProps) => {
|
const BookmarkNav: FC<BookmarkNavProps> = ({ tags, setTags, isSmallScreen }: BookmarkNavProps) => {
|
||||||
const localize = useLocalize();
|
const localize = useLocalize();
|
||||||
const { data } = useGetConversationTags();
|
const { data } = useGetConversationTags();
|
||||||
const conversation = useRecoilValue(store.conversationByIndex(0));
|
|
||||||
const label = useMemo(
|
const label = useMemo(
|
||||||
() => (tags.length > 0 ? tags.join(', ') : localize('com_ui_bookmarks')),
|
() => (tags.length > 0 ? tags.join(', ') : localize('com_ui_bookmarks')),
|
||||||
[tags, localize],
|
[tags, localize],
|
||||||
|
|
@ -56,11 +53,9 @@ const BookmarkNav: FC<BookmarkNavProps> = ({ tags, setTags, isSmallScreen }: Boo
|
||||||
anchor="bottom"
|
anchor="bottom"
|
||||||
className="absolute left-0 top-full z-[100] mt-1 w-60 translate-y-0 overflow-hidden rounded-lg bg-surface-secondary p-1.5 shadow-lg outline-none"
|
className="absolute left-0 top-full z-[100] mt-1 w-60 translate-y-0 overflow-hidden rounded-lg bg-surface-secondary p-1.5 shadow-lg outline-none"
|
||||||
>
|
>
|
||||||
{data && conversation && (
|
{data && (
|
||||||
<BookmarkContext.Provider value={{ bookmarks: data.filter((tag) => tag.count > 0) }}>
|
<BookmarkContext.Provider value={{ bookmarks: data.filter((tag) => tag.count > 0) }}>
|
||||||
<BookmarkNavItems
|
<BookmarkNavItems
|
||||||
// Currently selected conversation
|
|
||||||
conversation={conversation}
|
|
||||||
// List of selected tags(string)
|
// List of selected tags(string)
|
||||||
tags={tags}
|
tags={tags}
|
||||||
// When a user selects a tag, this `setTags` function is called to refetch the list of conversations for the selected tag
|
// When a user selects a tag, this `setTags` function is called to refetch the list of conversations for the selected tag
|
||||||
|
|
|
||||||
|
|
@ -1,25 +1,16 @@
|
||||||
import { useEffect, useState, type FC } from 'react';
|
import { type FC } from 'react';
|
||||||
import { CrossCircledIcon } from '@radix-ui/react-icons';
|
import { CrossCircledIcon } from '@radix-ui/react-icons';
|
||||||
import type { TConversation } from 'librechat-data-provider';
|
|
||||||
import { useBookmarkContext } from '~/Providers/BookmarkContext';
|
import { useBookmarkContext } from '~/Providers/BookmarkContext';
|
||||||
import { BookmarkItems, BookmarkItem } from '~/components/Bookmarks';
|
import { BookmarkItems, BookmarkItem } from '~/components/Bookmarks';
|
||||||
import { useLocalize } from '~/hooks';
|
import { useLocalize } from '~/hooks';
|
||||||
|
|
||||||
const BookmarkNavItems: FC<{
|
const BookmarkNavItems: FC<{
|
||||||
conversation: TConversation;
|
|
||||||
tags: string[];
|
tags: string[];
|
||||||
setTags: (tags: string[]) => void;
|
setTags: (tags: string[]) => void;
|
||||||
}> = ({ conversation, tags = [], setTags }) => {
|
}> = ({ tags = [], setTags }) => {
|
||||||
const [currentConversation, setCurrentConversation] = useState<TConversation>();
|
|
||||||
const { bookmarks } = useBookmarkContext();
|
const { bookmarks } = useBookmarkContext();
|
||||||
const localize = useLocalize();
|
const localize = useLocalize();
|
||||||
|
|
||||||
useEffect(() => {
|
|
||||||
if (!currentConversation) {
|
|
||||||
setCurrentConversation(conversation);
|
|
||||||
}
|
|
||||||
}, [conversation, currentConversation]);
|
|
||||||
|
|
||||||
const getUpdatedSelected = (tag: string) => {
|
const getUpdatedSelected = (tag: string) => {
|
||||||
if (tags.some((selectedTag) => selectedTag === tag)) {
|
if (tags.some((selectedTag) => selectedTag === tag)) {
|
||||||
return tags.filter((selectedTag) => selectedTag !== tag);
|
return tags.filter((selectedTag) => selectedTag !== tag);
|
||||||
|
|
|
||||||
|
|
@ -8,6 +8,7 @@ import {
|
||||||
TwoFactorScreen,
|
TwoFactorScreen,
|
||||||
RequestPasswordReset,
|
RequestPasswordReset,
|
||||||
} from '~/components/Auth';
|
} from '~/components/Auth';
|
||||||
|
import { MarketplaceProvider } from '~/components/Agents/MarketplaceContext';
|
||||||
import AgentMarketplace from '~/components/Agents/Marketplace';
|
import AgentMarketplace from '~/components/Agents/Marketplace';
|
||||||
import { OAuthSuccess, OAuthError } from '~/components/OAuth';
|
import { OAuthSuccess, OAuthError } from '~/components/OAuth';
|
||||||
import { AuthContextProvider } from '~/hooks/AuthContext';
|
import { AuthContextProvider } from '~/hooks/AuthContext';
|
||||||
|
|
@ -112,11 +113,19 @@ export const router = createBrowserRouter(
|
||||||
},
|
},
|
||||||
{
|
{
|
||||||
path: 'agents',
|
path: 'agents',
|
||||||
element: <AgentMarketplace />,
|
element: (
|
||||||
|
<MarketplaceProvider>
|
||||||
|
<AgentMarketplace />
|
||||||
|
</MarketplaceProvider>
|
||||||
|
),
|
||||||
},
|
},
|
||||||
{
|
{
|
||||||
path: 'agents/:category',
|
path: 'agents/:category',
|
||||||
element: <AgentMarketplace />,
|
element: (
|
||||||
|
<MarketplaceProvider>
|
||||||
|
<AgentMarketplace />
|
||||||
|
</MarketplaceProvider>
|
||||||
|
),
|
||||||
},
|
},
|
||||||
],
|
],
|
||||||
},
|
},
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue