feat(collection): implement saved search results as collections

This commit is contained in:
yiling
2026-05-25 17:29:45 +08:00
parent 0e5a4972b6
commit 794e7b3367
24 changed files with 2462 additions and 63 deletions
+67 -1
View File
@@ -14,6 +14,7 @@ import {
MoreHorizontal,
Share2,
LayoutGrid,
Bookmark,
} from 'lucide-react'
import { useEffect, useMemo, useState } from 'react'
import { useInView } from 'react-intersection-observer'
@@ -21,6 +22,7 @@ import { useDraggable, useDroppable } from '@dnd-kit/react'
import type { DragState } from './dnd-types'
import { toast } from 'sonner'
import type { ShareLinkInfo } from '@/dtos/share'
import type { CollectionInfo } from '@/dtos/collection'
interface FolderTreeProps {
teamId: string
@@ -61,6 +63,47 @@ export function FolderTree({
enabled: !!teamId && !!projectId,
})
const { data: collectionsData } = useQuery({
queryKey: ['collections', teamId, projectId],
queryFn: async () => {
const res = await client.api.teams[':teamId'].projects[':projectId'].collections.$get({
param: { teamId, projectId },
query: { first: '100' },
})
if (!res.ok) throw new Error('Failed to fetch collections')
return (await res.json()) as unknown as { data: CollectionInfo[] }
},
enabled: !!teamId && !!projectId,
})
const { mutate: createCollection } = useMutation({
mutationFn: async () => {
const res = await client.api.teams[':teamId'].projects[':projectId'].collections.$post({
param: { teamId, projectId },
json: {
name: 'Untitled Collection',
filter: {
conditions: [],
recursively: true,
},
},
})
if (!res.ok) throw new Error('Failed to create collection')
return await res.json()
},
onSuccess: (data) => {
queryClient.invalidateQueries({ queryKey: ['collections', teamId, projectId] })
toast.success('Collection created')
navigate({
to: '/projects/$projectId/collections/$collectionId',
params: { projectId, collectionId: data.id },
})
},
onError: (err) => {
toast.error(`Error: ${err.message}`)
},
})
const { mutate: createShareLink } = useMutation({
mutationFn: async () => {
const res = await client.api.teams[':teamId'].projects[':projectId'].shares.$post({
@@ -148,10 +191,33 @@ export function FolderTree({
<h3 className="text-xs font-semibold text-muted-foreground uppercase tracking-wider">
Collections
</h3>
<button className="text-muted-foreground hover:text-foreground">
<button
onClick={() => createCollection()}
className="text-muted-foreground hover:text-foreground"
>
<Plus className="h-3.5 w-3.5" />
</button>
</header>
<div className="space-y-0.5">
{collectionsData?.data.map((collection) => (
<div
key={collection.id}
className="group flex cursor-pointer items-center gap-2 rounded-md px-2 py-1.5 text-sm transition-colors hover:bg-sidebar-accent hover:text-sidebar-accent-foreground"
onClick={() =>
navigate({
to: '/projects/$projectId/collections/$collectionId',
params: { projectId, collectionId: collection.id },
})
}
>
<div className="flex h-4 w-4 items-center justify-center">
<Bookmark className="h-4 w-4 text-sidebar-primary" />
</div>
<span className="flex-1 truncate text-sidebar-foreground">{collection.name}</span>
</div>
))}
</div>
</div>
<div>