mirror of
https://github.com/shumaiOne/shumai.git
synced 2026-12-04 23:24:21 +00:00
feat(ui): unify header bar into a single route-aware component in __root.tsx
This commit is contained in:
@@ -12,7 +12,6 @@ import { useUserMetadataStore } from '@/ui/stores/user-metadata'
|
|||||||
import { useInfiniteQuery, useQuery, useQueryClient } from '@tanstack/react-query'
|
import { useInfiniteQuery, useQuery, useQueryClient } from '@tanstack/react-query'
|
||||||
import { useNavigate } from '@tanstack/react-router'
|
import { useNavigate } from '@tanstack/react-router'
|
||||||
import { useEffect, useMemo, useRef, useState } from 'react'
|
import { useEffect, useMemo, useRef, useState } from 'react'
|
||||||
import { BreadcrumbNav } from './breadcrumb-nav'
|
|
||||||
import { FileBrowser } from './file-browser/file-browser'
|
import { FileBrowser } from './file-browser/file-browser'
|
||||||
import { FileViewerRightSidebar } from './file-viewer-right-sidebar'
|
import { FileViewerRightSidebar } from './file-viewer-right-sidebar'
|
||||||
import { FolderTree } from './folder-tree'
|
import { FolderTree } from './folder-tree'
|
||||||
@@ -106,29 +105,12 @@ export default function FileSystemManager({
|
|||||||
fileListRightSidebarCollapsed: isRightSidebarCollapsed,
|
fileListRightSidebarCollapsed: isRightSidebarCollapsed,
|
||||||
setFileListRightSidebarCollapsed: setIsRightSidebarCollapsed,
|
setFileListRightSidebarCollapsed: setIsRightSidebarCollapsed,
|
||||||
viewModes,
|
viewModes,
|
||||||
setViewMode,
|
|
||||||
} = useUiStore()
|
} = useUiStore()
|
||||||
|
|
||||||
const displayStyle = viewModes[projectId] ?? 'card'
|
const displayStyle = viewModes[projectId] ?? 'card'
|
||||||
const setDisplayStyle = (style: 'card' | 'list') => {
|
|
||||||
setViewMode(projectId, style)
|
|
||||||
}
|
|
||||||
|
|
||||||
const containerRef = useRef<HTMLDivElement>(null)
|
const containerRef = useRef<HTMLDivElement>(null)
|
||||||
|
|
||||||
const { data: folderInfo } = isRecentlyDeleted
|
|
||||||
? { data: undefined }
|
|
||||||
: useQuery({
|
|
||||||
queryKey: ['folders', teamId, assetId],
|
|
||||||
queryFn: async () => {
|
|
||||||
const res = await client.api.teams[':teamId'].folders[':folderId'].$get({
|
|
||||||
param: { teamId: teamId, folderId: assetId },
|
|
||||||
})
|
|
||||||
if (!res.ok) throw new Error('failed to fetch folder')
|
|
||||||
return (await res.json()) as unknown as AssetInfo
|
|
||||||
},
|
|
||||||
})
|
|
||||||
|
|
||||||
const {
|
const {
|
||||||
data: foldersData,
|
data: foldersData,
|
||||||
fetchNextPage: fetchNextFoldersPage,
|
fetchNextPage: fetchNextFoldersPage,
|
||||||
@@ -358,26 +340,7 @@ export default function FileSystemManager({
|
|||||||
onDragStart={handleDragStart}
|
onDragStart={handleDragStart}
|
||||||
onDragEnd={handleDragEnd}
|
onDragEnd={handleDragEnd}
|
||||||
>
|
>
|
||||||
<div className="flex h-screen flex-col bg-background">
|
<div className="flex h-full flex-col bg-background">
|
||||||
<BreadcrumbNav
|
|
||||||
teamId={teamId}
|
|
||||||
projectId={projectId}
|
|
||||||
projectName={projectName}
|
|
||||||
ancestorFolders={folderInfo?.ancestorFolders ?? []}
|
|
||||||
currentAsset={
|
|
||||||
isRecentlyDeleted
|
|
||||||
? { name: 'Recently Deleted', type: 'folder' }
|
|
||||||
: { name: folderInfo?.name, type: 'folder' }
|
|
||||||
}
|
|
||||||
isRootFolder={assetId === rootFolderId}
|
|
||||||
displayStyle={displayStyle}
|
|
||||||
onDisplayStyleChange={setDisplayStyle}
|
|
||||||
isLeftSidebarCollapsed={isLeftSidebarCollapsed}
|
|
||||||
onLeftSidebarToggle={() => setIsLeftSidebarCollapsed(!isLeftSidebarCollapsed)}
|
|
||||||
isRightSidebarCollapsed={isRightSidebarCollapsed}
|
|
||||||
onRightSidebarToggle={() => setIsRightSidebarCollapsed(!isRightSidebarCollapsed)}
|
|
||||||
/>
|
|
||||||
|
|
||||||
<div ref={containerRef} className="flex flex-1 overflow-hidden relative">
|
<div ref={containerRef} className="flex flex-1 overflow-hidden relative">
|
||||||
{!isLeftSidebarCollapsed && (
|
{!isLeftSidebarCollapsed && (
|
||||||
<div
|
<div
|
||||||
|
|||||||
@@ -0,0 +1,179 @@
|
|||||||
|
import { client } from '@/ui/api/client'
|
||||||
|
import { useTeamContextStore } from '@/ui/stores/team-context'
|
||||||
|
import { useUiStore } from '@/ui/stores/ui'
|
||||||
|
import { useQuery } from '@tanstack/react-query'
|
||||||
|
import { useNavigate, useParams, useRouterState, useSearch } from '@tanstack/react-router'
|
||||||
|
import { BreadcrumbNav } from './breadcrumb-nav'
|
||||||
|
import { ShumaiLogo } from '@/ui/components/ui/icons'
|
||||||
|
import type { AncestorFolder } from '@/dtos/asset'
|
||||||
|
|
||||||
|
export function TopNav() {
|
||||||
|
const pathname = useRouterState({ select: (s) => s.location.pathname })
|
||||||
|
const { teamId } = useTeamContextStore()
|
||||||
|
|
||||||
|
// Match exact team page: /teams/$teamId or /teams/$teamId/
|
||||||
|
const isTeamDashboard = teamId && (pathname === `/teams/${teamId}` || pathname === `/teams/${teamId}/`)
|
||||||
|
|
||||||
|
if (isTeamDashboard) {
|
||||||
|
return <TeamHeader />
|
||||||
|
}
|
||||||
|
|
||||||
|
if (pathname.startsWith('/projects/')) {
|
||||||
|
return <ProjectTopNav />
|
||||||
|
}
|
||||||
|
|
||||||
|
return null
|
||||||
|
}
|
||||||
|
|
||||||
|
function TeamHeader() {
|
||||||
|
return (
|
||||||
|
<div className="flex h-14 flex-wrap items-center justify-center gap-2 border-b border-border bg-card px-4 py-2 flex-shrink-0">
|
||||||
|
<ShumaiLogo className="w-10 h-10 text-orange-600" />
|
||||||
|
</div>
|
||||||
|
)
|
||||||
|
}
|
||||||
|
|
||||||
|
function ProjectTopNav() {
|
||||||
|
const params = useParams({ strict: false }) as Record<string, string>
|
||||||
|
const search = useSearch({ strict: false }) as Record<string, string>
|
||||||
|
const pathname = useRouterState({ select: (s) => s.location.pathname })
|
||||||
|
const navigate = useNavigate()
|
||||||
|
|
||||||
|
const projectId = params.projectId
|
||||||
|
const folderId = params.folderId
|
||||||
|
const fileId = params.fileId
|
||||||
|
const versionAssetId = search.version
|
||||||
|
|
||||||
|
const { teamId } = useTeamContextStore()
|
||||||
|
const uiStore = useUiStore()
|
||||||
|
|
||||||
|
const isRecentlyDeleted = pathname.includes('/recently-deleted')
|
||||||
|
const isFileView = !!fileId
|
||||||
|
|
||||||
|
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()
|
||||||
|
},
|
||||||
|
enabled: !!projectId,
|
||||||
|
})
|
||||||
|
|
||||||
|
const rootFolderId = projectInfo?.rootFolder
|
||||||
|
const assetId = folderId || rootFolderId
|
||||||
|
|
||||||
|
const { data: folderInfo } = useQuery({
|
||||||
|
queryKey: ['folders', teamId, assetId],
|
||||||
|
queryFn: async () => {
|
||||||
|
const res = await client.api.teams[':teamId'].folders[':folderId'].$get({
|
||||||
|
param: { teamId: teamId!, folderId: assetId! },
|
||||||
|
})
|
||||||
|
if (!res.ok) throw new Error('failed to fetch folder')
|
||||||
|
return await res.json()
|
||||||
|
},
|
||||||
|
enabled: !!teamId && !!assetId && !isFileView && !isRecentlyDeleted,
|
||||||
|
})
|
||||||
|
|
||||||
|
const { data: fileData } = useQuery({
|
||||||
|
queryKey: ['teams', teamId, 'files', fileId],
|
||||||
|
queryFn: async () => {
|
||||||
|
const res = await client.api.teams[':teamId'].files[':fileId'].$get({
|
||||||
|
param: { teamId: teamId!, fileId: fileId! },
|
||||||
|
})
|
||||||
|
if (!res.ok) throw new Error('Failed to fetch stack')
|
||||||
|
return await res.json()
|
||||||
|
},
|
||||||
|
enabled: !!teamId && !!fileId && isFileView,
|
||||||
|
})
|
||||||
|
|
||||||
|
const { data: versionsList } = useQuery({
|
||||||
|
queryKey: ['projects', projectId, 'version_stacks', fileId, 'versions'],
|
||||||
|
queryFn: async () => {
|
||||||
|
const res = await client.api.projects[':projectId'].version_stacks[':stackId'].versions.$get({
|
||||||
|
param: { projectId: projectId!, stackId: fileId! },
|
||||||
|
})
|
||||||
|
if (!res.ok) throw new Error('Failed to fetch versions')
|
||||||
|
return await res.json()
|
||||||
|
},
|
||||||
|
enabled: !!projectId && !!fileId && !!versionAssetId && isFileView,
|
||||||
|
})
|
||||||
|
|
||||||
|
let ancestorFolders: AncestorFolder[] = []
|
||||||
|
let currentAsset: { name?: string; type: 'file' | 'folder'; version?: number } = {
|
||||||
|
name: '',
|
||||||
|
type: 'folder',
|
||||||
|
}
|
||||||
|
let versions = undefined
|
||||||
|
|
||||||
|
if (isRecentlyDeleted) {
|
||||||
|
currentAsset = { name: 'Recently Deleted', type: 'folder' }
|
||||||
|
} else if (isFileView && fileData) {
|
||||||
|
ancestorFolders = fileData.ancestorFolders || []
|
||||||
|
const versionsDataList = versionAssetId ? versionsList : fileData.versionStack?.versions
|
||||||
|
currentAsset = {
|
||||||
|
name: fileData.name,
|
||||||
|
type: 'file',
|
||||||
|
version: versionsDataList
|
||||||
|
? (versionsDataList.find((v: { id: string }) => v.id === (versionAssetId || fileId))?.version ??
|
||||||
|
versionsDataList.length)
|
||||||
|
: undefined,
|
||||||
|
}
|
||||||
|
versions = versionsDataList
|
||||||
|
} else if (!isFileView && folderInfo) {
|
||||||
|
ancestorFolders = folderInfo.ancestorFolders || []
|
||||||
|
currentAsset = { name: folderInfo.name, type: 'folder' }
|
||||||
|
}
|
||||||
|
|
||||||
|
const isLeftSidebarCollapsed = isFileView
|
||||||
|
? uiStore.fileViewLeftSidebarCollapsed
|
||||||
|
: uiStore.fileListLeftSidebarCollapsed
|
||||||
|
const onLeftSidebarToggle = () =>
|
||||||
|
isFileView
|
||||||
|
? uiStore.setFileViewLeftSidebarCollapsed(!uiStore.fileViewLeftSidebarCollapsed)
|
||||||
|
: uiStore.setFileListLeftSidebarCollapsed(!uiStore.fileListLeftSidebarCollapsed)
|
||||||
|
|
||||||
|
const isRightSidebarCollapsed = isFileView
|
||||||
|
? uiStore.fileViewRightSidebarCollapsed
|
||||||
|
: uiStore.fileListRightSidebarCollapsed
|
||||||
|
const onRightSidebarToggle = () =>
|
||||||
|
isFileView
|
||||||
|
? uiStore.setFileViewRightSidebarCollapsed(!uiStore.fileViewRightSidebarCollapsed)
|
||||||
|
: uiStore.setFileListRightSidebarCollapsed(!uiStore.fileListRightSidebarCollapsed)
|
||||||
|
|
||||||
|
const displayStyle = uiStore.viewModes[projectId!] ?? 'card'
|
||||||
|
const onDisplayStyleChange = (style: 'card' | 'list') => uiStore.setViewMode(projectId!, style)
|
||||||
|
|
||||||
|
const handleFolderClick = (id: string) => {
|
||||||
|
navigate({
|
||||||
|
to: '/projects/$projectId/folders/$folderId',
|
||||||
|
params: { projectId: projectId!, folderId: id },
|
||||||
|
})
|
||||||
|
}
|
||||||
|
|
||||||
|
if (!teamId || !projectId || !projectInfo) {
|
||||||
|
return <div className="h-14 border-b border-border bg-card flex-shrink-0" />
|
||||||
|
}
|
||||||
|
|
||||||
|
return (
|
||||||
|
<BreadcrumbNav
|
||||||
|
teamId={teamId}
|
||||||
|
projectId={projectId}
|
||||||
|
projectName={projectInfo.name ?? ''}
|
||||||
|
ancestorFolders={ancestorFolders}
|
||||||
|
currentAsset={currentAsset}
|
||||||
|
isRootFolder={!isFileView && !isRecentlyDeleted && assetId === rootFolderId}
|
||||||
|
displayStyle={isFileView ? undefined : displayStyle}
|
||||||
|
onDisplayStyleChange={isFileView ? undefined : onDisplayStyleChange}
|
||||||
|
isLeftSidebarCollapsed={isLeftSidebarCollapsed}
|
||||||
|
onLeftSidebarToggle={onLeftSidebarToggle}
|
||||||
|
isRightSidebarCollapsed={isRightSidebarCollapsed}
|
||||||
|
onRightSidebarToggle={onRightSidebarToggle}
|
||||||
|
fileId={fileId}
|
||||||
|
versions={versions}
|
||||||
|
onFolderClick={handleFolderClick}
|
||||||
|
/>
|
||||||
|
)
|
||||||
|
}
|
||||||
@@ -15,6 +15,7 @@ import {
|
|||||||
} from '@tanstack/react-router'
|
} from '@tanstack/react-router'
|
||||||
import { HomeIcon } from 'lucide-react'
|
import { HomeIcon } from 'lucide-react'
|
||||||
import { useEffect } from 'react'
|
import { useEffect } from 'react'
|
||||||
|
import { TopNav } from '@/ui/components/top-nav'
|
||||||
|
|
||||||
function RootComponent() {
|
function RootComponent() {
|
||||||
const user = useAuthStore((state) => state.user)
|
const user = useAuthStore((state) => state.user)
|
||||||
@@ -47,7 +48,7 @@ function RootComponent() {
|
|||||||
}, [teamId, projectId, setTeamId, ensureTeamIdForProject])
|
}, [teamId, projectId, setTeamId, ensureTeamIdForProject])
|
||||||
|
|
||||||
return (
|
return (
|
||||||
<>
|
<div className="flex h-screen w-full bg-background overflow-hidden">
|
||||||
<Toaster />
|
<Toaster />
|
||||||
<DualSidebar>
|
<DualSidebar>
|
||||||
<DualSidebarItem
|
<DualSidebarItem
|
||||||
@@ -77,10 +78,13 @@ function RootComponent() {
|
|||||||
<UploadTasks />
|
<UploadTasks />
|
||||||
</DualSidebarItem>
|
</DualSidebarItem>
|
||||||
</DualSidebar>
|
</DualSidebar>
|
||||||
<main className="md:pl-16">
|
<div className="flex flex-col flex-1 md:pl-16 overflow-hidden relative">
|
||||||
<Outlet />
|
<TopNav />
|
||||||
</main>
|
<main className="flex-1 overflow-hidden relative">
|
||||||
</>
|
<Outlet />
|
||||||
|
</main>
|
||||||
|
</div>
|
||||||
|
</div>
|
||||||
)
|
)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@@ -1,7 +1,6 @@
|
|||||||
import { InferRequestType, InferResponseType } from 'hono/client'
|
import { InferRequestType, InferResponseType } from 'hono/client'
|
||||||
import { useMutation } from '@tanstack/react-query'
|
import { useMutation } from '@tanstack/react-query'
|
||||||
import { client } from '@/ui/api/client'
|
import { client } from '@/ui/api/client'
|
||||||
import { BreadcrumbNav } from '@/ui/components/breadcrumb-nav'
|
|
||||||
import { FileViewer } from '@/ui/components/file-viewer'
|
import { FileViewer } from '@/ui/components/file-viewer'
|
||||||
import { FileViewerLeftSidebar } from '@/ui/components/file-viewer-left-sidebar'
|
import { FileViewerLeftSidebar } from '@/ui/components/file-viewer-left-sidebar'
|
||||||
import { FileViewerRightSidebar } from '@/ui/components/file-viewer-right-sidebar'
|
import { FileViewerRightSidebar } from '@/ui/components/file-viewer-right-sidebar'
|
||||||
@@ -27,7 +26,6 @@ function FileViewPage() {
|
|||||||
const videoRef = useRef<Player | null>(null)
|
const videoRef = useRef<Player | null>(null)
|
||||||
const {
|
const {
|
||||||
fileViewRightSidebarCollapsed: isRightSidebarCollapsed,
|
fileViewRightSidebarCollapsed: isRightSidebarCollapsed,
|
||||||
setFileViewRightSidebarCollapsed: setIsRightSidebarCollapsed,
|
|
||||||
fileViewLeftSidebarCollapsed: isLeftSidebarCollapsed,
|
fileViewLeftSidebarCollapsed: isLeftSidebarCollapsed,
|
||||||
setFileViewLeftSidebarCollapsed: setIsLeftSidebarCollapsed,
|
setFileViewLeftSidebarCollapsed: setIsLeftSidebarCollapsed,
|
||||||
} = useUiStore()
|
} = useUiStore()
|
||||||
@@ -96,18 +94,6 @@ function FileViewPage() {
|
|||||||
placeholderData: keepPreviousData,
|
placeholderData: keepPreviousData,
|
||||||
})
|
})
|
||||||
|
|
||||||
const { data: versionsList } = useQuery({
|
|
||||||
queryKey: ['projects', projectId, 'version_stacks', fileId, 'versions'],
|
|
||||||
queryFn: async () => {
|
|
||||||
const res = await client.api.projects[':projectId'].version_stacks[':stackId'].versions.$get({
|
|
||||||
param: { projectId: projectId, stackId: fileId },
|
|
||||||
})
|
|
||||||
if (!res.ok) throw new Error('Failed to fetch versions')
|
|
||||||
return await res.json()
|
|
||||||
},
|
|
||||||
enabled: !!projectId && !!fileId && !!versionAssetId,
|
|
||||||
})
|
|
||||||
|
|
||||||
const { data: projectInfo } = useQuery({
|
const { data: projectInfo } = useQuery({
|
||||||
queryKey: ['projects', projectId],
|
queryKey: ['projects', projectId],
|
||||||
queryFn: async () => {
|
queryFn: async () => {
|
||||||
@@ -123,7 +109,6 @@ function FileViewPage() {
|
|||||||
const isError = isStackError || (!!versionAssetId && isVersionError)
|
const isError = isStackError || (!!versionAssetId && isVersionError)
|
||||||
const isFetching = isStackFetching || (!!versionAssetId && isVersionFetching)
|
const isFetching = isStackFetching || (!!versionAssetId && isVersionFetching)
|
||||||
const fileData = versionData || stackData
|
const fileData = versionData || stackData
|
||||||
const versionsDataList = versionAssetId ? versionsList : stackData?.versionStack?.versions
|
|
||||||
|
|
||||||
if (isLoading && !fileData) {
|
if (isLoading && !fileData) {
|
||||||
return <div>Loading...</div>
|
return <div>Loading...</div>
|
||||||
@@ -167,28 +152,7 @@ function FileViewPage() {
|
|||||||
}
|
}
|
||||||
|
|
||||||
return (
|
return (
|
||||||
<div className="flex h-screen flex-col bg-background">
|
<div className="flex h-full flex-col bg-background">
|
||||||
<BreadcrumbNav
|
|
||||||
teamId={teamId}
|
|
||||||
projectId={projectId}
|
|
||||||
projectName={projectInfo.name ?? ''}
|
|
||||||
ancestorFolders={fileData.ancestorFolders ?? []}
|
|
||||||
currentAsset={{
|
|
||||||
name: fileData.name,
|
|
||||||
type: 'file',
|
|
||||||
version: versionsDataList
|
|
||||||
? (versionsDataList.find((v) => v.id === activeFileId)?.version ??
|
|
||||||
versionsDataList.length)
|
|
||||||
: undefined,
|
|
||||||
}}
|
|
||||||
isRootFolder={false}
|
|
||||||
isLeftSidebarCollapsed={isLeftSidebarCollapsed}
|
|
||||||
onLeftSidebarToggle={() => setIsLeftSidebarCollapsed(!isLeftSidebarCollapsed)}
|
|
||||||
isRightSidebarCollapsed={isRightSidebarCollapsed}
|
|
||||||
onRightSidebarToggle={() => setIsRightSidebarCollapsed(!isRightSidebarCollapsed)}
|
|
||||||
fileId={fileId}
|
|
||||||
versions={versionsDataList}
|
|
||||||
/>
|
|
||||||
<div className="flex flex-1 overflow-hidden">
|
<div className="flex flex-1 overflow-hidden">
|
||||||
{!isLeftSidebarCollapsed && (
|
{!isLeftSidebarCollapsed && (
|
||||||
<>
|
<>
|
||||||
|
|||||||
@@ -205,12 +205,8 @@ function TeamPage() {
|
|||||||
const safeMembers = Array.isArray(members) ? members : []
|
const safeMembers = Array.isArray(members) ? members : []
|
||||||
|
|
||||||
return (
|
return (
|
||||||
<div>
|
<div className="p-4">
|
||||||
<div className="flex h-14 flex-wrap items-center justify-center gap-2 border-b border-border bg-card px-4 py-2">
|
<div className="flex flex-wrap items-center justify-between mb-4 gap-4">
|
||||||
<ShumaiLogo className="w-10 h-10 text-orange-600" />
|
|
||||||
</div>
|
|
||||||
<div className="p-4">
|
|
||||||
<div className="flex flex-wrap items-center justify-between mb-4 gap-4">
|
|
||||||
<h1 className="text-2xl font-bold">Projects</h1>
|
<h1 className="text-2xl font-bold">Projects</h1>
|
||||||
<div className="flex flex-wrap items-center gap-4">
|
<div className="flex flex-wrap items-center gap-4">
|
||||||
<div
|
<div
|
||||||
@@ -379,7 +375,6 @@ function TeamPage() {
|
|||||||
onInvite={handleInvite}
|
onInvite={handleInvite}
|
||||||
/>
|
/>
|
||||||
</div>
|
</div>
|
||||||
</div>
|
|
||||||
)
|
)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user