mirror of
https://github.com/shumaiOne/shumai.git
synced 2026-12-01 13:34:33 +00:00
feat(project): add recent viewed files section to project folder tree (#348)
* feat(project): add recent viewed files section to project folder tree * feat(webui): disable toolbar buttons and context menu in recents page * test(core): optimize recents cap test execution time * feat(webui): show hint text in recents page top toolbar * feat(webui): rename recents section to Recently Viewed * refactor(core): consolidate recents methods into AssetService * fix(api): forward pagination parameters in folder children endpoint (#349) * fix(project-recents): scope views and disable recents mutations * fix(api): allow recent views in demo mode * fix(api): limit demo recent view exception to post
This commit is contained in:
@@ -100,6 +100,19 @@ function FileViewPage() {
|
||||
}
|
||||
}, [projectId, fetchProjectMembers])
|
||||
|
||||
useEffect(() => {
|
||||
if (projectId && fileId) {
|
||||
client.api.projects[':projectId'].recents.view
|
||||
.$post({
|
||||
param: { projectId },
|
||||
json: { assetId: fileId },
|
||||
})
|
||||
.catch(() => {
|
||||
// ignore background view recording errors
|
||||
})
|
||||
}
|
||||
}, [projectId, fileId])
|
||||
|
||||
const {
|
||||
data: stackData,
|
||||
isLoading: isStackLoading,
|
||||
|
||||
@@ -0,0 +1,51 @@
|
||||
import { createLazyFileRoute } from '@tanstack/react-router'
|
||||
import { useTeamContextStore } from '@/ui/stores/team-context'
|
||||
import { useQuery, useSuspenseQuery } from '@tanstack/react-query'
|
||||
import { useEffect } from 'react'
|
||||
import { client } from '@/ui/api/client'
|
||||
import FileSystemManager from '@/ui/components/file-system-manager'
|
||||
import { ProjectFolderSkeleton } from '@/ui/components/loading-skeletons'
|
||||
import { projectInfoQueryOptions } from './recents'
|
||||
|
||||
function RecentsPage() {
|
||||
const { projectId } = Route.useParams()
|
||||
const { teamId, ensureTeamIdForProject } = useTeamContextStore()
|
||||
|
||||
useEffect(() => {
|
||||
ensureTeamIdForProject(projectId)
|
||||
}, [projectId, ensureTeamIdForProject])
|
||||
|
||||
const { data: projectInfo } = useSuspenseQuery(projectInfoQueryOptions(projectId))
|
||||
|
||||
const rootFolderId = projectInfo?.rootFolder
|
||||
|
||||
const { data: rootFolder } = useQuery({
|
||||
queryKey: ['folders', rootFolderId!],
|
||||
queryFn: () =>
|
||||
(async () => {
|
||||
const res = await client.api.folders[':folderId'].$get({
|
||||
param: { folderId: rootFolderId! },
|
||||
})
|
||||
return await res.json()
|
||||
})(),
|
||||
enabled: !!rootFolderId,
|
||||
})
|
||||
|
||||
if (!teamId || !rootFolderId || !rootFolder) {
|
||||
return <ProjectFolderSkeleton />
|
||||
}
|
||||
|
||||
return (
|
||||
<FileSystemManager
|
||||
teamId={teamId}
|
||||
projectId={projectId}
|
||||
projectName={projectInfo.name ?? ''}
|
||||
assetId="recents"
|
||||
rootFolderId={rootFolderId}
|
||||
/>
|
||||
)
|
||||
}
|
||||
|
||||
export const Route = createLazyFileRoute('/projects/$projectId/recents')({
|
||||
component: RecentsPage,
|
||||
})
|
||||
@@ -0,0 +1,20 @@
|
||||
import { client } from '@/ui/api/client'
|
||||
import { ProjectFolderSkeleton } from '@/ui/components/loading-skeletons'
|
||||
import { createFileRoute } from '@tanstack/react-router'
|
||||
|
||||
export const projectInfoQueryOptions = (projectId: string) => ({
|
||||
queryKey: ['projects', projectId],
|
||||
queryFn: async () => {
|
||||
const res = await client.api.projects[':projectId'].$get({
|
||||
param: { projectId: projectId },
|
||||
})
|
||||
if (!res.ok) throw new Error('Failed to fetch project')
|
||||
return await res.json()
|
||||
},
|
||||
})
|
||||
|
||||
export const Route = createFileRoute('/projects/$projectId/recents')({
|
||||
loader: ({ context: { queryClient }, params: { projectId } }) =>
|
||||
queryClient.ensureQueryData(projectInfoQueryOptions(projectId)),
|
||||
pendingComponent: () => <ProjectFolderSkeleton />,
|
||||
})
|
||||
Reference in New Issue
Block a user