Skip to content

Commit 025a508

Browse files
committed
fix: collection sharing
1 parent 1ff6360 commit 025a508

File tree

2 files changed

+16
-73
lines changed

2 files changed

+16
-73
lines changed

web/src/app/marketplace/collections/[collectionId]/collection-header.tsx

Lines changed: 2 additions & 67 deletions
Original file line numberDiff line numberDiff line change
@@ -2,8 +2,6 @@
22

33
import { SharedCollection } from '@/api';
44
import { PageContent } from '@/components/page-container';
5-
import { useAppContext } from '@/components/providers/app-provider';
6-
import { Badge } from '@/components/ui/badge';
75
import {
86
Breadcrumb,
97
BreadcrumbItem,
@@ -14,21 +12,17 @@ import {
1412
import { Button } from '@/components/ui/button';
1513
import {
1614
Card,
17-
CardAction,
1815
CardDescription,
1916
CardHeader,
2017
CardTitle,
2118
} from '@/components/ui/card';
2219
import { Separator } from '@/components/ui/separator';
23-
import { apiClient } from '@/lib/api/client';
2420
import { cn } from '@/lib/utils';
2521
import _ from 'lodash';
26-
import { BookOpen, Files, Star, User, VectorSquare } from 'lucide-react';
22+
import { BookOpen, Files, VectorSquare } from 'lucide-react';
2723
import { useTranslations } from 'next-intl';
2824
import Link from 'next/link';
29-
import { usePathname, useRouter } from 'next/navigation';
30-
import { useCallback, useMemo } from 'react';
31-
import { FaStar } from 'react-icons/fa6';
25+
import { usePathname } from 'next/navigation';
3226

3327
export const CollectionHeader = ({
3428
className,
@@ -37,47 +31,13 @@ export const CollectionHeader = ({
3731
className?: string;
3832
collection: SharedCollection;
3933
}) => {
40-
const router = useRouter();
4134
const pathname = usePathname();
4235

43-
const { user, signIn } = useAppContext();
44-
const page_collections = useTranslations('page_collections');
4536
const page_documents = useTranslations('page_documents');
4637
const page_marketplace = useTranslations('page_marketplace');
4738
const page_graph = useTranslations('page_graph');
4839
const sidebar_workspace = useTranslations('sidebar_workspace');
4940

50-
const isOwner = useMemo(
51-
() => collection.owner_user_id === user?.id,
52-
[collection.owner_user_id, user?.id],
53-
);
54-
const isSubscriber = useMemo(
55-
() => collection.subscription_id !== null,
56-
[collection.subscription_id],
57-
);
58-
59-
const handleSubscribe = useCallback(async () => {
60-
if (!user) {
61-
signIn();
62-
return;
63-
}
64-
65-
if (isSubscriber) {
66-
await apiClient.defaultApi.marketplaceCollectionsCollectionIdSubscribeDelete(
67-
{
68-
collectionId: collection.id,
69-
},
70-
);
71-
} else {
72-
await apiClient.defaultApi.marketplaceCollectionsCollectionIdSubscribePost(
73-
{
74-
collectionId: collection.id,
75-
},
76-
);
77-
}
78-
router.refresh();
79-
}, [collection.id, isSubscriber, router, signIn, user]);
80-
8141
return (
8242
<PageContent className={cn('flex flex-col gap-4 pb-0', className)}>
8343
<div className="flex items-center">
@@ -110,31 +70,6 @@ export const CollectionHeader = ({
11070
<Card className="gap-0 p-0">
11171
<CardHeader className="p-4 pb-0">
11272
<CardTitle className="mb-0 text-2xl">{collection.title}</CardTitle>
113-
<CardAction className="text-muted-foreground flex flex-row items-center gap-4 text-xs">
114-
{isOwner ? (
115-
<Badge>{page_collections('mine')}</Badge>
116-
) : (
117-
<div className="flex flex-row items-center gap-1">
118-
<User className="size-4" />
119-
<div className="max-w-60 truncate">
120-
{collection.owner_username}
121-
</div>
122-
</div>
123-
)}
124-
<Button
125-
variant="outline"
126-
size="sm"
127-
hidden={isOwner}
128-
onClick={handleSubscribe}
129-
className="text-muted-foreground cursor-pointer text-xs"
130-
>
131-
{isSubscriber ? <FaStar className="text-orange-500" /> : <Star />}
132-
133-
{isSubscriber
134-
? page_collections('subscribed')
135-
: page_collections('subscribe')}
136-
</Button>
137-
</CardAction>
13873
</CardHeader>
13974
<CardDescription className="mb-4 px-4">
14075
{_.truncate(collection.description || 'No description available', {

web/src/app/workspace/collections/[collectionId]/collection-sharing.tsx

Lines changed: 14 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -47,12 +47,20 @@ export const CollectionSharing = ({
4747

4848
const handleSharing = useCallback(async () => {
4949
if (!collection?.id) return;
50-
await apiClient.defaultApi.collectionsCollectionIdSharingPost({
51-
collectionId: collection.id,
52-
collectionPublishRequest: {
53-
group_ids: selectedDepartents,
54-
},
55-
});
50+
51+
if (selectedDepartents.length === 0) {
52+
await apiClient.defaultApi.collectionsCollectionIdSharingDelete({
53+
collectionId: collection.id,
54+
});
55+
} else {
56+
await apiClient.defaultApi.collectionsCollectionIdSharingPost({
57+
collectionId: collection.id,
58+
collectionPublishRequest: {
59+
group_ids: selectedDepartents,
60+
},
61+
});
62+
}
63+
5664
setSharingVisible(false);
5765
toast.success(common_tips('update_success'));
5866
}, [collection?.id, common_tips, selectedDepartents]);

0 commit comments

Comments
 (0)