'use client';
import CollectionCard from '@/features/collections/components/collectionCard/CollectionCard';
import CollectionCardSkeleton from '@/features/collections/components/collectionCard/Skeleton.CollectionCard';
import CreateCollectionDrawer from '@/features/collections/components/createCollectionDrawer/CreateCollectionDrawer';
import useMyCollections from '@/features/collections/lib/queries/useMyCollections';
import useOpenCollectionsWithContributor from '@/features/collections/lib/queries/useOpenCollectionsWithContributor';
import useFollowingCollections from '@/features/follows/lib/queries/useFollowingCollections';
import useMyProfile from '@/features/profile/lib/queries/useMyProfile';
import {
Stack,
Button,
Text,
SimpleGrid,
Group,
Title,
ActionIcon,
} from '@mantine/core';
import { Suspense, useState } from 'react';
import { BiCollection } from 'react-icons/bi';
import { FiPlus } from 'react-icons/fi';
import { useUserSettings } from '@/features/settings/lib/queries/useUserSettings';
import { LinkButton } from '@/components/link/MantineLink';
type CollectionFilter = 'mine' | 'following' | 'contributed';
function CollectionsListSkeleton() {
return (
{Array.from({ length: 4 }).map((_, i) => (
))}
);
}
function MyCollectionsList({
onCreateCollection,
settings,
}: {
onCreateCollection: () => void;
settings: ReturnType['settings'];
}) {
const { data: collectionsData } = useMyCollections({ limit: 4 });
const collections =
collectionsData.pages.flatMap((page) => page.collections) ?? [];
if (collections.length === 0) {
return (
No collections
}
>
Create your first collection
);
}
return (
{collections.map((collection) => (
))}
);
}
function FollowingCollectionsList({
identifier,
settings,
}: {
identifier: string;
settings: ReturnType['settings'];
}) {
const { data: collectionsData } = useFollowingCollections({
identifier,
limit: 4,
});
const collections =
collectionsData.pages.flatMap((page) => page.collections) ?? [];
if (collections.length === 0) {
return (
Not following any collections
);
}
return (
{collections.map((collection) => (
))}
);
}
function ContributedCollectionsList({
identifier,
settings,
}: {
identifier: string;
settings: ReturnType['settings'];
}) {
const { data: collectionsData } = useOpenCollectionsWithContributor({
identifier,
limit: 4,
});
const collections =
collectionsData.pages.flatMap((page) => page.collections) ?? [];
if (collections.length === 0) {
return (
No collections contributed to
);
}
return (
{collections.map((collection) => (
))}
);
}
export default function RecentCollections() {
const { settings } = useUserSettings();
const [showCollectionDrawer, setShowCollectionDrawer] = useState(false);
const [filter, setFilter] = useState('mine');
const { data: profile } = useMyProfile();
const viewAllHref = {
mine: `/profile/${profile.handle}/collections`,
following: `/profile/${profile.handle}/network/collections-following`,
contributed: `/profile/${profile.handle}/network/contributed-to`,
}[filter];
return (
Collections
{filter === 'mine' && (
setShowCollectionDrawer(true)}
aria-label="Create collection"
>
)}
View all
}>
{filter === 'mine' && (
setShowCollectionDrawer(true)}
settings={settings}
/>
)}
{filter === 'following' && (
)}
{filter === 'contributed' && (
)}
setShowCollectionDrawer(false)}
/>
);
}