Add favorite link to chat dropdown

This commit is contained in:
Nate Kelley 2025-05-08 10:34:08 -06:00
parent bfe4cdce1c
commit 7894a06e2e
No known key found for this signature in database
GPG Key ID: FD90372AB8D98B4F
1 changed files with 27 additions and 3 deletions

View File

@ -1,14 +1,17 @@
import { Dropdown, DropdownItems } from '@/components/ui/dropdown'; import { Dropdown, DropdownItems } from '@/components/ui/dropdown';
import React, { useMemo } from 'react'; import React, { useMemo } from 'react';
import { useChatIndividualContextSelector } from '../../../ChatContext'; import { useChatIndividualContextSelector } from '../../../ChatContext';
import { Copy, Trash, Pencil, DuplicatePlus } from '@/components/ui/icons'; import { Copy, Trash, Pencil, DuplicatePlus, Star } from '@/components/ui/icons';
import { useDeleteChat, useDuplicateChat } from '@/api/buster_rest/chats'; import { Star as StarFilled } from '@/components/ui/icons/NucleoIconFilled';
import { useDeleteChat, useDuplicateChat, useGetChat } from '@/api/buster_rest/chats';
import { CHAT_HEADER_TITLE_ID } from '../ChatHeaderTitle'; import { CHAT_HEADER_TITLE_ID } from '../ChatHeaderTitle';
import { timeout } from '@/lib'; import { timeout } from '@/lib';
import { BusterRoutes } from '@/routes'; import { BusterRoutes } from '@/routes';
import { useAppLayoutContextSelector } from '@/context/BusterAppLayout'; import { useAppLayoutContextSelector } from '@/context/BusterAppLayout';
import { useBusterNotifications } from '@/context/BusterNotifications'; import { useBusterNotifications } from '@/context/BusterNotifications';
import { assetParamsToRoute } from '@/lib/assets'; import { assetParamsToRoute } from '@/lib/assets';
import { useFavoriteStar } from '@/components/features/list';
import { ShareAssetType } from '@/api/asset_interfaces/share';
export const ChatContainerHeaderDropdown: React.FC<{ export const ChatContainerHeaderDropdown: React.FC<{
children: React.ReactNode; children: React.ReactNode;
@ -21,6 +24,13 @@ export const ChatContainerHeaderDropdown: React.FC<{
const currentMessageId = useChatIndividualContextSelector((state) => state.currentMessageId); const currentMessageId = useChatIndividualContextSelector((state) => state.currentMessageId);
const selectedFileId = useChatIndividualContextSelector((state) => state.selectedFileId); const selectedFileId = useChatIndividualContextSelector((state) => state.selectedFileId);
const selectedFileType = useChatIndividualContextSelector((state) => state.selectedFileType); const selectedFileType = useChatIndividualContextSelector((state) => state.selectedFileType);
const { data: chatTitle } = useGetChat({ id: chatId || '' }, { select: (x) => x.title });
const { isFavorited, onFavoriteClick } = useFavoriteStar({
id: chatId || '',
type: ShareAssetType.CHAT,
name: chatTitle || ''
});
const menuItem: DropdownItems = useMemo(() => { const menuItem: DropdownItems = useMemo(() => {
return [ return [
@ -78,9 +88,23 @@ export const ChatContainerHeaderDropdown: React.FC<{
input.select(); input.select();
} }
} }
},
{
label: isFavorited ? 'Remove from favorites' : 'Add to favorites',
value: 'add-to-favorites',
icon: isFavorited ? <StarFilled /> : <Star />,
onClick: onFavoriteClick
} }
]; ];
}, [chatId, isDeleting, currentMessageId, deleteChat, duplicateChat]); }, [
chatId,
isDeleting,
currentMessageId,
deleteChat,
duplicateChat,
isFavorited,
onFavoriteClick
]);
return ( return (
<Dropdown align="end" items={menuItem}> <Dropdown align="end" items={menuItem}>