mirror of
https://github.com/shumaiOne/shumai.git
synced 2026-11-24 08:36:35 +00:00
feat(webui): always show right sidebar and implement left vertical carousel
This commit is contained in:
@@ -203,11 +203,13 @@ describe('Sandbox Network isolation integration', () => {
|
|||||||
|
|
||||||
// Mock SandboxManager.initialize to behave like a process-global singleton
|
// Mock SandboxManager.initialize to behave like a process-global singleton
|
||||||
let registeredCallback: SandboxAskCallback | null = null
|
let registeredCallback: SandboxAskCallback | null = null
|
||||||
const initializeSpy = vi.spyOn(SandboxManager, 'initialize').mockImplementation(async (config, cb) => {
|
const initializeSpy = vi
|
||||||
if (!registeredCallback) {
|
.spyOn(SandboxManager, 'initialize')
|
||||||
registeredCallback = cb || null
|
.mockImplementation(async (config, cb) => {
|
||||||
}
|
if (!registeredCallback) {
|
||||||
})
|
registeredCallback = cb || null
|
||||||
|
}
|
||||||
|
})
|
||||||
const resetSpy = vi.spyOn(SandboxManager, 'reset').mockImplementation(async () => {
|
const resetSpy = vi.spyOn(SandboxManager, 'reset').mockImplementation(async () => {
|
||||||
// In the real SandboxManager, reset clears the global initialization promise and servers,
|
// In the real SandboxManager, reset clears the global initialization promise and servers,
|
||||||
// which allows subsequent initialize calls to register a new callback.
|
// which allows subsequent initialize calls to register a new callback.
|
||||||
|
|||||||
@@ -240,65 +240,67 @@ export function BreadcrumbNav({
|
|||||||
)}
|
)}
|
||||||
</div>
|
</div>
|
||||||
|
|
||||||
<div className="flex flex-shrink-0 items-center gap-1 rounded-md border border-border bg-background p-1">
|
{!fileId && (
|
||||||
{/* Left Sidebar Toggle */}
|
<div className="flex flex-shrink-0 items-center gap-1 rounded-md border border-border bg-background p-1">
|
||||||
{!isPublic && onLeftSidebarToggle && (
|
{/* Left Sidebar Toggle */}
|
||||||
|
{!isPublic && onLeftSidebarToggle && (
|
||||||
|
<button
|
||||||
|
onClick={onLeftSidebarToggle}
|
||||||
|
className="rounded p-1.5 text-muted-foreground transition-colors hover:bg-accent/50 hover:text-foreground"
|
||||||
|
title={isLeftSidebarCollapsed ? 'Show Left Sidebar' : 'Hide Left Sidebar'}
|
||||||
|
>
|
||||||
|
{isLeftSidebarCollapsed ? (
|
||||||
|
<DockToLeft className="h-4 w-4" />
|
||||||
|
) : (
|
||||||
|
<DockToLeftFilled className="h-4 w-4 fill-primary stroke-0" />
|
||||||
|
)}
|
||||||
|
</button>
|
||||||
|
)}
|
||||||
|
|
||||||
|
{/* Card View */}
|
||||||
|
{!isPublic && displayStyle && onDisplayStyleChange && (
|
||||||
|
<>
|
||||||
|
<button
|
||||||
|
onClick={() => onDisplayStyleChange('card')}
|
||||||
|
className={`rounded p-1.5 transition-colors ${
|
||||||
|
displayStyle === 'card'
|
||||||
|
? 'bg-accent text-accent-foreground'
|
||||||
|
: 'text-muted-foreground hover:bg-accent/50 hover:text-foreground'
|
||||||
|
}`}
|
||||||
|
title="Card View"
|
||||||
|
>
|
||||||
|
<LayoutGrid className="h-4 w-4" />
|
||||||
|
</button>
|
||||||
|
|
||||||
|
{/* List View */}
|
||||||
|
<button
|
||||||
|
onClick={() => onDisplayStyleChange('list')}
|
||||||
|
className={`rounded p-1.5 transition-colors ${
|
||||||
|
displayStyle === 'list'
|
||||||
|
? 'bg-accent text-accent-foreground'
|
||||||
|
: 'text-muted-foreground hover:bg-accent/50 hover:text-foreground'
|
||||||
|
}`}
|
||||||
|
title="List View"
|
||||||
|
>
|
||||||
|
<List className="h-4 w-4" />
|
||||||
|
</button>
|
||||||
|
</>
|
||||||
|
)}
|
||||||
|
|
||||||
|
{/* Right Sidebar Toggle */}
|
||||||
<button
|
<button
|
||||||
onClick={onLeftSidebarToggle}
|
onClick={onRightSidebarToggle}
|
||||||
className="rounded p-1.5 text-muted-foreground transition-colors hover:bg-accent/50 hover:text-foreground"
|
className="rounded p-1.5 text-muted-foreground transition-colors hover:bg-accent/50 hover:text-foreground"
|
||||||
title={isLeftSidebarCollapsed ? 'Show Left Sidebar' : 'Hide Left Sidebar'}
|
title={isRightSidebarCollapsed ? 'Show Right Sidebar' : 'Hide Right Sidebar'}
|
||||||
>
|
>
|
||||||
{isLeftSidebarCollapsed ? (
|
{isRightSidebarCollapsed ? (
|
||||||
<DockToLeft className="h-4 w-4" />
|
<DockToRight className="h-4 w-4" />
|
||||||
) : (
|
) : (
|
||||||
<DockToLeftFilled className="h-4 w-4 fill-primary stroke-0" />
|
<DockToRightFilled className="h-4 w-4 fill-primary stroke-0" />
|
||||||
)}
|
)}
|
||||||
</button>
|
</button>
|
||||||
)}
|
</div>
|
||||||
|
)}
|
||||||
{/* Card View */}
|
|
||||||
{!isPublic && displayStyle && onDisplayStyleChange && (
|
|
||||||
<>
|
|
||||||
<button
|
|
||||||
onClick={() => onDisplayStyleChange('card')}
|
|
||||||
className={`rounded p-1.5 transition-colors ${
|
|
||||||
displayStyle === 'card'
|
|
||||||
? 'bg-accent text-accent-foreground'
|
|
||||||
: 'text-muted-foreground hover:bg-accent/50 hover:text-foreground'
|
|
||||||
}`}
|
|
||||||
title="Card View"
|
|
||||||
>
|
|
||||||
<LayoutGrid className="h-4 w-4" />
|
|
||||||
</button>
|
|
||||||
|
|
||||||
{/* List View */}
|
|
||||||
<button
|
|
||||||
onClick={() => onDisplayStyleChange('list')}
|
|
||||||
className={`rounded p-1.5 transition-colors ${
|
|
||||||
displayStyle === 'list'
|
|
||||||
? 'bg-accent text-accent-foreground'
|
|
||||||
: 'text-muted-foreground hover:bg-accent/50 hover:text-foreground'
|
|
||||||
}`}
|
|
||||||
title="List View"
|
|
||||||
>
|
|
||||||
<List className="h-4 w-4" />
|
|
||||||
</button>
|
|
||||||
</>
|
|
||||||
)}
|
|
||||||
|
|
||||||
{/* Right Sidebar Toggle */}
|
|
||||||
<button
|
|
||||||
onClick={onRightSidebarToggle}
|
|
||||||
className="rounded p-1.5 text-muted-foreground transition-colors hover:bg-accent/50 hover:text-foreground"
|
|
||||||
title={isRightSidebarCollapsed ? 'Show Right Sidebar' : 'Hide Right Sidebar'}
|
|
||||||
>
|
|
||||||
{isRightSidebarCollapsed ? (
|
|
||||||
<DockToRight className="h-4 w-4" />
|
|
||||||
) : (
|
|
||||||
<DockToRightFilled className="h-4 w-4 fill-primary stroke-0" />
|
|
||||||
)}
|
|
||||||
</button>
|
|
||||||
</div>
|
|
||||||
</div>
|
</div>
|
||||||
)
|
)
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -457,125 +457,126 @@ export const ChatInput = React.forwardRef<HTMLDivElement, ChatInputProps>(
|
|||||||
cursor: text;
|
cursor: text;
|
||||||
}
|
}
|
||||||
`}</style>
|
`}</style>
|
||||||
{showMentionList && (membersLoading || filteredAgents.length > 0 || filteredHumans.length > 0) && (
|
{showMentionList &&
|
||||||
<div className="absolute bottom-full left-4 mb-2 w-64 rounded-xl shadow-lg border border-border overflow-hidden z-20 bg-popover text-popover-foreground animate-in fade-in slide-in-from-bottom-2 duration-200">
|
(membersLoading || filteredAgents.length > 0 || filteredHumans.length > 0) && (
|
||||||
<div className="h-64 overflow-y-auto">
|
<div className="absolute bottom-full left-4 mb-2 w-64 rounded-xl shadow-lg border border-border overflow-hidden z-20 bg-popover text-popover-foreground animate-in fade-in slide-in-from-bottom-2 duration-200">
|
||||||
{membersLoading ? (
|
<div className="h-64 overflow-y-auto">
|
||||||
<div className="p-2 space-y-4 animate-pulse">
|
{membersLoading ? (
|
||||||
{/* Agents Skeleton */}
|
<div className="p-2 space-y-4 animate-pulse">
|
||||||
<div className="space-y-2">
|
{/* Agents Skeleton */}
|
||||||
<div className="px-3 py-1.5 bg-muted/50 border-b border-border">
|
<div className="space-y-2">
|
||||||
<Skeleton className="h-3 w-16" />
|
<div className="px-3 py-1.5 bg-muted/50 border-b border-border">
|
||||||
|
<Skeleton className="h-3 w-16" />
|
||||||
|
</div>
|
||||||
|
<div className="flex items-center gap-2 px-3 py-2">
|
||||||
|
<Skeleton className="w-6 h-6 rounded-full" />
|
||||||
|
<Skeleton className="h-4 w-28" />
|
||||||
|
</div>
|
||||||
|
<div className="flex items-center gap-2 px-3 py-2">
|
||||||
|
<Skeleton className="w-6 h-6 rounded-full" />
|
||||||
|
<Skeleton className="h-4 w-20" />
|
||||||
|
</div>
|
||||||
</div>
|
</div>
|
||||||
<div className="flex items-center gap-2 px-3 py-2">
|
{/* Members Skeleton */}
|
||||||
<Skeleton className="w-6 h-6 rounded-full" />
|
<div className="space-y-2">
|
||||||
<Skeleton className="h-4 w-28" />
|
<div className="px-3 py-1.5 bg-muted/50 border-b border-border">
|
||||||
</div>
|
<Skeleton className="h-3 w-16" />
|
||||||
<div className="flex items-center gap-2 px-3 py-2">
|
</div>
|
||||||
<Skeleton className="w-6 h-6 rounded-full" />
|
<div className="flex items-center gap-2 px-3 py-2">
|
||||||
<Skeleton className="h-4 w-20" />
|
<Skeleton className="w-6 h-6 rounded-full" />
|
||||||
|
<Skeleton className="h-4 w-32" />
|
||||||
|
</div>
|
||||||
|
<div className="flex items-center gap-2 px-3 py-2">
|
||||||
|
<Skeleton className="w-6 h-6 rounded-full" />
|
||||||
|
<Skeleton className="h-4 w-24" />
|
||||||
|
</div>
|
||||||
</div>
|
</div>
|
||||||
</div>
|
</div>
|
||||||
{/* Members Skeleton */}
|
) : (
|
||||||
<div className="space-y-2">
|
<>
|
||||||
<div className="px-3 py-1.5 bg-muted/50 border-b border-border">
|
{filteredAgents.length > 0 && (
|
||||||
<Skeleton className="h-3 w-16" />
|
<>
|
||||||
</div>
|
<button
|
||||||
<div className="flex items-center gap-2 px-3 py-2">
|
onClick={(e) => {
|
||||||
<Skeleton className="w-6 h-6 rounded-full" />
|
e.preventDefault()
|
||||||
<Skeleton className="h-4 w-32" />
|
e.stopPropagation()
|
||||||
</div>
|
setCollapsedSections((prev) => ({ ...prev, bots: !prev.bots }))
|
||||||
<div className="flex items-center gap-2 px-3 py-2">
|
}}
|
||||||
<Skeleton className="w-6 h-6 rounded-full" />
|
className="w-full text-xs font-semibold text-muted-foreground px-3 py-2 bg-muted/50 border-b border-border sticky top-0 flex items-center justify-between hover:bg-muted transition-colors"
|
||||||
<Skeleton className="h-4 w-24" />
|
>
|
||||||
</div>
|
<span>Agents</span>
|
||||||
</div>
|
<ChevronDown
|
||||||
</div>
|
className={`w-3 h-3 transition-transform ${collapsedSections.bots ? '-rotate-90' : ''}`}
|
||||||
) : (
|
/>
|
||||||
<>
|
</button>
|
||||||
{filteredAgents.length > 0 && (
|
{!collapsedSections.bots &&
|
||||||
<>
|
filteredAgents.map((item, index) => {
|
||||||
<button
|
const actualIndex = index
|
||||||
onClick={(e) => {
|
return (
|
||||||
e.preventDefault()
|
<button
|
||||||
e.stopPropagation()
|
key={item.data.id}
|
||||||
setCollapsedSections((prev) => ({ ...prev, bots: !prev.bots }))
|
onClick={() => handleSelectEntity(item)}
|
||||||
}}
|
onMouseEnter={() => setHighlightedIndex(actualIndex)}
|
||||||
className="w-full text-xs font-semibold text-muted-foreground px-3 py-2 bg-muted/50 border-b border-border sticky top-0 flex items-center justify-between hover:bg-muted transition-colors"
|
className={`w-full flex items-center gap-2 px-3 py-2 transition-colors text-left ${
|
||||||
>
|
actualIndex === highlightedIndex
|
||||||
<span>Agents</span>
|
? 'bg-accent text-accent-foreground'
|
||||||
<ChevronDown
|
: 'hover:bg-accent/50'
|
||||||
className={`w-3 h-3 transition-transform ${collapsedSections.bots ? '-rotate-90' : ''}`}
|
}`}
|
||||||
/>
|
>
|
||||||
</button>
|
<div className="w-6 h-6 rounded-full bg-purple-100 dark:bg-purple-900/40 flex items-center justify-center text-xs font-bold text-purple-600 dark:text-purple-300">
|
||||||
{!collapsedSections.bots &&
|
{item.data.name?.[0]}
|
||||||
filteredAgents.map((item, index) => {
|
</div>
|
||||||
const actualIndex = index
|
<span className="text-sm">{item.data.name}</span>
|
||||||
return (
|
</button>
|
||||||
<button
|
)
|
||||||
key={item.data.id}
|
})}
|
||||||
onClick={() => handleSelectEntity(item)}
|
</>
|
||||||
onMouseEnter={() => setHighlightedIndex(actualIndex)}
|
)}
|
||||||
className={`w-full flex items-center gap-2 px-3 py-2 transition-colors text-left ${
|
|
||||||
actualIndex === highlightedIndex
|
|
||||||
? 'bg-accent text-accent-foreground'
|
|
||||||
: 'hover:bg-accent/50'
|
|
||||||
}`}
|
|
||||||
>
|
|
||||||
<div className="w-6 h-6 rounded-full bg-purple-100 dark:bg-purple-900/40 flex items-center justify-center text-xs font-bold text-purple-600 dark:text-purple-300">
|
|
||||||
{item.data.name?.[0]}
|
|
||||||
</div>
|
|
||||||
<span className="text-sm">{item.data.name}</span>
|
|
||||||
</button>
|
|
||||||
)
|
|
||||||
})}
|
|
||||||
</>
|
|
||||||
)}
|
|
||||||
|
|
||||||
{filteredHumans.length > 0 && (
|
{filteredHumans.length > 0 && (
|
||||||
<>
|
<>
|
||||||
<button
|
<button
|
||||||
onClick={(e) => {
|
onClick={(e) => {
|
||||||
e.preventDefault()
|
e.preventDefault()
|
||||||
e.stopPropagation()
|
e.stopPropagation()
|
||||||
setCollapsedSections((prev) => ({ ...prev, users: !prev.users }))
|
setCollapsedSections((prev) => ({ ...prev, users: !prev.users }))
|
||||||
}}
|
}}
|
||||||
className="w-full text-xs font-semibold text-muted-foreground px-3 py-2 bg-muted/50 border-b border-border sticky top-0 flex items-center justify-between hover:bg-muted transition-colors"
|
className="w-full text-xs font-semibold text-muted-foreground px-3 py-2 bg-muted/50 border-b border-border sticky top-0 flex items-center justify-between hover:bg-muted transition-colors"
|
||||||
>
|
>
|
||||||
<span>Members</span>
|
<span>Members</span>
|
||||||
<ChevronDown
|
<ChevronDown
|
||||||
className={`w-3 h-3 transition-transform ${collapsedSections.users ? '-rotate-90' : ''}`}
|
className={`w-3 h-3 transition-transform ${collapsedSections.users ? '-rotate-90' : ''}`}
|
||||||
/>
|
/>
|
||||||
</button>
|
</button>
|
||||||
{!collapsedSections.users &&
|
{!collapsedSections.users &&
|
||||||
filteredHumans.map((item, index) => {
|
filteredHumans.map((item, index) => {
|
||||||
const actualIndex =
|
const actualIndex =
|
||||||
(collapsedSections.bots ? 0 : filteredAgents.length) + index
|
(collapsedSections.bots ? 0 : filteredAgents.length) + index
|
||||||
return (
|
return (
|
||||||
<button
|
<button
|
||||||
key={item.data.id}
|
key={item.data.id}
|
||||||
onClick={() => handleSelectEntity(item)}
|
onClick={() => handleSelectEntity(item)}
|
||||||
onMouseEnter={() => setHighlightedIndex(actualIndex)}
|
onMouseEnter={() => setHighlightedIndex(actualIndex)}
|
||||||
className={`w-full flex items-center gap-2 px-3 py-2 transition-colors text-left ${
|
className={`w-full flex items-center gap-2 px-3 py-2 transition-colors text-left ${
|
||||||
actualIndex === highlightedIndex
|
actualIndex === highlightedIndex
|
||||||
? 'bg-accent text-accent-foreground'
|
? 'bg-accent text-accent-foreground'
|
||||||
: 'hover:bg-accent/50'
|
: 'hover:bg-accent/50'
|
||||||
}`}
|
}`}
|
||||||
>
|
>
|
||||||
<div className="w-6 h-6 rounded-full bg-blue-100 dark:bg-blue-900/40 flex items-center justify-center text-xs font-bold text-blue-600 dark:text-blue-300">
|
<div className="w-6 h-6 rounded-full bg-blue-100 dark:bg-blue-900/40 flex items-center justify-center text-xs font-bold text-blue-600 dark:text-blue-300">
|
||||||
{item.data.name?.[0]}
|
{item.data.name?.[0]}
|
||||||
</div>
|
</div>
|
||||||
<span className="text-sm">{item.data.name}</span>
|
<span className="text-sm">{item.data.name}</span>
|
||||||
</button>
|
</button>
|
||||||
)
|
)
|
||||||
})}
|
})}
|
||||||
</>
|
</>
|
||||||
)}
|
)}
|
||||||
</>
|
</>
|
||||||
)}
|
)}
|
||||||
|
</div>
|
||||||
</div>
|
</div>
|
||||||
</div>
|
)}
|
||||||
)}
|
|
||||||
|
|
||||||
{showUpperPart && (
|
{showUpperPart && (
|
||||||
<div className="flex flex-col gap-2 p-3 pb-0 animate-in fade-in slide-in-from-bottom-2 duration-200">
|
<div className="flex flex-col gap-2 p-3 pb-0 animate-in fade-in slide-in-from-bottom-2 duration-200">
|
||||||
|
|||||||
@@ -1,26 +1,40 @@
|
|||||||
import { client } from '@/ui/api/client'
|
import { client } from '@/ui/api/client'
|
||||||
import { useInfiniteQuery } from '@tanstack/react-query'
|
import { File, Loader2 } from 'lucide-react'
|
||||||
import { Loader2, PanelLeftClose } from 'lucide-react'
|
|
||||||
import type { FC } from 'react'
|
import type { FC } from 'react'
|
||||||
import type { AssetInfoPaginatedList } from '@shumai/dtos'
|
import type { AssetInfo, AssetInfoPaginatedList } from '@shumai/dtos'
|
||||||
import { useEffect, useRef } from 'react'
|
import { useEffect, useRef, useState } from 'react'
|
||||||
import { useInView } from 'react-intersection-observer'
|
import { useInView } from 'react-intersection-observer'
|
||||||
import { SidebarFileCard } from './sidebar-file-card'
|
import { Link } from '@tanstack/react-router'
|
||||||
import { Button } from './ui/button'
|
import { cn } from '@/ui/lib/utils'
|
||||||
import { ScrollArea } from './ui/scroll-area'
|
|
||||||
|
|
||||||
interface FileViewerLeftSidebarProps {
|
interface FileViewerLeftSidebarProps {
|
||||||
projectId: string
|
projectId: string
|
||||||
currentAssetId: string
|
currentAssetId: string
|
||||||
parentFolderId: string
|
parentFolderId: string
|
||||||
onCollapse: () => void
|
initialFiles: AssetInfo[]
|
||||||
|
initialNextCursor: string | undefined
|
||||||
|
}
|
||||||
|
|
||||||
|
export const CarouselFilePreview = ({ item }: { item: AssetInfo }) => {
|
||||||
|
if (item.preview?.thumbnailUrl) {
|
||||||
|
return (
|
||||||
|
<img src={item.preview.thumbnailUrl} alt="Preview" className="w-full h-full object-cover" />
|
||||||
|
)
|
||||||
|
}
|
||||||
|
|
||||||
|
return (
|
||||||
|
<div className="w-full h-full flex items-center justify-center bg-muted">
|
||||||
|
<File className="w-5 h-5 text-muted-foreground" />
|
||||||
|
</div>
|
||||||
|
)
|
||||||
}
|
}
|
||||||
|
|
||||||
export const FileViewerLeftSidebar: FC<FileViewerLeftSidebarProps> = ({
|
export const FileViewerLeftSidebar: FC<FileViewerLeftSidebarProps> = ({
|
||||||
projectId,
|
projectId,
|
||||||
currentAssetId,
|
currentAssetId,
|
||||||
parentFolderId,
|
parentFolderId,
|
||||||
onCollapse,
|
initialFiles,
|
||||||
|
initialNextCursor,
|
||||||
}) => {
|
}) => {
|
||||||
const { ref, inView } = useInView({
|
const { ref, inView } = useInView({
|
||||||
threshold: 0,
|
threshold: 0,
|
||||||
@@ -29,38 +43,51 @@ export const FileViewerLeftSidebar: FC<FileViewerLeftSidebarProps> = ({
|
|||||||
const activeItemRef = useRef<HTMLDivElement>(null)
|
const activeItemRef = useRef<HTMLDivElement>(null)
|
||||||
const hasScrolledRef = useRef(false)
|
const hasScrolledRef = useRef(false)
|
||||||
|
|
||||||
const { data, fetchNextPage, hasNextPage, isFetchingNextPage, isLoading } = useInfiniteQuery({
|
const [files, setFiles] = useState<AssetInfo[]>(initialFiles)
|
||||||
queryKey: [
|
const [nextCursor, setNextCursor] = useState<string | undefined>(initialNextCursor)
|
||||||
'folders',
|
const [hasMore, setHasMore] = useState<boolean>(!!initialNextCursor)
|
||||||
parentFolderId,
|
const [isFetchingNext, setIsFetchingNext] = useState<boolean>(false)
|
||||||
'children',
|
|
||||||
{
|
|
||||||
assetType: 'file',
|
|
||||||
},
|
|
||||||
],
|
|
||||||
queryFn: async ({ pageParam }) => {
|
|
||||||
const res = await client.api.folders[':folderId'].children.$get({
|
|
||||||
param: { folderId: parentFolderId },
|
|
||||||
query: {
|
|
||||||
assetType: 'file',
|
|
||||||
after: pageParam,
|
|
||||||
first: '20',
|
|
||||||
},
|
|
||||||
})
|
|
||||||
if (!res.ok) throw new Error('failed to fetch folder children')
|
|
||||||
return (await res.json()) as unknown as AssetInfoPaginatedList
|
|
||||||
},
|
|
||||||
initialPageParam: '',
|
|
||||||
getNextPageParam: (lastPage) => lastPage.pageInfo?.cursor || undefined,
|
|
||||||
})
|
|
||||||
|
|
||||||
const files = data?.pages.flatMap((page) => page.data) ?? []
|
|
||||||
|
|
||||||
|
// Sync state if initial files / cursor changes (due to parent folder change)
|
||||||
useEffect(() => {
|
useEffect(() => {
|
||||||
if (inView && hasNextPage && !isFetchingNextPage) {
|
setFiles(initialFiles)
|
||||||
fetchNextPage()
|
setNextCursor(initialNextCursor)
|
||||||
|
setHasMore(!!initialNextCursor)
|
||||||
|
hasScrolledRef.current = false
|
||||||
|
}, [initialFiles, initialNextCursor])
|
||||||
|
|
||||||
|
// Fetch next page when scrolling near bottom
|
||||||
|
useEffect(() => {
|
||||||
|
const fetchNextPage = async () => {
|
||||||
|
if (!nextCursor || isFetchingNext || !inView || !hasMore) return
|
||||||
|
setIsFetchingNext(true)
|
||||||
|
try {
|
||||||
|
const res = await client.api.folders[':folderId'].search.$post({
|
||||||
|
param: { folderId: parentFolderId },
|
||||||
|
json: {
|
||||||
|
assetType: 'file',
|
||||||
|
after: nextCursor,
|
||||||
|
first: 200,
|
||||||
|
recursively: false,
|
||||||
|
conditions: [],
|
||||||
|
},
|
||||||
|
})
|
||||||
|
if (!res.ok) throw new Error('Failed to fetch next page')
|
||||||
|
const result = (await res.json()) as unknown as AssetInfoPaginatedList
|
||||||
|
const batchFiles = (result.data || []) as AssetInfo[]
|
||||||
|
|
||||||
|
setFiles((prev) => [...prev, ...batchFiles])
|
||||||
|
setNextCursor(result.pageInfo?.cursor || undefined)
|
||||||
|
setHasMore(!!result.pageInfo?.cursor && batchFiles.length > 0)
|
||||||
|
} catch (err) {
|
||||||
|
console.error('Error fetching next page:', err)
|
||||||
|
} finally {
|
||||||
|
setIsFetchingNext(false)
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}, [inView, hasNextPage, isFetchingNextPage, fetchNextPage])
|
|
||||||
|
fetchNextPage()
|
||||||
|
}, [inView, nextCursor, hasMore, isFetchingNext, parentFolderId])
|
||||||
|
|
||||||
// Reset scroll lock when current asset changes
|
// Reset scroll lock when current asset changes
|
||||||
useEffect(() => {
|
useEffect(() => {
|
||||||
@@ -73,47 +100,48 @@ export const FileViewerLeftSidebar: FC<FileViewerLeftSidebarProps> = ({
|
|||||||
if (activeFileInView && activeItemRef.current && !hasScrolledRef.current) {
|
if (activeFileInView && activeItemRef.current && !hasScrolledRef.current) {
|
||||||
activeItemRef.current.scrollIntoView({
|
activeItemRef.current.scrollIntoView({
|
||||||
block: 'center',
|
block: 'center',
|
||||||
|
behavior: 'smooth',
|
||||||
})
|
})
|
||||||
hasScrolledRef.current = true
|
hasScrolledRef.current = true
|
||||||
}
|
}
|
||||||
}, [files, currentAssetId])
|
}, [files, currentAssetId])
|
||||||
|
|
||||||
return (
|
return (
|
||||||
<div className="h-full w-full bg-card border-r border-border flex flex-col">
|
<div className="h-full w-24 bg-card border-r border-border flex flex-col flex-shrink-0 select-none">
|
||||||
<div className="p-2 border-b flex items-center justify-between">
|
<div className="flex-1 overflow-y-auto py-4 flex flex-col items-center gap-3 no-scrollbar">
|
||||||
<h3 className="text-sm font-semibold px-2">Current Folder</h3>
|
{files.map((file) => {
|
||||||
<Button variant="ghost" size="icon-sm" onClick={onCollapse}>
|
if (!file) return null
|
||||||
<PanelLeftClose className="h-4 w-4" />
|
const isActive = file.id === currentAssetId
|
||||||
</Button>
|
return (
|
||||||
</div>
|
<div
|
||||||
<ScrollArea className="flex-1 [&>div>div]:block! px-2">
|
key={file.id}
|
||||||
<div className="p-2 space-y-2">
|
ref={file.id === currentAssetId ? activeItemRef : null}
|
||||||
{isLoading && (
|
className="flex-shrink-0"
|
||||||
<div className="flex justify-center items-center p-4">
|
>
|
||||||
<Loader2 className="h-6 w-6 animate-spin text-muted-foreground" />
|
<Link
|
||||||
|
to="/projects/$projectId/files/$fileId"
|
||||||
|
params={{ projectId, fileId: file.id }}
|
||||||
|
search={{ version: undefined }}
|
||||||
|
className={cn(
|
||||||
|
'w-[54px] h-[54px] rounded-lg border overflow-hidden flex items-center justify-center transition-all bg-muted/30 block',
|
||||||
|
isActive
|
||||||
|
? 'border-primary ring-2 ring-primary opacity-100 scale-105'
|
||||||
|
: 'border-border hover:border-primary/50 opacity-65 hover:opacity-100',
|
||||||
|
)}
|
||||||
|
>
|
||||||
|
<CarouselFilePreview item={file} />
|
||||||
|
</Link>
|
||||||
</div>
|
</div>
|
||||||
)}
|
)
|
||||||
{files.map(
|
})}
|
||||||
(file) =>
|
|
||||||
file && (
|
{/* Infinite Scroll Trigger */}
|
||||||
<SidebarFileCard
|
{hasMore && (
|
||||||
ref={file.id === currentAssetId ? activeItemRef : null}
|
<div ref={ref} className="py-2 flex justify-center items-center w-full">
|
||||||
key={file.id}
|
{isFetchingNext && <Loader2 className="h-5 w-5 animate-spin text-muted-foreground" />}
|
||||||
projectId={projectId}
|
|
||||||
item={file}
|
|
||||||
isActive={file.id === currentAssetId}
|
|
||||||
/>
|
|
||||||
),
|
|
||||||
)}
|
|
||||||
<div ref={ref}>
|
|
||||||
{isFetchingNextPage && (
|
|
||||||
<div className="flex justify-center items-center p-4">
|
|
||||||
<Loader2 className="h-6 w-6 animate-spin text-muted-foreground" />
|
|
||||||
</div>
|
|
||||||
)}
|
|
||||||
</div>
|
</div>
|
||||||
</div>
|
)}
|
||||||
</ScrollArea>
|
</div>
|
||||||
</div>
|
</div>
|
||||||
)
|
)
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -7,12 +7,11 @@ import { FileDetailSkeleton } from '@/ui/components/loading-skeletons'
|
|||||||
import { useMemberStore } from '@/ui/stores/members'
|
import { useMemberStore } from '@/ui/stores/members'
|
||||||
import { useTeamContextStore } from '@/ui/stores/team-context'
|
import { useTeamContextStore } from '@/ui/stores/team-context'
|
||||||
import { useTopNavStore } from '@/ui/stores/top-nav'
|
import { useTopNavStore } from '@/ui/stores/top-nav'
|
||||||
import { useUiStore } from '@/ui/stores/ui'
|
|
||||||
import { type Annotation } from '@/ui/types'
|
import { type Annotation } from '@/ui/types'
|
||||||
import { useMutation } from '@tanstack/react-query'
|
import { useMutation } from '@tanstack/react-query'
|
||||||
import { InferRequestType, InferResponseType } from 'hono/client'
|
import { InferRequestType, InferResponseType } from 'hono/client'
|
||||||
|
|
||||||
import type { AssetInfo, CommentInfo } from '@shumai/dtos'
|
import type { AssetInfo, AssetInfoPaginatedList, CommentInfo } from '@shumai/dtos'
|
||||||
import { keepPreviousData, useQuery, useQueryClient } from '@tanstack/react-query'
|
import { keepPreviousData, useQuery, useQueryClient } from '@tanstack/react-query'
|
||||||
import { createFileRoute, useNavigate } from '@tanstack/react-router'
|
import { createFileRoute, useNavigate } from '@tanstack/react-router'
|
||||||
import { Loader2 } from 'lucide-react'
|
import { Loader2 } from 'lucide-react'
|
||||||
@@ -26,13 +25,7 @@ function FileViewPage() {
|
|||||||
const activeFileId = versionAssetId || fileId
|
const activeFileId = versionAssetId || fileId
|
||||||
|
|
||||||
const videoRef = useRef<Player | null>(null)
|
const videoRef = useRef<Player | null>(null)
|
||||||
const {
|
|
||||||
fileViewRightSidebarCollapsed: isRightSidebarCollapsed,
|
|
||||||
fileViewLeftSidebarCollapsed: isLeftSidebarCollapsed,
|
|
||||||
setFileViewLeftSidebarCollapsed: setIsLeftSidebarCollapsed,
|
|
||||||
} = useUiStore()
|
|
||||||
const { teamId, ensureTeamIdForProject } = useTeamContextStore()
|
const { teamId, ensureTeamIdForProject } = useTeamContextStore()
|
||||||
const [leftSidebarWidth, setLeftSidebarWidth] = useState(280)
|
|
||||||
const [rightSidebarWidth, setRightSidebarWidth] = useState(360)
|
const [rightSidebarWidth, setRightSidebarWidth] = useState(360)
|
||||||
const [annotations, setAnnotations] = useState<Annotation[]>([])
|
const [annotations, setAnnotations] = useState<Annotation[]>([])
|
||||||
const [currentTime, setCurrentTime] = useState(0)
|
const [currentTime, setCurrentTime] = useState(0)
|
||||||
@@ -222,30 +215,110 @@ function FileViewPage() {
|
|||||||
setSelectedCommentId(null)
|
setSelectedCommentId(null)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
const parentFolderId =
|
||||||
|
fileData.ancestorFolders?.[fileData.ancestorFolders.length - 1]?.id ??
|
||||||
|
projectInfo.rootFolder ??
|
||||||
|
''
|
||||||
|
|
||||||
|
const [carouselState, setCarouselState] = useState<{
|
||||||
|
show: boolean
|
||||||
|
files: AssetInfo[]
|
||||||
|
nextCursor?: string
|
||||||
|
folderId?: string
|
||||||
|
}>({ show: false, files: [], nextCursor: undefined, folderId: undefined })
|
||||||
|
|
||||||
|
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])
|
||||||
|
|
||||||
return (
|
return (
|
||||||
<div className="h-full flex flex-1 flex-col bg-background">
|
<div className="h-full flex flex-1 flex-col bg-background">
|
||||||
<div className="h-full flex flex-1 overflow-hidden">
|
<div className="h-full flex flex-1 overflow-hidden">
|
||||||
{!isLeftSidebarCollapsed && (
|
{carouselState.show && (
|
||||||
<>
|
<FileViewerLeftSidebar
|
||||||
<div style={{ width: leftSidebarWidth }} className="flex-shrink-0">
|
projectId={projectId}
|
||||||
<FileViewerLeftSidebar
|
currentAssetId={activeFileId}
|
||||||
projectId={projectId}
|
parentFolderId={parentFolderId}
|
||||||
currentAssetId={activeFileId}
|
initialFiles={carouselState.files}
|
||||||
parentFolderId={
|
initialNextCursor={carouselState.nextCursor}
|
||||||
fileData.ancestorFolders?.[fileData.ancestorFolders.length - 1]?.id ??
|
/>
|
||||||
projectInfo.rootFolder ??
|
|
||||||
''
|
|
||||||
}
|
|
||||||
onCollapse={() => setIsLeftSidebarCollapsed(true)}
|
|
||||||
/>
|
|
||||||
</div>
|
|
||||||
<ResizeHandle
|
|
||||||
onResize={(delta) => {
|
|
||||||
setLeftSidebarWidth((prev) => Math.max(200, Math.min(500, prev + delta)))
|
|
||||||
}}
|
|
||||||
className="hidden md:block"
|
|
||||||
/>
|
|
||||||
</>
|
|
||||||
)}
|
)}
|
||||||
<div className="flex-1 relative">
|
<div className="flex-1 relative">
|
||||||
{isFetching && (
|
{isFetching && (
|
||||||
@@ -261,33 +334,29 @@ function FileViewPage() {
|
|||||||
annotations={annotations}
|
annotations={annotations}
|
||||||
/>
|
/>
|
||||||
</div>
|
</div>
|
||||||
{!isRightSidebarCollapsed && (
|
<ResizeHandle
|
||||||
<>
|
onResize={(delta) => {
|
||||||
<ResizeHandle
|
setRightSidebarWidth((prev) => Math.max(300, Math.min(600, prev - delta)))
|
||||||
onResize={(delta) => {
|
}}
|
||||||
setRightSidebarWidth((prev) => Math.max(300, Math.min(600, prev - delta)))
|
className="hidden md:block"
|
||||||
}}
|
/>
|
||||||
className="hidden md:block"
|
<div style={{ width: rightSidebarWidth }} className="flex-shrink-0">
|
||||||
/>
|
<FileViewerRightSidebar
|
||||||
<div style={{ width: rightSidebarWidth }} className="flex-shrink-0">
|
teamId={teamId}
|
||||||
<FileViewerRightSidebar
|
projectId={projectId}
|
||||||
teamId={teamId}
|
file={fileData as unknown as AssetInfo}
|
||||||
projectId={projectId}
|
onSaveField={handleSaveField}
|
||||||
file={fileData as unknown as AssetInfo}
|
members={members}
|
||||||
onSaveField={handleSaveField}
|
onCommentSelect={handleCommentSelect}
|
||||||
members={members}
|
currentTime={currentTime}
|
||||||
onCommentSelect={handleCommentSelect}
|
onTyping={() => {
|
||||||
currentTime={currentTime}
|
if (videoRef.current) {
|
||||||
onTyping={() => {
|
videoRef.current.pause()
|
||||||
if (videoRef.current) {
|
}
|
||||||
videoRef.current.pause()
|
}}
|
||||||
}
|
selectedCommentId={selectedCommentId}
|
||||||
}}
|
/>
|
||||||
selectedCommentId={selectedCommentId}
|
</div>
|
||||||
/>
|
|
||||||
</div>
|
|
||||||
</>
|
|
||||||
)}
|
|
||||||
</div>
|
</div>
|
||||||
</div>
|
</div>
|
||||||
)
|
)
|
||||||
|
|||||||
Reference in New Issue
Block a user