mirror of
https://github.com/shumaiOne/shumai.git
synced 2026-11-29 04:14:30 +00:00
feat(api,webui): implement image compression, auto-refresh for uploads, and infinite pagination for collections/shares
This commit is contained in:
@@ -12,10 +12,11 @@ import {
|
||||
import { Avatar, AvatarImage, AvatarFallback } from '@/ui/components/ui/avatar'
|
||||
import { useUiStore } from '@/ui/stores/ui'
|
||||
import { useTeamContextStore } from '@/ui/stores/team-context'
|
||||
import { useQuery, useSuspenseQuery } from '@tanstack/react-query'
|
||||
import { useInfiniteQuery, useSuspenseQuery } from '@tanstack/react-query'
|
||||
import { createFileRoute, useNavigate } from '@tanstack/react-router'
|
||||
import { useEffect, useState } from 'react'
|
||||
import { Bookmark, Calendar, LayoutGrid } from 'lucide-react'
|
||||
import { useEffect, useMemo, useState } from 'react'
|
||||
import { Bookmark, Calendar, LayoutGrid, Loader2 } from 'lucide-react'
|
||||
import { useInView } from 'react-intersection-observer'
|
||||
import type { CollectionInfo } from '@shumai/dtos'
|
||||
import { ProjectFolderSkeleton } from '@/ui/components/loading-skeletons'
|
||||
|
||||
@@ -59,25 +60,47 @@ function CollectionsPage() {
|
||||
setFileListLeftSidebarCollapsed: setIsLeftSidebarCollapsed,
|
||||
} = useUiStore()
|
||||
|
||||
const { data: collectionsData, isLoading: isCollectionsLoading } = useQuery({
|
||||
const {
|
||||
data: collectionsData,
|
||||
isLoading: isCollectionsLoading,
|
||||
fetchNextPage,
|
||||
hasNextPage,
|
||||
isFetchingNextPage,
|
||||
} = useInfiniteQuery({
|
||||
queryKey: ['collections', projectId],
|
||||
queryFn: async () => {
|
||||
queryFn: async ({ pageParam }) => {
|
||||
const res = await client.api.projects[':projectId'].collections.$get({
|
||||
param: { projectId },
|
||||
query: { first: '100' },
|
||||
query: { first: '20', after: pageParam as string },
|
||||
})
|
||||
if (!res.ok) throw new Error('Failed to fetch collections')
|
||||
return (await res.json()) as unknown as { data: CollectionInfo[] }
|
||||
return (await res.json()) as unknown as {
|
||||
data: CollectionInfo[]
|
||||
pageInfo: { cursor?: string; total?: number }
|
||||
}
|
||||
},
|
||||
initialPageParam: '',
|
||||
getNextPageParam: (lastPage) => lastPage.pageInfo?.cursor || undefined,
|
||||
enabled: !!projectId,
|
||||
})
|
||||
|
||||
const { ref: inViewRef, inView } = useInView()
|
||||
|
||||
useEffect(() => {
|
||||
if (inView && hasNextPage && !isFetchingNextPage) {
|
||||
fetchNextPage()
|
||||
}
|
||||
}, [inView, hasNextPage, isFetchingNextPage, fetchNextPage])
|
||||
|
||||
const collections = useMemo(
|
||||
() => collectionsData?.pages.flatMap((p) => p.data) || [],
|
||||
[collectionsData],
|
||||
)
|
||||
|
||||
if (!teamId || !rootFolderId || !projectInfo) {
|
||||
return <ProjectFolderSkeleton />
|
||||
}
|
||||
|
||||
const collections = collectionsData?.data ?? []
|
||||
|
||||
return (
|
||||
<div className="flex flex-1 flex-col bg-background min-h-0">
|
||||
<div className="flex flex-1 overflow-hidden relative">
|
||||
@@ -187,6 +210,9 @@ function CollectionsPage() {
|
||||
))}
|
||||
</TableBody>
|
||||
</Table>
|
||||
<div ref={inViewRef} className="h-10 w-full flex items-center justify-center">
|
||||
{isFetchingNextPage && <Loader2 className="h-6 w-6 animate-spin text-primary" />}
|
||||
</div>
|
||||
</div>
|
||||
)}
|
||||
</div>
|
||||
|
||||
@@ -14,10 +14,16 @@ import {
|
||||
import { Avatar, AvatarImage, AvatarFallback } from '@/ui/components/ui/avatar'
|
||||
import { useUiStore } from '@/ui/stores/ui'
|
||||
import { useTeamContextStore } from '@/ui/stores/team-context'
|
||||
import { useMutation, useQuery, useQueryClient, useSuspenseQuery } from '@tanstack/react-query'
|
||||
import {
|
||||
useMutation,
|
||||
useInfiniteQuery,
|
||||
useQueryClient,
|
||||
useSuspenseQuery,
|
||||
} from '@tanstack/react-query'
|
||||
import { createFileRoute, useNavigate } from '@tanstack/react-router'
|
||||
import { useEffect, useState } from 'react'
|
||||
import { Copy, ExternalLink, Calendar, Link2, Share2 } from 'lucide-react'
|
||||
import { useEffect, useMemo, useState } from 'react'
|
||||
import { Copy, ExternalLink, Calendar, Link2, Share2, Loader2 } from 'lucide-react'
|
||||
import { useInView } from 'react-intersection-observer'
|
||||
import { toast } from 'sonner'
|
||||
import type { ShareLinkInfo } from '@shumai/dtos'
|
||||
import { ProjectFolderSkeleton } from '@/ui/components/loading-skeletons'
|
||||
@@ -63,19 +69,40 @@ function SharesPage() {
|
||||
setFileListLeftSidebarCollapsed: setIsLeftSidebarCollapsed,
|
||||
} = useUiStore()
|
||||
|
||||
const { data: sharesData, isLoading: isSharesLoading } = useQuery({
|
||||
const {
|
||||
data: sharesData,
|
||||
isLoading: isSharesLoading,
|
||||
fetchNextPage,
|
||||
hasNextPage,
|
||||
isFetchingNextPage,
|
||||
} = useInfiniteQuery({
|
||||
queryKey: ['shares', projectId],
|
||||
queryFn: async () => {
|
||||
queryFn: async ({ pageParam }) => {
|
||||
const res = await client.api.projects[':projectId'].shares.$get({
|
||||
param: { projectId },
|
||||
query: { first: '100' },
|
||||
query: { first: '20', after: pageParam as string },
|
||||
})
|
||||
if (!res.ok) throw new Error('Failed to fetch share links')
|
||||
return (await res.json()) as unknown as { data: ShareLinkInfo[] }
|
||||
return (await res.json()) as unknown as {
|
||||
data: ShareLinkInfo[]
|
||||
pageInfo: { cursor?: string; total?: number }
|
||||
}
|
||||
},
|
||||
initialPageParam: '',
|
||||
getNextPageParam: (lastPage) => lastPage.pageInfo?.cursor || undefined,
|
||||
enabled: !!projectId,
|
||||
})
|
||||
|
||||
const { ref: inViewRef, inView } = useInView()
|
||||
|
||||
useEffect(() => {
|
||||
if (inView && hasNextPage && !isFetchingNextPage) {
|
||||
fetchNextPage()
|
||||
}
|
||||
}, [inView, hasNextPage, isFetchingNextPage, fetchNextPage])
|
||||
|
||||
const shares = useMemo(() => sharesData?.pages.flatMap((p) => p.data) || [], [sharesData])
|
||||
|
||||
const { mutate: toggleVisibility } = useMutation({
|
||||
mutationFn: async ({ id, isDisabled }: { id: string; isDisabled: boolean }) => {
|
||||
const res = await client.api.shares[':shareId'].$put({
|
||||
@@ -98,8 +125,6 @@ function SharesPage() {
|
||||
return <ProjectFolderSkeleton />
|
||||
}
|
||||
|
||||
const shares = sharesData?.data ?? []
|
||||
|
||||
const handleCopyLink = (shareId: string) => {
|
||||
const url = `${window.location.origin}/share/${shareId}`
|
||||
navigator.clipboard.writeText(url)
|
||||
@@ -255,6 +280,9 @@ function SharesPage() {
|
||||
})}
|
||||
</TableBody>
|
||||
</Table>
|
||||
<div ref={inViewRef} className="h-10 w-full flex items-center justify-center">
|
||||
{isFetchingNextPage && <Loader2 className="h-6 w-6 animate-spin text-primary" />}
|
||||
</div>
|
||||
</div>
|
||||
)}
|
||||
</div>
|
||||
|
||||
Reference in New Issue
Block a user