mirror of
https://github.com/shumaiOne/shumai.git
synced 2026-12-05 23:54:25 +00:00
feat(webui): enable route-level manual code-splitting to optimize bundle size
This commit is contained in:
@@ -56,12 +56,12 @@ const ShareShareIdIndexRoute = ShareShareIdIndexRouteImport.update({
|
|||||||
id: '/',
|
id: '/',
|
||||||
path: '/',
|
path: '/',
|
||||||
getParentRoute: () => ShareShareIdRoute,
|
getParentRoute: () => ShareShareIdRoute,
|
||||||
} as any)
|
} as any).lazy(() => import('./routes/share/$shareId/index.lazy').then((d) => d.Route))
|
||||||
const ProjectsProjectIdIndexRoute = ProjectsProjectIdIndexRouteImport.update({
|
const ProjectsProjectIdIndexRoute = ProjectsProjectIdIndexRouteImport.update({
|
||||||
id: '/projects/$projectId/',
|
id: '/projects/$projectId/',
|
||||||
path: '/projects/$projectId/',
|
path: '/projects/$projectId/',
|
||||||
getParentRoute: () => rootRouteImport,
|
getParentRoute: () => rootRouteImport,
|
||||||
} as any)
|
} as any).lazy(() => import('./routes/projects/$projectId/index.lazy').then((d) => d.Route))
|
||||||
const TeamsTeamIdSettingsRoute = TeamsTeamIdSettingsRouteImport.update({
|
const TeamsTeamIdSettingsRoute = TeamsTeamIdSettingsRouteImport.update({
|
||||||
id: '/teams/$teamId/settings',
|
id: '/teams/$teamId/settings',
|
||||||
path: '/teams/$teamId/settings',
|
path: '/teams/$teamId/settings',
|
||||||
@@ -71,7 +71,9 @@ const ProjectsProjectIdRecentlyDeletedRoute = ProjectsProjectIdRecentlyDeletedRo
|
|||||||
id: '/projects/$projectId/recently-deleted',
|
id: '/projects/$projectId/recently-deleted',
|
||||||
path: '/projects/$projectId/recently-deleted',
|
path: '/projects/$projectId/recently-deleted',
|
||||||
getParentRoute: () => rootRouteImport,
|
getParentRoute: () => rootRouteImport,
|
||||||
} as any)
|
} as any).lazy(() =>
|
||||||
|
import('./routes/projects/$projectId/recently-deleted.lazy').then((d) => d.Route),
|
||||||
|
)
|
||||||
const ProjectsProjectIdSharesIndexRoute = ProjectsProjectIdSharesIndexRouteImport.update({
|
const ProjectsProjectIdSharesIndexRoute = ProjectsProjectIdSharesIndexRouteImport.update({
|
||||||
id: '/projects/$projectId/shares/',
|
id: '/projects/$projectId/shares/',
|
||||||
path: '/projects/$projectId/shares/',
|
path: '/projects/$projectId/shares/',
|
||||||
@@ -86,12 +88,12 @@ const ShareShareIdFoldersFolderIdRoute = ShareShareIdFoldersFolderIdRouteImport.
|
|||||||
id: '/folders/$folderId',
|
id: '/folders/$folderId',
|
||||||
path: '/folders/$folderId',
|
path: '/folders/$folderId',
|
||||||
getParentRoute: () => ShareShareIdRoute,
|
getParentRoute: () => ShareShareIdRoute,
|
||||||
} as any)
|
} as any).lazy(() => import('./routes/share/$shareId/folders/$folderId.lazy').then((d) => d.Route))
|
||||||
const ShareShareIdFilesFileIdRoute = ShareShareIdFilesFileIdRouteImport.update({
|
const ShareShareIdFilesFileIdRoute = ShareShareIdFilesFileIdRouteImport.update({
|
||||||
id: '/files/$fileId',
|
id: '/files/$fileId',
|
||||||
path: '/files/$fileId',
|
path: '/files/$fileId',
|
||||||
getParentRoute: () => ShareShareIdRoute,
|
getParentRoute: () => ShareShareIdRoute,
|
||||||
} as any)
|
} as any).lazy(() => import('./routes/share/$shareId/files/$fileId.lazy').then((d) => d.Route))
|
||||||
const ProjectsProjectIdSharesShareIdRoute = ProjectsProjectIdSharesShareIdRouteImport.update({
|
const ProjectsProjectIdSharesShareIdRoute = ProjectsProjectIdSharesShareIdRouteImport.update({
|
||||||
id: '/projects/$projectId/shares/$shareId',
|
id: '/projects/$projectId/shares/$shareId',
|
||||||
path: '/projects/$projectId/shares/$shareId',
|
path: '/projects/$projectId/shares/$shareId',
|
||||||
@@ -101,18 +103,22 @@ const ProjectsProjectIdFoldersFolderIdRoute = ProjectsProjectIdFoldersFolderIdRo
|
|||||||
id: '/projects/$projectId/folders/$folderId',
|
id: '/projects/$projectId/folders/$folderId',
|
||||||
path: '/projects/$projectId/folders/$folderId',
|
path: '/projects/$projectId/folders/$folderId',
|
||||||
getParentRoute: () => rootRouteImport,
|
getParentRoute: () => rootRouteImport,
|
||||||
} as any)
|
} as any).lazy(() =>
|
||||||
|
import('./routes/projects/$projectId/folders/$folderId.lazy').then((d) => d.Route),
|
||||||
|
)
|
||||||
const ProjectsProjectIdFilesFileIdRoute = ProjectsProjectIdFilesFileIdRouteImport.update({
|
const ProjectsProjectIdFilesFileIdRoute = ProjectsProjectIdFilesFileIdRouteImport.update({
|
||||||
id: '/projects/$projectId/files/$fileId',
|
id: '/projects/$projectId/files/$fileId',
|
||||||
path: '/projects/$projectId/files/$fileId',
|
path: '/projects/$projectId/files/$fileId',
|
||||||
getParentRoute: () => rootRouteImport,
|
getParentRoute: () => rootRouteImport,
|
||||||
} as any)
|
} as any).lazy(() => import('./routes/projects/$projectId/files/$fileId.lazy').then((d) => d.Route))
|
||||||
const ProjectsProjectIdCollectionsCollectionIdRoute =
|
const ProjectsProjectIdCollectionsCollectionIdRoute =
|
||||||
ProjectsProjectIdCollectionsCollectionIdRouteImport.update({
|
ProjectsProjectIdCollectionsCollectionIdRouteImport.update({
|
||||||
id: '/projects/$projectId/collections/$collectionId',
|
id: '/projects/$projectId/collections/$collectionId',
|
||||||
path: '/projects/$projectId/collections/$collectionId',
|
path: '/projects/$projectId/collections/$collectionId',
|
||||||
getParentRoute: () => rootRouteImport,
|
getParentRoute: () => rootRouteImport,
|
||||||
} as any)
|
} as any).lazy(() =>
|
||||||
|
import('./routes/projects/$projectId/collections/$collectionId.lazy').then((d) => d.Route),
|
||||||
|
)
|
||||||
|
|
||||||
export interface FileRoutesByFullPath {
|
export interface FileRoutesByFullPath {
|
||||||
'/': typeof IndexRoute
|
'/': typeof IndexRoute
|
||||||
|
|||||||
@@ -0,0 +1,75 @@
|
|||||||
|
import { createLazyFileRoute } from '@tanstack/react-router'
|
||||||
|
import { useTeamContextStore } from '@/ui/stores/team-context'
|
||||||
|
import { useMutation, 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 { m } from '@/ui/paraglide/messages.js'
|
||||||
|
import { projectInfoQueryOptions, collectionInfoQueryOptions } from './$collectionId'
|
||||||
|
|
||||||
|
function CollectionPage() {
|
||||||
|
const { projectId, collectionId } = Route.useParams()
|
||||||
|
const { teamId, ensureTeamIdForProject } = useTeamContextStore()
|
||||||
|
|
||||||
|
useEffect(() => {
|
||||||
|
ensureTeamIdForProject(projectId)
|
||||||
|
}, [projectId, ensureTeamIdForProject])
|
||||||
|
|
||||||
|
const { data: projectInfo } = useSuspenseQuery(projectInfoQueryOptions(projectId))
|
||||||
|
|
||||||
|
const { data: collection, refetch: refetchCollection } = useQuery({
|
||||||
|
...collectionInfoQueryOptions(collectionId),
|
||||||
|
})
|
||||||
|
|
||||||
|
const { mutate: updateCollection } = useMutation({
|
||||||
|
// eslint-disable-next-line @typescript-eslint/no-explicit-any
|
||||||
|
mutationFn: async (updates: { name?: string; filter?: any }) => {
|
||||||
|
const res = await client.api.collections[':collectionId'].$patch({
|
||||||
|
param: { collectionId },
|
||||||
|
json: updates,
|
||||||
|
})
|
||||||
|
if (!res.ok) throw new Error('Failed to update collection')
|
||||||
|
return await res.json()
|
||||||
|
},
|
||||||
|
onSuccess: () => {
|
||||||
|
refetchCollection()
|
||||||
|
},
|
||||||
|
})
|
||||||
|
|
||||||
|
const rootFolderId = projectInfo?.rootFolder
|
||||||
|
|
||||||
|
const { data: rootFolder } = useQuery({
|
||||||
|
queryKey: ['folders', rootFolderId!],
|
||||||
|
queryFn: async () => {
|
||||||
|
const res = await client.api.folders[':folderId'].$get({
|
||||||
|
param: { folderId: rootFolderId! },
|
||||||
|
})
|
||||||
|
if (!res.ok) throw new Error('Failed to fetch folder')
|
||||||
|
return await res.json()
|
||||||
|
},
|
||||||
|
enabled: !!rootFolderId,
|
||||||
|
})
|
||||||
|
|
||||||
|
if (!teamId || !rootFolderId || !rootFolder || !collection) {
|
||||||
|
return <div>{m.loading_collection()}</div>
|
||||||
|
}
|
||||||
|
|
||||||
|
const sourceFolderId = collection.filter.sourceFolderId || rootFolderId
|
||||||
|
|
||||||
|
return (
|
||||||
|
<FileSystemManager
|
||||||
|
teamId={teamId}
|
||||||
|
projectId={projectId}
|
||||||
|
projectName={projectInfo.name ?? ''}
|
||||||
|
assetId={sourceFolderId}
|
||||||
|
rootFolderId={rootFolderId}
|
||||||
|
// eslint-disable-next-line @typescript-eslint/no-explicit-any
|
||||||
|
collection={collection as any}
|
||||||
|
onUpdateCollection={updateCollection}
|
||||||
|
/>
|
||||||
|
)
|
||||||
|
}
|
||||||
|
|
||||||
|
export const Route = createLazyFileRoute('/projects/$projectId/collections/$collectionId')({
|
||||||
|
component: CollectionPage,
|
||||||
|
})
|
||||||
@@ -1,12 +1,8 @@
|
|||||||
import { client } from '@/ui/api/client'
|
import { client } from '@/ui/api/client'
|
||||||
import FileSystemManager from '@/ui/components/file-system-manager'
|
|
||||||
import { useTeamContextStore } from '@/ui/stores/team-context'
|
|
||||||
import { useMutation, useQuery, useSuspenseQuery } from '@tanstack/react-query'
|
|
||||||
import { createFileRoute } from '@tanstack/react-router'
|
|
||||||
import { useEffect } from 'react'
|
|
||||||
import { m } from '@/ui/paraglide/messages.js'
|
import { m } from '@/ui/paraglide/messages.js'
|
||||||
|
import { createFileRoute } from '@tanstack/react-router'
|
||||||
|
|
||||||
const projectInfoQueryOptions = (projectId: string) => ({
|
export const projectInfoQueryOptions = (projectId: string) => ({
|
||||||
queryKey: ['projects', projectId],
|
queryKey: ['projects', projectId],
|
||||||
queryFn: async () => {
|
queryFn: async () => {
|
||||||
const res = await client.api.projects[':projectId'].$get({
|
const res = await client.api.projects[':projectId'].$get({
|
||||||
@@ -17,7 +13,7 @@ const projectInfoQueryOptions = (projectId: string) => ({
|
|||||||
},
|
},
|
||||||
})
|
})
|
||||||
|
|
||||||
const collectionInfoQueryOptions = (collectionId: string) => ({
|
export const collectionInfoQueryOptions = (collectionId: string) => ({
|
||||||
queryKey: ['collections', collectionId],
|
queryKey: ['collections', collectionId],
|
||||||
queryFn: async () => {
|
queryFn: async () => {
|
||||||
const res = await client.api.collections[':collectionId'].$get({
|
const res = await client.api.collections[':collectionId'].$get({
|
||||||
@@ -28,71 +24,7 @@ const collectionInfoQueryOptions = (collectionId: string) => ({
|
|||||||
},
|
},
|
||||||
})
|
})
|
||||||
|
|
||||||
function CollectionPage() {
|
|
||||||
const { projectId, collectionId } = Route.useParams()
|
|
||||||
const { teamId, ensureTeamIdForProject } = useTeamContextStore()
|
|
||||||
|
|
||||||
useEffect(() => {
|
|
||||||
ensureTeamIdForProject(projectId)
|
|
||||||
}, [projectId, ensureTeamIdForProject])
|
|
||||||
|
|
||||||
const { data: projectInfo } = useSuspenseQuery(projectInfoQueryOptions(projectId))
|
|
||||||
|
|
||||||
const { data: collection, refetch: refetchCollection } = useQuery({
|
|
||||||
...collectionInfoQueryOptions(collectionId),
|
|
||||||
})
|
|
||||||
|
|
||||||
const { mutate: updateCollection } = useMutation({
|
|
||||||
// eslint-disable-next-line @typescript-eslint/no-explicit-any
|
|
||||||
mutationFn: async (updates: { name?: string; filter?: any }) => {
|
|
||||||
const res = await client.api.collections[':collectionId'].$patch({
|
|
||||||
param: { collectionId },
|
|
||||||
json: updates,
|
|
||||||
})
|
|
||||||
if (!res.ok) throw new Error('Failed to update collection')
|
|
||||||
return await res.json()
|
|
||||||
},
|
|
||||||
onSuccess: () => {
|
|
||||||
refetchCollection()
|
|
||||||
},
|
|
||||||
})
|
|
||||||
|
|
||||||
const rootFolderId = projectInfo?.rootFolder
|
|
||||||
|
|
||||||
const { data: rootFolder } = useQuery({
|
|
||||||
queryKey: ['folders', rootFolderId!],
|
|
||||||
queryFn: async () => {
|
|
||||||
const res = await client.api.folders[':folderId'].$get({
|
|
||||||
param: { folderId: rootFolderId! },
|
|
||||||
})
|
|
||||||
if (!res.ok) throw new Error('Failed to fetch folder')
|
|
||||||
return await res.json()
|
|
||||||
},
|
|
||||||
enabled: !!rootFolderId,
|
|
||||||
})
|
|
||||||
|
|
||||||
if (!teamId || !rootFolderId || !rootFolder || !collection) {
|
|
||||||
return <div>{m.loading_collection()}</div>
|
|
||||||
}
|
|
||||||
|
|
||||||
const sourceFolderId = collection.filter.sourceFolderId || rootFolderId
|
|
||||||
|
|
||||||
return (
|
|
||||||
<FileSystemManager
|
|
||||||
teamId={teamId}
|
|
||||||
projectId={projectId}
|
|
||||||
projectName={projectInfo.name ?? ''}
|
|
||||||
assetId={sourceFolderId}
|
|
||||||
rootFolderId={rootFolderId}
|
|
||||||
// eslint-disable-next-line @typescript-eslint/no-explicit-any
|
|
||||||
collection={collection as any}
|
|
||||||
onUpdateCollection={updateCollection}
|
|
||||||
/>
|
|
||||||
)
|
|
||||||
}
|
|
||||||
|
|
||||||
export const Route = createFileRoute('/projects/$projectId/collections/$collectionId')({
|
export const Route = createFileRoute('/projects/$projectId/collections/$collectionId')({
|
||||||
component: CollectionPage,
|
|
||||||
loader: ({ context: { queryClient }, params: { projectId } }) =>
|
loader: ({ context: { queryClient }, params: { projectId } }) =>
|
||||||
queryClient.ensureQueryData(projectInfoQueryOptions(projectId)),
|
queryClient.ensureQueryData(projectInfoQueryOptions(projectId)),
|
||||||
pendingComponent: () => <div>{m.loading_collection()}</div>,
|
pendingComponent: () => <div>{m.loading_collection()}</div>,
|
||||||
|
|||||||
@@ -0,0 +1,464 @@
|
|||||||
|
import { createLazyFileRoute } from '@tanstack/react-router'
|
||||||
|
import { client } from '@/ui/api/client'
|
||||||
|
import { FileViewer } from '@/ui/components/file-viewer'
|
||||||
|
import { CompareViewer } from '@/ui/components/compare/compare-viewer'
|
||||||
|
import { pickDefaultCompareVersions } from '@/ui/components/compare/compare-utils'
|
||||||
|
import { FileViewerLeftSidebar } from '@/ui/components/file-viewer-left-sidebar'
|
||||||
|
import { m } from '@/ui/paraglide/messages.js'
|
||||||
|
import { FileViewerRightSidebar } from '@/ui/components/file-viewer-right-sidebar'
|
||||||
|
import { ResizeHandle } from '@/ui/components/resize-handle'
|
||||||
|
import { FileDetailSkeleton } from '@/ui/components/loading-skeletons'
|
||||||
|
import { useMemberStore } from '@/ui/stores/members'
|
||||||
|
import { useTeamContextStore } from '@/ui/stores/team-context'
|
||||||
|
import { useTopNavStore } from '@/ui/stores/top-nav'
|
||||||
|
import { type Annotation } from '@/ui/types'
|
||||||
|
import { useMutation } from '@tanstack/react-query'
|
||||||
|
import { InferRequestType, InferResponseType } from 'hono/client'
|
||||||
|
|
||||||
|
import type { AssetInfo, AssetInfoPaginatedList, CommentInfo } from '@shumai/dtos'
|
||||||
|
import { keepPreviousData, useQuery, useQueryClient } from '@tanstack/react-query'
|
||||||
|
import { useNavigate } from '@tanstack/react-router'
|
||||||
|
import { Loader2 } from 'lucide-react'
|
||||||
|
import { useEffect, useRef, useState } from 'react'
|
||||||
|
import type { MediaController } from '@/ui/components/viewers/types'
|
||||||
|
|
||||||
|
function FileViewPage() {
|
||||||
|
const { projectId, fileId } = Route.useParams()
|
||||||
|
const search = Route.useSearch()
|
||||||
|
const versionAssetId = search.version
|
||||||
|
const startTime = search.start
|
||||||
|
const activeFileId = versionAssetId || fileId
|
||||||
|
const compareLeftId = search.cmpLeft
|
||||||
|
const compareRightId = search.cmpRight
|
||||||
|
const compareActiveSide = search.cmpActive ?? 'left'
|
||||||
|
const isCompareMode = !!search.compare && !!compareLeftId && !!compareRightId
|
||||||
|
|
||||||
|
const mediaControllerRef = useRef<MediaController | null>(null)
|
||||||
|
const { teamId, ensureTeamIdForProject } = useTeamContextStore()
|
||||||
|
const [rightSidebarWidth, setRightSidebarWidth] = useState(360)
|
||||||
|
const [annotations, setAnnotations] = useState<Annotation[]>([])
|
||||||
|
const [currentTime, setCurrentTime] = useState(0)
|
||||||
|
const [selectedCommentId, setSelectedCommentId] = useState<string | null>(null)
|
||||||
|
const [compareActiveAsset, setCompareActiveAsset] = useState<AssetInfo | null>(null)
|
||||||
|
const [seekRequest, setSeekRequest] = useState<{ second: number; nonce: number } | undefined>(
|
||||||
|
undefined,
|
||||||
|
)
|
||||||
|
const [carouselState, setCarouselState] = useState<{
|
||||||
|
show: boolean
|
||||||
|
files: AssetInfo[]
|
||||||
|
nextCursor?: string
|
||||||
|
folderId?: string
|
||||||
|
}>({ show: false, files: [], nextCursor: undefined, folderId: undefined })
|
||||||
|
const $patchMetadata = client.api.files[':fileId'].metadata.$patch
|
||||||
|
const { mutate: patchMetadata } = useMutation<
|
||||||
|
InferResponseType<typeof $patchMetadata>,
|
||||||
|
Error,
|
||||||
|
InferRequestType<typeof $patchMetadata>
|
||||||
|
>({
|
||||||
|
mutationFn: async (request) => {
|
||||||
|
const res = await $patchMetadata(request)
|
||||||
|
if (!res.ok) throw new Error('Failed to patch metadata')
|
||||||
|
return (await res.json()) as unknown as InferResponseType<typeof $patchMetadata>
|
||||||
|
},
|
||||||
|
})
|
||||||
|
const queryClient = useQueryClient()
|
||||||
|
const { members, fetchMembers } = useMemberStore()
|
||||||
|
|
||||||
|
useEffect(() => {
|
||||||
|
ensureTeamIdForProject(projectId)
|
||||||
|
}, [projectId, ensureTeamIdForProject])
|
||||||
|
|
||||||
|
useEffect(() => {
|
||||||
|
if (teamId) {
|
||||||
|
fetchMembers(teamId, true)
|
||||||
|
}
|
||||||
|
}, [teamId, fetchMembers])
|
||||||
|
|
||||||
|
const {
|
||||||
|
data: stackData,
|
||||||
|
isLoading: isStackLoading,
|
||||||
|
isError: isStackError,
|
||||||
|
isFetching: isStackFetching,
|
||||||
|
} = useQuery({
|
||||||
|
queryKey: ['files', fileId],
|
||||||
|
queryFn: async () => {
|
||||||
|
const res = await client.api.files[':fileId'].$get({
|
||||||
|
param: { fileId: fileId },
|
||||||
|
})
|
||||||
|
if (!res.ok) throw new Error('Failed to fetch stack')
|
||||||
|
return await res.json()
|
||||||
|
},
|
||||||
|
enabled: !!teamId,
|
||||||
|
placeholderData: keepPreviousData,
|
||||||
|
})
|
||||||
|
|
||||||
|
const {
|
||||||
|
data: versionData,
|
||||||
|
isLoading: isVersionLoading,
|
||||||
|
isError: isVersionError,
|
||||||
|
isFetching: isVersionFetching,
|
||||||
|
} = useQuery({
|
||||||
|
queryKey: ['files', versionAssetId],
|
||||||
|
queryFn: async () => {
|
||||||
|
const res = await client.api.files[':fileId'].$get({
|
||||||
|
param: { fileId: versionAssetId! },
|
||||||
|
})
|
||||||
|
if (!res.ok) throw new Error('Failed to fetch version')
|
||||||
|
return await res.json()
|
||||||
|
},
|
||||||
|
enabled: !!teamId && !!versionAssetId,
|
||||||
|
placeholderData: keepPreviousData,
|
||||||
|
})
|
||||||
|
|
||||||
|
const { data: versionsList } = useQuery({
|
||||||
|
queryKey: ['version_stacks', fileId, 'versions'],
|
||||||
|
queryFn: async () => {
|
||||||
|
const res = await client.api.version_stacks[':stackId'].versions.$get({
|
||||||
|
param: { stackId: fileId },
|
||||||
|
})
|
||||||
|
if (!res.ok) throw new Error('Failed to fetch versions')
|
||||||
|
return await res.json()
|
||||||
|
},
|
||||||
|
enabled: !!projectId && !!fileId && (!!versionAssetId || isCompareMode),
|
||||||
|
})
|
||||||
|
|
||||||
|
const { data: projectInfo } = useQuery({
|
||||||
|
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()
|
||||||
|
},
|
||||||
|
})
|
||||||
|
|
||||||
|
const navigate = useNavigate()
|
||||||
|
const { setProjectState, clearProjectState } = useTopNavStore()
|
||||||
|
|
||||||
|
const isLoading = isStackLoading || (!!versionAssetId && isVersionLoading)
|
||||||
|
const isError = isStackError || (!!versionAssetId && isVersionError)
|
||||||
|
const isFetching = isStackFetching || (!!versionAssetId && isVersionFetching)
|
||||||
|
const fileData = versionData || stackData
|
||||||
|
const versionsDataList = versionAssetId ? versionsList : stackData?.versionStack?.versions
|
||||||
|
|
||||||
|
useEffect(() => {
|
||||||
|
if (fileData && projectInfo && teamId) {
|
||||||
|
setProjectState({
|
||||||
|
teamId,
|
||||||
|
projectId,
|
||||||
|
projectName: projectInfo.name ?? '',
|
||||||
|
ancestorFolders: fileData.ancestorFolders ?? [],
|
||||||
|
currentAsset: {
|
||||||
|
name: fileData.name,
|
||||||
|
type: 'file',
|
||||||
|
version: versionsDataList
|
||||||
|
? (versionsDataList.find((v: { id: string }) => v.id === activeFileId)?.version ??
|
||||||
|
versionsDataList.length)
|
||||||
|
: undefined,
|
||||||
|
mediaType: fileData.mediaType,
|
||||||
|
},
|
||||||
|
isRootFolder: false,
|
||||||
|
fileId,
|
||||||
|
downloadInfo: {
|
||||||
|
originalKey: fileData.media?.original?.key,
|
||||||
|
videoTranscodes: fileData.media?.videoTranscodes?.map((t) => ({
|
||||||
|
key: t.key,
|
||||||
|
width: t.width,
|
||||||
|
height: t.height,
|
||||||
|
isRaw: t.isRaw,
|
||||||
|
})),
|
||||||
|
},
|
||||||
|
versions: versionsDataList,
|
||||||
|
compareMode: isCompareMode,
|
||||||
|
canCompareVersions: (versionsDataList?.length ?? 0) >= 2,
|
||||||
|
onCompareVersions: () => {
|
||||||
|
const pair = pickDefaultCompareVersions(versionsDataList)
|
||||||
|
if (!pair) return
|
||||||
|
navigate({
|
||||||
|
to: '/projects/$projectId/files/$fileId',
|
||||||
|
params: { projectId, fileId },
|
||||||
|
search: (p: Record<string, unknown>) => ({
|
||||||
|
...p,
|
||||||
|
version: undefined,
|
||||||
|
compare: true,
|
||||||
|
cmpLeft: pair.left.id,
|
||||||
|
cmpRight: pair.right.id,
|
||||||
|
cmpActive: 'left' as const,
|
||||||
|
}),
|
||||||
|
})
|
||||||
|
},
|
||||||
|
onFolderClick: (id: string) => {
|
||||||
|
navigate({
|
||||||
|
to: '/projects/$projectId/folders/$folderId',
|
||||||
|
params: { projectId, folderId: id },
|
||||||
|
})
|
||||||
|
},
|
||||||
|
})
|
||||||
|
}
|
||||||
|
|
||||||
|
return () => clearProjectState()
|
||||||
|
}, [
|
||||||
|
teamId,
|
||||||
|
projectId,
|
||||||
|
projectInfo,
|
||||||
|
fileData,
|
||||||
|
versionsDataList,
|
||||||
|
activeFileId,
|
||||||
|
fileId,
|
||||||
|
isCompareMode,
|
||||||
|
setProjectState,
|
||||||
|
clearProjectState,
|
||||||
|
navigate,
|
||||||
|
])
|
||||||
|
|
||||||
|
const parentFolderId = fileData?.ancestorFolders?.[0]?.id ?? projectInfo?.rootFolder ?? ''
|
||||||
|
|
||||||
|
useEffect(() => {
|
||||||
|
if (!parentFolderId || !activeFileId) return
|
||||||
|
if (carouselState.folderId === parentFolderId) {
|
||||||
|
return
|
||||||
|
}
|
||||||
|
|
||||||
|
let isMounted = true
|
||||||
|
|
||||||
|
const fetchCarouselData = async () => {
|
||||||
|
try {
|
||||||
|
let cursor = ''
|
||||||
|
let found = false
|
||||||
|
const allFiles: AssetInfo[] = []
|
||||||
|
let lastCursor: string | undefined = undefined
|
||||||
|
|
||||||
|
for (let batch = 0; batch < 5; batch++) {
|
||||||
|
const res = await client.api.folders[':folderId'].search.$post({
|
||||||
|
param: { folderId: parentFolderId },
|
||||||
|
json: {
|
||||||
|
assetType: 'file',
|
||||||
|
after: cursor,
|
||||||
|
first: 200,
|
||||||
|
recursively: false,
|
||||||
|
conditions: [],
|
||||||
|
},
|
||||||
|
})
|
||||||
|
if (!res.ok) {
|
||||||
|
throw new Error('Failed to search parent folder for carousel')
|
||||||
|
}
|
||||||
|
const result = (await res.json()) as unknown as AssetInfoPaginatedList
|
||||||
|
const batchFiles = (result.data || []) as AssetInfo[]
|
||||||
|
allFiles.push(...batchFiles)
|
||||||
|
|
||||||
|
if (batchFiles.some((f) => f.id === activeFileId)) {
|
||||||
|
found = true
|
||||||
|
lastCursor = result.pageInfo?.cursor || undefined
|
||||||
|
break
|
||||||
|
}
|
||||||
|
if (!result.pageInfo?.cursor || batchFiles.length < 200) {
|
||||||
|
break
|
||||||
|
}
|
||||||
|
cursor = result.pageInfo.cursor
|
||||||
|
}
|
||||||
|
|
||||||
|
if (isMounted) {
|
||||||
|
if (found) {
|
||||||
|
setCarouselState({
|
||||||
|
show: true,
|
||||||
|
files: allFiles,
|
||||||
|
nextCursor: lastCursor,
|
||||||
|
folderId: parentFolderId,
|
||||||
|
})
|
||||||
|
} else {
|
||||||
|
setCarouselState({
|
||||||
|
show: false,
|
||||||
|
files: [],
|
||||||
|
nextCursor: undefined,
|
||||||
|
folderId: parentFolderId,
|
||||||
|
})
|
||||||
|
}
|
||||||
|
}
|
||||||
|
} catch (err) {
|
||||||
|
console.error(err)
|
||||||
|
if (isMounted) {
|
||||||
|
setCarouselState({
|
||||||
|
show: false,
|
||||||
|
files: [],
|
||||||
|
nextCursor: undefined,
|
||||||
|
folderId: parentFolderId,
|
||||||
|
})
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
fetchCarouselData()
|
||||||
|
|
||||||
|
return () => {
|
||||||
|
isMounted = false
|
||||||
|
}
|
||||||
|
}, [parentFolderId, activeFileId, carouselState.folderId])
|
||||||
|
|
||||||
|
useEffect(() => {
|
||||||
|
setCurrentTime(0)
|
||||||
|
setSelectedCommentId(null)
|
||||||
|
setAnnotations([])
|
||||||
|
}, [fileData?.id])
|
||||||
|
|
||||||
|
useEffect(() => {
|
||||||
|
setSelectedCommentId(null)
|
||||||
|
setAnnotations([])
|
||||||
|
}, [compareActiveAsset?.id])
|
||||||
|
|
||||||
|
if (isLoading && !fileData) {
|
||||||
|
return <FileDetailSkeleton />
|
||||||
|
}
|
||||||
|
|
||||||
|
if (isError || !fileData || !projectInfo || !teamId) {
|
||||||
|
return <div>{m.file_not_found()}</div>
|
||||||
|
}
|
||||||
|
|
||||||
|
const sidebarFile = isCompareMode ? compareActiveAsset : (fileData as unknown as AssetInfo)
|
||||||
|
const sidebarFileId = sidebarFile?.id ?? activeFileId
|
||||||
|
|
||||||
|
const handleSaveField = (fieldId: string, value: unknown) => {
|
||||||
|
if (!teamId) return
|
||||||
|
patchMetadata(
|
||||||
|
{
|
||||||
|
param: { fileId: sidebarFileId },
|
||||||
|
json: [{ key: fieldId, value }] as InferRequestType<typeof $patchMetadata>['json'],
|
||||||
|
},
|
||||||
|
{
|
||||||
|
onSuccess: () => {
|
||||||
|
queryClient.invalidateQueries({
|
||||||
|
queryKey: ['files', sidebarFileId],
|
||||||
|
})
|
||||||
|
},
|
||||||
|
},
|
||||||
|
)
|
||||||
|
}
|
||||||
|
|
||||||
|
const updateCompareSearch = (patch: Record<string, unknown>) => {
|
||||||
|
navigate({
|
||||||
|
to: '/projects/$projectId/files/$fileId',
|
||||||
|
params: { projectId, fileId },
|
||||||
|
search: (p: Record<string, unknown>) => ({ ...p, ...patch }),
|
||||||
|
})
|
||||||
|
}
|
||||||
|
|
||||||
|
const handleCompareExit = () => {
|
||||||
|
const activeId = compareActiveSide === 'left' ? compareLeftId : compareRightId
|
||||||
|
updateCompareSearch({
|
||||||
|
compare: undefined,
|
||||||
|
cmpLeft: undefined,
|
||||||
|
cmpRight: undefined,
|
||||||
|
cmpActive: undefined,
|
||||||
|
version: activeId,
|
||||||
|
})
|
||||||
|
}
|
||||||
|
|
||||||
|
const handleCommentSelect = (comment: CommentInfo) => {
|
||||||
|
setSelectedCommentId(comment.id || null)
|
||||||
|
const newAnnotations = comment.annotations as Annotation[]
|
||||||
|
if (newAnnotations && newAnnotations.length > 0) {
|
||||||
|
setAnnotations(newAnnotations)
|
||||||
|
} else {
|
||||||
|
setAnnotations([])
|
||||||
|
}
|
||||||
|
|
||||||
|
if (isCompareMode) {
|
||||||
|
if (comment.second !== null && comment.second !== undefined) {
|
||||||
|
setSeekRequest({ second: comment.second, nonce: Date.now() })
|
||||||
|
}
|
||||||
|
return
|
||||||
|
}
|
||||||
|
|
||||||
|
if (comment.second !== null && comment.second !== undefined) {
|
||||||
|
mediaControllerRef.current?.seekTo(comment.second)
|
||||||
|
mediaControllerRef.current?.pause()
|
||||||
|
} else if (newAnnotations && newAnnotations.length > 0) {
|
||||||
|
mediaControllerRef.current?.pause()
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
const handlePlay = () => {
|
||||||
|
setAnnotations([])
|
||||||
|
setSelectedCommentId(null)
|
||||||
|
}
|
||||||
|
|
||||||
|
return (
|
||||||
|
<div className="h-full flex flex-1 flex-col bg-background">
|
||||||
|
<div className="h-full flex flex-1 overflow-hidden">
|
||||||
|
<div className="flex-1 relative">
|
||||||
|
{isFetching && !isCompareMode && (
|
||||||
|
<div className="absolute inset-0 z-10 flex items-center justify-center bg-background/50">
|
||||||
|
<Loader2 className="h-8 w-8 animate-spin text-foreground" />
|
||||||
|
</div>
|
||||||
|
)}
|
||||||
|
{isCompareMode && compareLeftId && compareRightId ? (
|
||||||
|
<CompareViewer
|
||||||
|
versions={versionsDataList ?? []}
|
||||||
|
leftId={compareLeftId}
|
||||||
|
rightId={compareRightId}
|
||||||
|
activeSide={compareActiveSide}
|
||||||
|
annotations={annotations}
|
||||||
|
seekRequest={seekRequest}
|
||||||
|
onActiveSideChange={(side) => updateCompareSearch({ cmpActive: side })}
|
||||||
|
onSwitchVersion={(side, versionId) =>
|
||||||
|
updateCompareSearch(
|
||||||
|
side === 'left' ? { cmpLeft: versionId } : { cmpRight: versionId },
|
||||||
|
)
|
||||||
|
}
|
||||||
|
onExit={handleCompareExit}
|
||||||
|
onActiveAssetChange={setCompareActiveAsset}
|
||||||
|
onPlay={handlePlay}
|
||||||
|
onTimeUpdate={setCurrentTime}
|
||||||
|
/>
|
||||||
|
) : (
|
||||||
|
<FileViewer
|
||||||
|
file={fileData as unknown as AssetInfo}
|
||||||
|
mediaControllerRef={mediaControllerRef}
|
||||||
|
onPlay={handlePlay}
|
||||||
|
onTimeUpdate={setCurrentTime}
|
||||||
|
annotations={annotations}
|
||||||
|
startTime={startTime}
|
||||||
|
>
|
||||||
|
{carouselState.show && (
|
||||||
|
<FileViewerLeftSidebar
|
||||||
|
projectId={projectId}
|
||||||
|
currentAssetId={activeFileId}
|
||||||
|
parentFolderId={parentFolderId}
|
||||||
|
initialFiles={carouselState.files}
|
||||||
|
initialNextCursor={carouselState.nextCursor}
|
||||||
|
/>
|
||||||
|
)}
|
||||||
|
</FileViewer>
|
||||||
|
)}
|
||||||
|
</div>
|
||||||
|
<ResizeHandle
|
||||||
|
onResize={(delta) => {
|
||||||
|
setRightSidebarWidth((prev) => Math.max(300, Math.min(600, prev - delta)))
|
||||||
|
}}
|
||||||
|
className="hidden md:block"
|
||||||
|
/>
|
||||||
|
<div style={{ width: rightSidebarWidth }} className="flex-shrink-0">
|
||||||
|
<FileViewerRightSidebar
|
||||||
|
teamId={teamId}
|
||||||
|
projectId={projectId}
|
||||||
|
file={sidebarFile}
|
||||||
|
onSaveField={handleSaveField}
|
||||||
|
members={members}
|
||||||
|
onCommentSelect={handleCommentSelect}
|
||||||
|
currentTime={currentTime}
|
||||||
|
onTyping={() => {
|
||||||
|
if (isCompareMode) return
|
||||||
|
mediaControllerRef.current?.pause()
|
||||||
|
}}
|
||||||
|
selectedCommentId={selectedCommentId}
|
||||||
|
hideAnnotationControl={sidebarFile?.mediaType?.startsWith('audio/')}
|
||||||
|
/>
|
||||||
|
</div>
|
||||||
|
</div>
|
||||||
|
</div>
|
||||||
|
)
|
||||||
|
}
|
||||||
|
|
||||||
|
export const Route = createLazyFileRoute('/projects/$projectId/files/$fileId')({
|
||||||
|
component: FileViewPage,
|
||||||
|
})
|
||||||
@@ -1,465 +1,6 @@
|
|||||||
import { client } from '@/ui/api/client'
|
import { createFileRoute } from '@tanstack/react-router'
|
||||||
import { FileViewer } from '@/ui/components/file-viewer'
|
|
||||||
import { CompareViewer } from '@/ui/components/compare/compare-viewer'
|
|
||||||
import { pickDefaultCompareVersions } from '@/ui/components/compare/compare-utils'
|
|
||||||
import { FileViewerLeftSidebar } from '@/ui/components/file-viewer-left-sidebar'
|
|
||||||
import { m } from '@/ui/paraglide/messages.js'
|
|
||||||
import { FileViewerRightSidebar } from '@/ui/components/file-viewer-right-sidebar'
|
|
||||||
import { ResizeHandle } from '@/ui/components/resize-handle'
|
|
||||||
import { FileDetailSkeleton } from '@/ui/components/loading-skeletons'
|
|
||||||
import { useMemberStore } from '@/ui/stores/members'
|
|
||||||
import { useTeamContextStore } from '@/ui/stores/team-context'
|
|
||||||
import { useTopNavStore } from '@/ui/stores/top-nav'
|
|
||||||
import { type Annotation } from '@/ui/types'
|
|
||||||
import { useMutation } from '@tanstack/react-query'
|
|
||||||
import { InferRequestType, InferResponseType } from 'hono/client'
|
|
||||||
|
|
||||||
import type { AssetInfo, AssetInfoPaginatedList, CommentInfo } from '@shumai/dtos'
|
|
||||||
import { keepPreviousData, useQuery, useQueryClient } from '@tanstack/react-query'
|
|
||||||
import { createFileRoute, useNavigate } from '@tanstack/react-router'
|
|
||||||
import { Loader2 } from 'lucide-react'
|
|
||||||
import { useEffect, useRef, useState } from 'react'
|
|
||||||
import type { MediaController } from '@/ui/components/viewers/types'
|
|
||||||
|
|
||||||
function FileViewPage() {
|
|
||||||
const { projectId, fileId } = Route.useParams()
|
|
||||||
const search = Route.useSearch()
|
|
||||||
const versionAssetId = search.version
|
|
||||||
const startTime = search.start
|
|
||||||
const activeFileId = versionAssetId || fileId
|
|
||||||
const compareLeftId = search.cmpLeft
|
|
||||||
const compareRightId = search.cmpRight
|
|
||||||
const compareActiveSide = search.cmpActive ?? 'left'
|
|
||||||
const isCompareMode = !!search.compare && !!compareLeftId && !!compareRightId
|
|
||||||
|
|
||||||
const mediaControllerRef = useRef<MediaController | null>(null)
|
|
||||||
const { teamId, ensureTeamIdForProject } = useTeamContextStore()
|
|
||||||
const [rightSidebarWidth, setRightSidebarWidth] = useState(360)
|
|
||||||
const [annotations, setAnnotations] = useState<Annotation[]>([])
|
|
||||||
const [currentTime, setCurrentTime] = useState(0)
|
|
||||||
const [selectedCommentId, setSelectedCommentId] = useState<string | null>(null)
|
|
||||||
const [compareActiveAsset, setCompareActiveAsset] = useState<AssetInfo | null>(null)
|
|
||||||
const [seekRequest, setSeekRequest] = useState<{ second: number; nonce: number } | undefined>(
|
|
||||||
undefined,
|
|
||||||
)
|
|
||||||
const [carouselState, setCarouselState] = useState<{
|
|
||||||
show: boolean
|
|
||||||
files: AssetInfo[]
|
|
||||||
nextCursor?: string
|
|
||||||
folderId?: string
|
|
||||||
}>({ show: false, files: [], nextCursor: undefined, folderId: undefined })
|
|
||||||
const $patchMetadata = client.api.files[':fileId'].metadata.$patch
|
|
||||||
const { mutate: patchMetadata } = useMutation<
|
|
||||||
InferResponseType<typeof $patchMetadata>,
|
|
||||||
Error,
|
|
||||||
InferRequestType<typeof $patchMetadata>
|
|
||||||
>({
|
|
||||||
mutationFn: async (request) => {
|
|
||||||
const res = await $patchMetadata(request)
|
|
||||||
if (!res.ok) throw new Error('Failed to patch metadata')
|
|
||||||
return (await res.json()) as unknown as InferResponseType<typeof $patchMetadata>
|
|
||||||
},
|
|
||||||
})
|
|
||||||
const queryClient = useQueryClient()
|
|
||||||
const { members, fetchMembers } = useMemberStore()
|
|
||||||
|
|
||||||
useEffect(() => {
|
|
||||||
ensureTeamIdForProject(projectId)
|
|
||||||
}, [projectId, ensureTeamIdForProject])
|
|
||||||
|
|
||||||
useEffect(() => {
|
|
||||||
if (teamId) {
|
|
||||||
fetchMembers(teamId, true)
|
|
||||||
}
|
|
||||||
}, [teamId, fetchMembers])
|
|
||||||
|
|
||||||
const {
|
|
||||||
data: stackData,
|
|
||||||
isLoading: isStackLoading,
|
|
||||||
isError: isStackError,
|
|
||||||
isFetching: isStackFetching,
|
|
||||||
} = useQuery({
|
|
||||||
queryKey: ['files', fileId],
|
|
||||||
queryFn: async () => {
|
|
||||||
const res = await client.api.files[':fileId'].$get({
|
|
||||||
param: { fileId: fileId },
|
|
||||||
})
|
|
||||||
if (!res.ok) throw new Error('Failed to fetch stack')
|
|
||||||
return await res.json()
|
|
||||||
},
|
|
||||||
enabled: !!teamId,
|
|
||||||
placeholderData: keepPreviousData,
|
|
||||||
})
|
|
||||||
|
|
||||||
const {
|
|
||||||
data: versionData,
|
|
||||||
isLoading: isVersionLoading,
|
|
||||||
isError: isVersionError,
|
|
||||||
isFetching: isVersionFetching,
|
|
||||||
} = useQuery({
|
|
||||||
queryKey: ['files', versionAssetId],
|
|
||||||
queryFn: async () => {
|
|
||||||
const res = await client.api.files[':fileId'].$get({
|
|
||||||
param: { fileId: versionAssetId! },
|
|
||||||
})
|
|
||||||
if (!res.ok) throw new Error('Failed to fetch version')
|
|
||||||
return await res.json()
|
|
||||||
},
|
|
||||||
enabled: !!teamId && !!versionAssetId,
|
|
||||||
placeholderData: keepPreviousData,
|
|
||||||
})
|
|
||||||
|
|
||||||
const { data: versionsList } = useQuery({
|
|
||||||
queryKey: ['version_stacks', fileId, 'versions'],
|
|
||||||
queryFn: async () => {
|
|
||||||
const res = await client.api.version_stacks[':stackId'].versions.$get({
|
|
||||||
param: { stackId: fileId },
|
|
||||||
})
|
|
||||||
if (!res.ok) throw new Error('Failed to fetch versions')
|
|
||||||
return await res.json()
|
|
||||||
},
|
|
||||||
enabled: !!projectId && !!fileId && (!!versionAssetId || isCompareMode),
|
|
||||||
})
|
|
||||||
|
|
||||||
const { data: projectInfo } = useQuery({
|
|
||||||
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()
|
|
||||||
},
|
|
||||||
})
|
|
||||||
|
|
||||||
const navigate = useNavigate()
|
|
||||||
const { setProjectState, clearProjectState } = useTopNavStore()
|
|
||||||
|
|
||||||
const isLoading = isStackLoading || (!!versionAssetId && isVersionLoading)
|
|
||||||
const isError = isStackError || (!!versionAssetId && isVersionError)
|
|
||||||
const isFetching = isStackFetching || (!!versionAssetId && isVersionFetching)
|
|
||||||
const fileData = versionData || stackData
|
|
||||||
const versionsDataList = versionAssetId ? versionsList : stackData?.versionStack?.versions
|
|
||||||
|
|
||||||
useEffect(() => {
|
|
||||||
if (fileData && projectInfo && teamId) {
|
|
||||||
setProjectState({
|
|
||||||
teamId,
|
|
||||||
projectId,
|
|
||||||
projectName: projectInfo.name ?? '',
|
|
||||||
ancestorFolders: fileData.ancestorFolders ?? [],
|
|
||||||
currentAsset: {
|
|
||||||
name: fileData.name,
|
|
||||||
type: 'file',
|
|
||||||
version: versionsDataList
|
|
||||||
? (versionsDataList.find((v: { id: string }) => v.id === activeFileId)?.version ??
|
|
||||||
versionsDataList.length)
|
|
||||||
: undefined,
|
|
||||||
mediaType: fileData.mediaType,
|
|
||||||
},
|
|
||||||
isRootFolder: false,
|
|
||||||
fileId,
|
|
||||||
downloadInfo: {
|
|
||||||
originalKey: fileData.media?.original?.key,
|
|
||||||
videoTranscodes: fileData.media?.videoTranscodes?.map((t) => ({
|
|
||||||
key: t.key,
|
|
||||||
width: t.width,
|
|
||||||
height: t.height,
|
|
||||||
isRaw: t.isRaw,
|
|
||||||
})),
|
|
||||||
},
|
|
||||||
versions: versionsDataList,
|
|
||||||
compareMode: isCompareMode,
|
|
||||||
canCompareVersions: (versionsDataList?.length ?? 0) >= 2,
|
|
||||||
onCompareVersions: () => {
|
|
||||||
const pair = pickDefaultCompareVersions(versionsDataList)
|
|
||||||
if (!pair) return
|
|
||||||
navigate({
|
|
||||||
to: '/projects/$projectId/files/$fileId',
|
|
||||||
params: { projectId, fileId },
|
|
||||||
search: (p: Record<string, unknown>) => ({
|
|
||||||
...p,
|
|
||||||
version: undefined,
|
|
||||||
compare: true,
|
|
||||||
cmpLeft: pair.left.id,
|
|
||||||
cmpRight: pair.right.id,
|
|
||||||
cmpActive: 'left' as const,
|
|
||||||
}),
|
|
||||||
})
|
|
||||||
},
|
|
||||||
onFolderClick: (id: string) => {
|
|
||||||
navigate({
|
|
||||||
to: '/projects/$projectId/folders/$folderId',
|
|
||||||
params: { projectId, folderId: id },
|
|
||||||
})
|
|
||||||
},
|
|
||||||
})
|
|
||||||
}
|
|
||||||
|
|
||||||
return () => clearProjectState()
|
|
||||||
}, [
|
|
||||||
teamId,
|
|
||||||
projectId,
|
|
||||||
projectInfo,
|
|
||||||
fileData,
|
|
||||||
versionsDataList,
|
|
||||||
activeFileId,
|
|
||||||
fileId,
|
|
||||||
isCompareMode,
|
|
||||||
setProjectState,
|
|
||||||
clearProjectState,
|
|
||||||
navigate,
|
|
||||||
])
|
|
||||||
|
|
||||||
const parentFolderId = fileData?.ancestorFolders?.[0]?.id ?? projectInfo?.rootFolder ?? ''
|
|
||||||
|
|
||||||
useEffect(() => {
|
|
||||||
if (!parentFolderId || !activeFileId) return
|
|
||||||
if (carouselState.folderId === parentFolderId) {
|
|
||||||
return
|
|
||||||
}
|
|
||||||
|
|
||||||
let isMounted = true
|
|
||||||
|
|
||||||
const fetchCarouselData = async () => {
|
|
||||||
try {
|
|
||||||
let cursor = ''
|
|
||||||
let found = false
|
|
||||||
const allFiles: AssetInfo[] = []
|
|
||||||
let lastCursor: string | undefined = undefined
|
|
||||||
|
|
||||||
for (let batch = 0; batch < 5; batch++) {
|
|
||||||
const res = await client.api.folders[':folderId'].search.$post({
|
|
||||||
param: { folderId: parentFolderId },
|
|
||||||
json: {
|
|
||||||
assetType: 'file',
|
|
||||||
after: cursor,
|
|
||||||
first: 200,
|
|
||||||
recursively: false,
|
|
||||||
conditions: [],
|
|
||||||
},
|
|
||||||
})
|
|
||||||
if (!res.ok) {
|
|
||||||
throw new Error('Failed to search parent folder for carousel')
|
|
||||||
}
|
|
||||||
const result = (await res.json()) as unknown as AssetInfoPaginatedList
|
|
||||||
const batchFiles = (result.data || []) as AssetInfo[]
|
|
||||||
allFiles.push(...batchFiles)
|
|
||||||
|
|
||||||
if (batchFiles.some((f) => f.id === activeFileId)) {
|
|
||||||
found = true
|
|
||||||
lastCursor = result.pageInfo?.cursor || undefined
|
|
||||||
break
|
|
||||||
}
|
|
||||||
if (!result.pageInfo?.cursor || batchFiles.length < 200) {
|
|
||||||
break
|
|
||||||
}
|
|
||||||
cursor = result.pageInfo.cursor
|
|
||||||
}
|
|
||||||
|
|
||||||
if (isMounted) {
|
|
||||||
if (found) {
|
|
||||||
setCarouselState({
|
|
||||||
show: true,
|
|
||||||
files: allFiles,
|
|
||||||
nextCursor: lastCursor,
|
|
||||||
folderId: parentFolderId,
|
|
||||||
})
|
|
||||||
} else {
|
|
||||||
setCarouselState({
|
|
||||||
show: false,
|
|
||||||
files: [],
|
|
||||||
nextCursor: undefined,
|
|
||||||
folderId: parentFolderId,
|
|
||||||
})
|
|
||||||
}
|
|
||||||
}
|
|
||||||
} catch (err) {
|
|
||||||
console.error(err)
|
|
||||||
if (isMounted) {
|
|
||||||
setCarouselState({
|
|
||||||
show: false,
|
|
||||||
files: [],
|
|
||||||
nextCursor: undefined,
|
|
||||||
folderId: parentFolderId,
|
|
||||||
})
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
fetchCarouselData()
|
|
||||||
|
|
||||||
return () => {
|
|
||||||
isMounted = false
|
|
||||||
}
|
|
||||||
}, [parentFolderId, activeFileId, carouselState.folderId])
|
|
||||||
|
|
||||||
useEffect(() => {
|
|
||||||
setCurrentTime(0)
|
|
||||||
setSelectedCommentId(null)
|
|
||||||
setAnnotations([])
|
|
||||||
}, [fileData?.id])
|
|
||||||
|
|
||||||
useEffect(() => {
|
|
||||||
setSelectedCommentId(null)
|
|
||||||
setAnnotations([])
|
|
||||||
}, [compareActiveAsset?.id])
|
|
||||||
|
|
||||||
if (isLoading && !fileData) {
|
|
||||||
return <FileDetailSkeleton />
|
|
||||||
}
|
|
||||||
|
|
||||||
if (isError || !fileData || !projectInfo || !teamId) {
|
|
||||||
return <div>{m.file_not_found()}</div>
|
|
||||||
}
|
|
||||||
|
|
||||||
const sidebarFile = isCompareMode ? compareActiveAsset : (fileData as unknown as AssetInfo)
|
|
||||||
const sidebarFileId = sidebarFile?.id ?? activeFileId
|
|
||||||
|
|
||||||
const handleSaveField = (fieldId: string, value: unknown) => {
|
|
||||||
if (!teamId) return
|
|
||||||
patchMetadata(
|
|
||||||
{
|
|
||||||
param: { fileId: sidebarFileId },
|
|
||||||
json: [{ key: fieldId, value }] as InferRequestType<typeof $patchMetadata>['json'],
|
|
||||||
},
|
|
||||||
{
|
|
||||||
onSuccess: () => {
|
|
||||||
queryClient.invalidateQueries({
|
|
||||||
queryKey: ['files', sidebarFileId],
|
|
||||||
})
|
|
||||||
},
|
|
||||||
},
|
|
||||||
)
|
|
||||||
}
|
|
||||||
|
|
||||||
const updateCompareSearch = (patch: Record<string, unknown>) => {
|
|
||||||
navigate({
|
|
||||||
to: '/projects/$projectId/files/$fileId',
|
|
||||||
params: { projectId, fileId },
|
|
||||||
search: (p: Record<string, unknown>) => ({ ...p, ...patch }),
|
|
||||||
})
|
|
||||||
}
|
|
||||||
|
|
||||||
const handleCompareExit = () => {
|
|
||||||
const activeId = compareActiveSide === 'left' ? compareLeftId : compareRightId
|
|
||||||
updateCompareSearch({
|
|
||||||
compare: undefined,
|
|
||||||
cmpLeft: undefined,
|
|
||||||
cmpRight: undefined,
|
|
||||||
cmpActive: undefined,
|
|
||||||
version: activeId,
|
|
||||||
})
|
|
||||||
}
|
|
||||||
|
|
||||||
const handleCommentSelect = (comment: CommentInfo) => {
|
|
||||||
setSelectedCommentId(comment.id || null)
|
|
||||||
const newAnnotations = comment.annotations as Annotation[]
|
|
||||||
if (newAnnotations && newAnnotations.length > 0) {
|
|
||||||
setAnnotations(newAnnotations)
|
|
||||||
} else {
|
|
||||||
setAnnotations([])
|
|
||||||
}
|
|
||||||
|
|
||||||
if (isCompareMode) {
|
|
||||||
if (comment.second !== null && comment.second !== undefined) {
|
|
||||||
setSeekRequest({ second: comment.second, nonce: Date.now() })
|
|
||||||
}
|
|
||||||
return
|
|
||||||
}
|
|
||||||
|
|
||||||
if (comment.second !== null && comment.second !== undefined) {
|
|
||||||
mediaControllerRef.current?.seekTo(comment.second)
|
|
||||||
mediaControllerRef.current?.pause()
|
|
||||||
} else if (newAnnotations && newAnnotations.length > 0) {
|
|
||||||
mediaControllerRef.current?.pause()
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
const handlePlay = () => {
|
|
||||||
setAnnotations([])
|
|
||||||
setSelectedCommentId(null)
|
|
||||||
}
|
|
||||||
|
|
||||||
return (
|
|
||||||
<div className="h-full flex flex-1 flex-col bg-background">
|
|
||||||
<div className="h-full flex flex-1 overflow-hidden">
|
|
||||||
<div className="flex-1 relative">
|
|
||||||
{isFetching && !isCompareMode && (
|
|
||||||
<div className="absolute inset-0 z-10 flex items-center justify-center bg-background/50">
|
|
||||||
<Loader2 className="h-8 w-8 animate-spin text-foreground" />
|
|
||||||
</div>
|
|
||||||
)}
|
|
||||||
{isCompareMode && compareLeftId && compareRightId ? (
|
|
||||||
<CompareViewer
|
|
||||||
versions={versionsDataList ?? []}
|
|
||||||
leftId={compareLeftId}
|
|
||||||
rightId={compareRightId}
|
|
||||||
activeSide={compareActiveSide}
|
|
||||||
annotations={annotations}
|
|
||||||
seekRequest={seekRequest}
|
|
||||||
onActiveSideChange={(side) => updateCompareSearch({ cmpActive: side })}
|
|
||||||
onSwitchVersion={(side, versionId) =>
|
|
||||||
updateCompareSearch(
|
|
||||||
side === 'left' ? { cmpLeft: versionId } : { cmpRight: versionId },
|
|
||||||
)
|
|
||||||
}
|
|
||||||
onExit={handleCompareExit}
|
|
||||||
onActiveAssetChange={setCompareActiveAsset}
|
|
||||||
onPlay={handlePlay}
|
|
||||||
onTimeUpdate={setCurrentTime}
|
|
||||||
/>
|
|
||||||
) : (
|
|
||||||
<FileViewer
|
|
||||||
file={fileData as unknown as AssetInfo}
|
|
||||||
mediaControllerRef={mediaControllerRef}
|
|
||||||
onPlay={handlePlay}
|
|
||||||
onTimeUpdate={setCurrentTime}
|
|
||||||
annotations={annotations}
|
|
||||||
startTime={startTime}
|
|
||||||
>
|
|
||||||
{carouselState.show && (
|
|
||||||
<FileViewerLeftSidebar
|
|
||||||
projectId={projectId}
|
|
||||||
currentAssetId={activeFileId}
|
|
||||||
parentFolderId={parentFolderId}
|
|
||||||
initialFiles={carouselState.files}
|
|
||||||
initialNextCursor={carouselState.nextCursor}
|
|
||||||
/>
|
|
||||||
)}
|
|
||||||
</FileViewer>
|
|
||||||
)}
|
|
||||||
</div>
|
|
||||||
<ResizeHandle
|
|
||||||
onResize={(delta) => {
|
|
||||||
setRightSidebarWidth((prev) => Math.max(300, Math.min(600, prev - delta)))
|
|
||||||
}}
|
|
||||||
className="hidden md:block"
|
|
||||||
/>
|
|
||||||
<div style={{ width: rightSidebarWidth }} className="flex-shrink-0">
|
|
||||||
<FileViewerRightSidebar
|
|
||||||
teamId={teamId}
|
|
||||||
projectId={projectId}
|
|
||||||
file={sidebarFile}
|
|
||||||
onSaveField={handleSaveField}
|
|
||||||
members={members}
|
|
||||||
onCommentSelect={handleCommentSelect}
|
|
||||||
currentTime={currentTime}
|
|
||||||
onTyping={() => {
|
|
||||||
if (isCompareMode) return
|
|
||||||
mediaControllerRef.current?.pause()
|
|
||||||
}}
|
|
||||||
selectedCommentId={selectedCommentId}
|
|
||||||
hideAnnotationControl={sidebarFile?.mediaType?.startsWith('audio/')}
|
|
||||||
/>
|
|
||||||
</div>
|
|
||||||
</div>
|
|
||||||
</div>
|
|
||||||
)
|
|
||||||
}
|
|
||||||
|
|
||||||
export const Route = createFileRoute('/projects/$projectId/files/$fileId')({
|
export const Route = createFileRoute('/projects/$projectId/files/$fileId')({
|
||||||
component: FileViewPage,
|
|
||||||
validateSearch: (search: Record<string, unknown>) => {
|
validateSearch: (search: Record<string, unknown>) => {
|
||||||
return {
|
return {
|
||||||
version: (search.version as string) || undefined,
|
version: (search.version as string) || undefined,
|
||||||
|
|||||||
@@ -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 './$folderId'
|
||||||
|
|
||||||
|
function FolderPage() {
|
||||||
|
const { projectId, folderId } = 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={folderId}
|
||||||
|
rootFolderId={rootFolderId}
|
||||||
|
/>
|
||||||
|
)
|
||||||
|
}
|
||||||
|
|
||||||
|
export const Route = createLazyFileRoute('/projects/$projectId/folders/$folderId')({
|
||||||
|
component: FolderPage,
|
||||||
|
})
|
||||||
@@ -1,12 +1,8 @@
|
|||||||
import { client } from '@/ui/api/client'
|
import { client } from '@/ui/api/client'
|
||||||
import FileSystemManager from '@/ui/components/file-system-manager'
|
|
||||||
import { ProjectFolderSkeleton } from '@/ui/components/loading-skeletons'
|
import { ProjectFolderSkeleton } from '@/ui/components/loading-skeletons'
|
||||||
import { useTeamContextStore } from '@/ui/stores/team-context'
|
|
||||||
import { useQuery, useSuspenseQuery } from '@tanstack/react-query'
|
|
||||||
import { createFileRoute } from '@tanstack/react-router'
|
import { createFileRoute } from '@tanstack/react-router'
|
||||||
import { useEffect } from 'react'
|
|
||||||
|
|
||||||
const projectInfoQueryOptions = (projectId: string) => ({
|
export const projectInfoQueryOptions = (projectId: string) => ({
|
||||||
queryKey: ['projects', projectId],
|
queryKey: ['projects', projectId],
|
||||||
queryFn: async () => {
|
queryFn: async () => {
|
||||||
const res = await client.api.projects[':projectId'].$get({
|
const res = await client.api.projects[':projectId'].$get({
|
||||||
@@ -17,47 +13,7 @@ const projectInfoQueryOptions = (projectId: string) => ({
|
|||||||
},
|
},
|
||||||
})
|
})
|
||||||
|
|
||||||
function FolderPage() {
|
|
||||||
const { projectId, folderId } = 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={folderId}
|
|
||||||
rootFolderId={rootFolderId}
|
|
||||||
/>
|
|
||||||
)
|
|
||||||
}
|
|
||||||
|
|
||||||
export const Route = createFileRoute('/projects/$projectId/folders/$folderId')({
|
export const Route = createFileRoute('/projects/$projectId/folders/$folderId')({
|
||||||
component: FolderPage,
|
|
||||||
loader: ({ context: { queryClient }, params: { projectId } }) =>
|
loader: ({ context: { queryClient }, params: { projectId } }) =>
|
||||||
queryClient.ensureQueryData(projectInfoQueryOptions(projectId)),
|
queryClient.ensureQueryData(projectInfoQueryOptions(projectId)),
|
||||||
pendingComponent: () => <ProjectFolderSkeleton />,
|
pendingComponent: () => <ProjectFolderSkeleton />,
|
||||||
|
|||||||
@@ -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 './index'
|
||||||
|
|
||||||
|
function ProjectPage() {
|
||||||
|
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! },
|
||||||
|
})
|
||||||
|
if (!res.ok) throw new Error('failed to fetch folder')
|
||||||
|
return await res.json()
|
||||||
|
},
|
||||||
|
enabled: !!rootFolderId,
|
||||||
|
})
|
||||||
|
|
||||||
|
if (!teamId || !rootFolderId || !rootFolder) {
|
||||||
|
return <ProjectFolderSkeleton />
|
||||||
|
}
|
||||||
|
|
||||||
|
return (
|
||||||
|
<FileSystemManager
|
||||||
|
teamId={teamId}
|
||||||
|
projectId={projectId}
|
||||||
|
projectName={projectInfo.name ?? ''}
|
||||||
|
assetId={rootFolderId}
|
||||||
|
rootFolderId={rootFolderId}
|
||||||
|
/>
|
||||||
|
)
|
||||||
|
}
|
||||||
|
|
||||||
|
export const Route = createLazyFileRoute('/projects/$projectId/')({
|
||||||
|
component: ProjectPage,
|
||||||
|
})
|
||||||
@@ -1,12 +1,8 @@
|
|||||||
import { client } from '@/ui/api/client'
|
import { client } from '@/ui/api/client'
|
||||||
import FileSystemManager from '@/ui/components/file-system-manager'
|
|
||||||
import { ProjectFolderSkeleton } from '@/ui/components/loading-skeletons'
|
import { ProjectFolderSkeleton } from '@/ui/components/loading-skeletons'
|
||||||
import { useTeamContextStore } from '@/ui/stores/team-context'
|
|
||||||
import { useQuery, useSuspenseQuery } from '@tanstack/react-query'
|
|
||||||
import { createFileRoute } from '@tanstack/react-router'
|
import { createFileRoute } from '@tanstack/react-router'
|
||||||
import { useEffect } from 'react'
|
|
||||||
|
|
||||||
const projectInfoQueryOptions = (projectId: string) => ({
|
export const projectInfoQueryOptions = (projectId: string) => ({
|
||||||
queryKey: ['projects', projectId],
|
queryKey: ['projects', projectId],
|
||||||
queryFn: async () => {
|
queryFn: async () => {
|
||||||
const res = await client.api.projects[':projectId'].$get({
|
const res = await client.api.projects[':projectId'].$get({
|
||||||
@@ -17,47 +13,7 @@ const projectInfoQueryOptions = (projectId: string) => ({
|
|||||||
},
|
},
|
||||||
})
|
})
|
||||||
|
|
||||||
function ProjectPage() {
|
|
||||||
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! },
|
|
||||||
})
|
|
||||||
if (!res.ok) throw new Error('failed to fetch folder')
|
|
||||||
return await res.json()
|
|
||||||
},
|
|
||||||
enabled: !!rootFolderId,
|
|
||||||
})
|
|
||||||
|
|
||||||
if (!teamId || !rootFolderId || !rootFolder) {
|
|
||||||
return <ProjectFolderSkeleton />
|
|
||||||
}
|
|
||||||
|
|
||||||
return (
|
|
||||||
<FileSystemManager
|
|
||||||
teamId={teamId}
|
|
||||||
projectId={projectId}
|
|
||||||
projectName={projectInfo.name ?? ''}
|
|
||||||
assetId={rootFolderId}
|
|
||||||
rootFolderId={rootFolderId}
|
|
||||||
/>
|
|
||||||
)
|
|
||||||
}
|
|
||||||
|
|
||||||
export const Route = createFileRoute('/projects/$projectId/')({
|
export const Route = createFileRoute('/projects/$projectId/')({
|
||||||
component: ProjectPage,
|
|
||||||
loader: ({ context: { queryClient }, params: { projectId } }) =>
|
loader: ({ context: { queryClient }, params: { projectId } }) =>
|
||||||
queryClient.ensureQueryData(projectInfoQueryOptions(projectId)),
|
queryClient.ensureQueryData(projectInfoQueryOptions(projectId)),
|
||||||
pendingComponent: () => <ProjectFolderSkeleton />,
|
pendingComponent: () => <ProjectFolderSkeleton />,
|
||||||
|
|||||||
@@ -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 './recently-deleted'
|
||||||
|
|
||||||
|
function RecentlyDeletedPage() {
|
||||||
|
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="recently-deleted"
|
||||||
|
rootFolderId={rootFolderId}
|
||||||
|
/>
|
||||||
|
)
|
||||||
|
}
|
||||||
|
|
||||||
|
export const Route = createLazyFileRoute('/projects/$projectId/recently-deleted')({
|
||||||
|
component: RecentlyDeletedPage,
|
||||||
|
})
|
||||||
@@ -1,12 +1,8 @@
|
|||||||
import { client } from '@/ui/api/client'
|
import { client } from '@/ui/api/client'
|
||||||
import FileSystemManager from '@/ui/components/file-system-manager'
|
|
||||||
import { ProjectFolderSkeleton } from '@/ui/components/loading-skeletons'
|
import { ProjectFolderSkeleton } from '@/ui/components/loading-skeletons'
|
||||||
import { useTeamContextStore } from '@/ui/stores/team-context'
|
|
||||||
import { useQuery, useSuspenseQuery } from '@tanstack/react-query'
|
|
||||||
import { createFileRoute } from '@tanstack/react-router'
|
import { createFileRoute } from '@tanstack/react-router'
|
||||||
import { useEffect } from 'react'
|
|
||||||
|
|
||||||
const projectInfoQueryOptions = (projectId: string) => ({
|
export const projectInfoQueryOptions = (projectId: string) => ({
|
||||||
queryKey: ['projects', projectId],
|
queryKey: ['projects', projectId],
|
||||||
queryFn: async () => {
|
queryFn: async () => {
|
||||||
const res = await client.api.projects[':projectId'].$get({
|
const res = await client.api.projects[':projectId'].$get({
|
||||||
@@ -17,47 +13,7 @@ const projectInfoQueryOptions = (projectId: string) => ({
|
|||||||
},
|
},
|
||||||
})
|
})
|
||||||
|
|
||||||
function RecentlyDeletedPage() {
|
|
||||||
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="recently-deleted"
|
|
||||||
rootFolderId={rootFolderId}
|
|
||||||
/>
|
|
||||||
)
|
|
||||||
}
|
|
||||||
|
|
||||||
export const Route = createFileRoute('/projects/$projectId/recently-deleted')({
|
export const Route = createFileRoute('/projects/$projectId/recently-deleted')({
|
||||||
component: RecentlyDeletedPage,
|
|
||||||
loader: ({ context: { queryClient }, params: { projectId } }) =>
|
loader: ({ context: { queryClient }, params: { projectId } }) =>
|
||||||
queryClient.ensureQueryData(projectInfoQueryOptions(projectId)),
|
queryClient.ensureQueryData(projectInfoQueryOptions(projectId)),
|
||||||
pendingComponent: () => <ProjectFolderSkeleton />,
|
pendingComponent: () => <ProjectFolderSkeleton />,
|
||||||
|
|||||||
@@ -0,0 +1,24 @@
|
|||||||
|
import { createLazyFileRoute } from '@tanstack/react-router'
|
||||||
|
import { PublicShareManager } from '@/ui/components/public-share-manager'
|
||||||
|
|
||||||
|
function PublicShareFilePage() {
|
||||||
|
const { shareId, fileId } = Route.useParams()
|
||||||
|
const { start, version, compare, cmpLeft, cmpRight, cmpActive } = Route.useSearch()
|
||||||
|
|
||||||
|
return (
|
||||||
|
<PublicShareManager
|
||||||
|
shareId={shareId}
|
||||||
|
initialFileId={fileId}
|
||||||
|
startTime={start}
|
||||||
|
versionId={version}
|
||||||
|
compare={compare}
|
||||||
|
compareLeftId={cmpLeft}
|
||||||
|
compareRightId={cmpRight}
|
||||||
|
compareActiveSide={cmpActive}
|
||||||
|
/>
|
||||||
|
)
|
||||||
|
}
|
||||||
|
|
||||||
|
export const Route = createLazyFileRoute('/share/$shareId/files/$fileId')({
|
||||||
|
component: PublicShareFilePage,
|
||||||
|
})
|
||||||
@@ -1,26 +1,6 @@
|
|||||||
import { PublicShareManager } from '@/ui/components/public-share-manager'
|
|
||||||
import { createFileRoute } from '@tanstack/react-router'
|
import { createFileRoute } from '@tanstack/react-router'
|
||||||
|
|
||||||
function PublicShareFilePage() {
|
|
||||||
const { shareId, fileId } = Route.useParams()
|
|
||||||
const { start, version, compare, cmpLeft, cmpRight, cmpActive } = Route.useSearch()
|
|
||||||
|
|
||||||
return (
|
|
||||||
<PublicShareManager
|
|
||||||
shareId={shareId}
|
|
||||||
initialFileId={fileId}
|
|
||||||
startTime={start}
|
|
||||||
versionId={version}
|
|
||||||
compare={compare}
|
|
||||||
compareLeftId={cmpLeft}
|
|
||||||
compareRightId={cmpRight}
|
|
||||||
compareActiveSide={cmpActive}
|
|
||||||
/>
|
|
||||||
)
|
|
||||||
}
|
|
||||||
|
|
||||||
export const Route = createFileRoute('/share/$shareId/files/$fileId')({
|
export const Route = createFileRoute('/share/$shareId/files/$fileId')({
|
||||||
component: PublicShareFilePage,
|
|
||||||
validateSearch: (search: Record<string, unknown>) => {
|
validateSearch: (search: Record<string, unknown>) => {
|
||||||
return {
|
return {
|
||||||
start: search.start ? Number(search.start) : undefined,
|
start: search.start ? Number(search.start) : undefined,
|
||||||
|
|||||||
@@ -0,0 +1,12 @@
|
|||||||
|
import { createLazyFileRoute } from '@tanstack/react-router'
|
||||||
|
import { PublicShareManager } from '@/ui/components/public-share-manager'
|
||||||
|
|
||||||
|
function PublicShareFolderPage() {
|
||||||
|
const { shareId, folderId } = Route.useParams()
|
||||||
|
|
||||||
|
return <PublicShareManager shareId={shareId} initialFolderId={folderId} />
|
||||||
|
}
|
||||||
|
|
||||||
|
export const Route = createLazyFileRoute('/share/$shareId/folders/$folderId')({
|
||||||
|
component: PublicShareFolderPage,
|
||||||
|
})
|
||||||
@@ -1,12 +1,3 @@
|
|||||||
import { PublicShareManager } from '@/ui/components/public-share-manager'
|
|
||||||
import { createFileRoute } from '@tanstack/react-router'
|
import { createFileRoute } from '@tanstack/react-router'
|
||||||
|
|
||||||
function PublicShareFolderPage() {
|
export const Route = createFileRoute('/share/$shareId/folders/$folderId')({})
|
||||||
const { shareId, folderId } = Route.useParams()
|
|
||||||
|
|
||||||
return <PublicShareManager shareId={shareId} initialFolderId={folderId} />
|
|
||||||
}
|
|
||||||
|
|
||||||
export const Route = createFileRoute('/share/$shareId/folders/$folderId')({
|
|
||||||
component: PublicShareFolderPage,
|
|
||||||
})
|
|
||||||
|
|||||||
@@ -0,0 +1,12 @@
|
|||||||
|
import { createLazyFileRoute } from '@tanstack/react-router'
|
||||||
|
import { PublicShareManager } from '@/ui/components/public-share-manager'
|
||||||
|
|
||||||
|
function PublicShareIndexPage() {
|
||||||
|
const { shareId } = Route.useParams()
|
||||||
|
|
||||||
|
return <PublicShareManager shareId={shareId} />
|
||||||
|
}
|
||||||
|
|
||||||
|
export const Route = createLazyFileRoute('/share/$shareId/')({
|
||||||
|
component: PublicShareIndexPage,
|
||||||
|
})
|
||||||
@@ -1,12 +1,3 @@
|
|||||||
import { PublicShareManager } from '@/ui/components/public-share-manager'
|
|
||||||
import { createFileRoute } from '@tanstack/react-router'
|
import { createFileRoute } from '@tanstack/react-router'
|
||||||
|
|
||||||
function PublicShareIndexPage() {
|
export const Route = createFileRoute('/share/$shareId/')({})
|
||||||
const { shareId } = Route.useParams()
|
|
||||||
|
|
||||||
return <PublicShareManager shareId={shareId} />
|
|
||||||
}
|
|
||||||
|
|
||||||
export const Route = createFileRoute('/share/$shareId/')({
|
|
||||||
component: PublicShareIndexPage,
|
|
||||||
})
|
|
||||||
|
|||||||
@@ -1,4 +1,5 @@
|
|||||||
{
|
{
|
||||||
"routesDirectory": "routes",
|
"routesDirectory": "routes",
|
||||||
"generatedRouteTree": "routeTree.gen.ts"
|
"generatedRouteTree": "routeTree.gen.ts",
|
||||||
|
"autoCodeSplitting": true
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user