collection dropdown update

This commit is contained in:
Nate Kelley 2025-03-28 14:30:34 -06:00
parent 40edefd8a0
commit c04418bc0c
No known key found for this signature in database
GPG Key ID: FD90372AB8D98B4F
3 changed files with 47 additions and 15 deletions

View File

@ -41,12 +41,16 @@ const useFetchCollection = () => {
}); });
}; };
export const useGetCollection = (collectionId: string | undefined) => { export const useGetCollection = <T = BusterCollection>(
collectionId: string | undefined,
select?: (data: BusterCollection) => T
) => {
const fetchCollection = useFetchCollection(); const fetchCollection = useFetchCollection();
return useQuery({ return useQuery({
...collectionQueryKeys.collectionsGetCollection(collectionId!), ...collectionQueryKeys.collectionsGetCollection(collectionId!),
queryFn: () => fetchCollection(collectionId!), queryFn: () => fetchCollection(collectionId!),
enabled: !!collectionId enabled: !!collectionId,
select
}); });
}; };

View File

@ -0,0 +1,21 @@
import React from 'react';
import { ShareButton } from './ShareButton';
import { ShareMenu } from '../ShareMenu';
import { ShareAssetType } from '@/api/asset_interfaces';
import { getShareAssetConfig } from '../ShareMenu/helpers';
import { useGetCollection } from '@/api/buster_rest/collections';
export const ShareCollectionButton = React.memo(({ collectionId }: { collectionId: string }) => {
const { data: collectionResponse } = useGetCollection(collectionId, getShareAssetConfig);
return (
<ShareMenu
shareAssetConfig={collectionResponse || null}
assetId={collectionId}
assetType={ShareAssetType.COLLECTION}>
<ShareButton />
</ShareMenu>
);
});
ShareCollectionButton.displayName = 'ShareCollectionButton';

View File

@ -5,7 +5,7 @@ import { Button } from '@/components/ui/buttons';
import { Dropdown, DropdownItems } from '@/components/ui/dropdown'; import { Dropdown, DropdownItems } from '@/components/ui/dropdown';
import { useAppLayoutContextSelector } from '@/context/BusterAppLayout'; import { useAppLayoutContextSelector } from '@/context/BusterAppLayout';
import { BusterRoutes } from '@/routes'; import { BusterRoutes } from '@/routes';
import { FavoriteStar } from '@/components/features/list/FavoriteStar'; import { FavoriteStar, useFavoriteStar } from '@/components/features/list/FavoriteStar';
import { ShareMenu } from '@/components/features/ShareMenu'; import { ShareMenu } from '@/components/features/ShareMenu';
import { BusterCollection, ShareAssetType } from '@/api/asset_interfaces'; import { BusterCollection, ShareAssetType } from '@/api/asset_interfaces';
import { useMemoizedFn } from '@/hooks'; import { useMemoizedFn } from '@/hooks';
@ -13,6 +13,9 @@ import { type BreadcrumbItem, Breadcrumb } from '@/components/ui/breadcrumb';
import { Dots, Pencil, Plus, ShareAllRight, ShareRight, Trash } from '@/components/ui/icons'; import { Dots, Pencil, Plus, ShareAllRight, ShareRight, Trash } from '@/components/ui/icons';
import { useDeleteCollection, useUpdateCollection } from '@/api/buster_rest/collections'; import { useDeleteCollection, useUpdateCollection } from '@/api/buster_rest/collections';
import { canEdit } from '@/lib/share'; import { canEdit } from '@/lib/share';
import { ShareCollectionButton } from '@/components/features/buttons/ShareMenuCollectionButton';
import { Star as StarFilled } from '@/components/ui/icons/NucleoIconFilled';
import { Star } from '@/components/ui/icons';
export const CollectionsIndividualHeader: React.FC<{ export const CollectionsIndividualHeader: React.FC<{
openAddTypeModal: boolean; openAddTypeModal: boolean;
@ -70,12 +73,7 @@ const ContentRight: React.FC<{
return ( return (
<div className="flex items-center space-x-2"> <div className="flex items-center space-x-2">
<ShareMenu <ShareCollectionButton collectionId={collection.id} />
assetType={ShareAssetType.COLLECTION}
assetId={collection.id}
shareAssetConfig={collection}>
<Button variant="ghost" prefix={<ShareRight />} />
</ShareMenu>
<Button prefix={<Plus />} onClick={onButtonClick}> <Button prefix={<Plus />} onClick={onButtonClick}>
Add to collection Add to collection
</Button> </Button>
@ -89,6 +87,11 @@ const ThreeDotDropdown: React.FC<{
}> = React.memo(({ collection }) => { }> = React.memo(({ collection }) => {
const onChangePage = useAppLayoutContextSelector((s) => s.onChangePage); const onChangePage = useAppLayoutContextSelector((s) => s.onChangePage);
const { mutateAsync: deleteCollection, isPending: isDeletingCollection } = useDeleteCollection(); const { mutateAsync: deleteCollection, isPending: isDeletingCollection } = useDeleteCollection();
const { isFavorited, onFavoriteClick } = useFavoriteStar({
id: collection.id,
type: ShareAssetType.COLLECTION,
name: collection.name || ''
});
const items: DropdownItems = useMemo( const items: DropdownItems = useMemo(
() => [ () => [
@ -113,17 +116,21 @@ const ThreeDotDropdown: React.FC<{
onClick: () => { onClick: () => {
// //
} }
},
{
value: 'favorite',
label: isFavorited ? 'Remove from favorites' : 'Add to favorites',
icon: isFavorited ? <StarFilled /> : <Star />,
onClick: onFavoriteClick
} }
], ],
[collection.id, deleteCollection, onChangePage] [collection.id, deleteCollection, onChangePage, isFavorited, onFavoriteClick]
); );
return ( return (
<div className="flex items-center">
<Dropdown items={items}> <Dropdown items={items}>
<Button variant="ghost" prefix={<Dots />}></Button> <Button variant="ghost" prefix={<Dots />}></Button>
</Dropdown> </Dropdown>
</div>
); );
}); });
ThreeDotDropdown.displayName = 'ThreeDotDropdown'; ThreeDotDropdown.displayName = 'ThreeDotDropdown';