mirror of
https://github.com/shumaiOne/shumai.git
synced 2026-12-04 06:54:28 +00:00
fix(webui): fix loading skeleton layout mismatches and keep left carousel visible (#485)
* fix(webui): fix loading skeleton layout mismatches and keep left carousel visible * fix(webui): update mobile file list skeleton to match card layout * fix(webui): blur video poster before playback with instant cut on play * docs: consolidate webui changelog entries into single line
This commit is contained in:
@@ -14,6 +14,7 @@ The format is based on [Keep a Changelog](https://keepachangelog.com/en/1.1.0/).
|
|||||||
### Fixed
|
### Fixed
|
||||||
|
|
||||||
* **transcode**: Fix an issue where PDF, 3D model, and image background transcode workflows could fail with missing temporary file errors if a worker restarted or recovered midway through processing
|
* **transcode**: Fix an issue where PDF, 3D model, and image background transcode workflows could fail with missing temporary file errors if a worker restarted or recovered midway through processing
|
||||||
|
* **webui**: Improve file list and detail loading with matching skeleton layouts, a persistent sidebar carousel to eliminate layout shift, and smoothed video poster previews
|
||||||
|
|
||||||
### Changed
|
### Changed
|
||||||
|
|
||||||
|
|||||||
@@ -227,4 +227,38 @@ describe('FileViewerLeftSidebar', () => {
|
|||||||
expect(agentBadge?.getAttribute('title')).toBe('DrawBot')
|
expect(agentBadge?.getAttribute('title')).toBe('DrawBot')
|
||||||
expect(agentBadge?.textContent).toBe('AI')
|
expect(agentBadge?.textContent).toBe('AI')
|
||||||
})
|
})
|
||||||
|
|
||||||
|
it('renders thumbnail skeletons when isLoading is true and initialFiles is empty', () => {
|
||||||
|
const { container } = render(
|
||||||
|
<FileViewerLeftSidebar
|
||||||
|
projectId="proj-1"
|
||||||
|
currentAssetId="file-1"
|
||||||
|
parentFolderId="folder-1"
|
||||||
|
initialFiles={[]}
|
||||||
|
initialNextCursor={undefined}
|
||||||
|
isLoading={true}
|
||||||
|
/>,
|
||||||
|
)
|
||||||
|
|
||||||
|
const skeletons = container.querySelectorAll('[data-testid="carousel-skeleton-item"]')
|
||||||
|
expect(skeletons.length).toBe(6)
|
||||||
|
})
|
||||||
|
|
||||||
|
it('renders files instead of skeletons when isLoading is false', () => {
|
||||||
|
const { container } = render(
|
||||||
|
<FileViewerLeftSidebar
|
||||||
|
projectId="proj-1"
|
||||||
|
currentAssetId="file-1"
|
||||||
|
parentFolderId="folder-1"
|
||||||
|
initialFiles={mockFiles}
|
||||||
|
initialNextCursor={undefined}
|
||||||
|
isLoading={false}
|
||||||
|
/>,
|
||||||
|
)
|
||||||
|
|
||||||
|
const skeletons = container.querySelectorAll('[data-testid="carousel-skeleton-item"]')
|
||||||
|
expect(skeletons.length).toBe(0)
|
||||||
|
const links = container.querySelectorAll('[data-testid="carousel-link"]')
|
||||||
|
expect(links.length).toBe(3)
|
||||||
|
})
|
||||||
})
|
})
|
||||||
|
|||||||
@@ -6,6 +6,7 @@ import { File, Loader2, AudioLines } from 'lucide-react'
|
|||||||
import type { FC } from 'react'
|
import type { FC } from 'react'
|
||||||
import { useEffect, useRef, useState } from 'react'
|
import { useEffect, useRef, useState } from 'react'
|
||||||
import { useInView } from 'react-intersection-observer'
|
import { useInView } from 'react-intersection-observer'
|
||||||
|
import { Skeleton } from '@/ui/components/ui/skeleton'
|
||||||
|
|
||||||
interface FileViewerLeftSidebarProps {
|
interface FileViewerLeftSidebarProps {
|
||||||
projectId: string
|
projectId: string
|
||||||
@@ -13,6 +14,7 @@ interface FileViewerLeftSidebarProps {
|
|||||||
parentFolderId: string
|
parentFolderId: string
|
||||||
initialFiles: AssetInfo[]
|
initialFiles: AssetInfo[]
|
||||||
initialNextCursor: string | undefined
|
initialNextCursor: string | undefined
|
||||||
|
isLoading?: boolean
|
||||||
}
|
}
|
||||||
|
|
||||||
export const CarouselFilePreview = ({ item }: { item: AssetInfo }) => {
|
export const CarouselFilePreview = ({ item }: { item: AssetInfo }) => {
|
||||||
@@ -44,6 +46,7 @@ export const FileViewerLeftSidebar: FC<FileViewerLeftSidebarProps> = ({
|
|||||||
parentFolderId,
|
parentFolderId,
|
||||||
initialFiles,
|
initialFiles,
|
||||||
initialNextCursor,
|
initialNextCursor,
|
||||||
|
isLoading = false,
|
||||||
}) => {
|
}) => {
|
||||||
const { ref, inView } = useInView({
|
const { ref, inView } = useInView({
|
||||||
threshold: 0,
|
threshold: 0,
|
||||||
@@ -122,43 +125,51 @@ export const FileViewerLeftSidebar: FC<FileViewerLeftSidebarProps> = ({
|
|||||||
return (
|
return (
|
||||||
<div className="h-24 md:h-full w-full md:w-24 bg-gray-100 dark:bg-gray-950 flex flex-row md:flex-col flex-shrink-0 select-none">
|
<div className="h-24 md:h-full w-full md:w-24 bg-gray-100 dark:bg-gray-950 flex flex-row md:flex-col flex-shrink-0 select-none">
|
||||||
<div className="flex-1 overflow-x-auto overflow-y-hidden md:overflow-y-auto md:overflow-x-hidden px-4 md:px-0 py-2 md:py-4 flex flex-row md:flex-col items-center gap-3 no-scrollbar">
|
<div className="flex-1 overflow-x-auto overflow-y-hidden md:overflow-y-auto md:overflow-x-hidden px-4 md:px-0 py-2 md:py-4 flex flex-row md:flex-col items-center gap-3 no-scrollbar">
|
||||||
{files.map((file) => {
|
{isLoading && files.length === 0
|
||||||
if (!file) return null
|
? Array.from({ length: 6 }).map((_, i) => (
|
||||||
const isActive = file.id === currentAssetId
|
<Skeleton
|
||||||
return (
|
key={i}
|
||||||
<div
|
className="w-[52px] h-[52px] rounded-lg shrink-0"
|
||||||
key={file.id}
|
data-testid="carousel-skeleton-item"
|
||||||
ref={file.id === currentAssetId ? activeItemRef : null}
|
/>
|
||||||
className="flex-shrink-0"
|
))
|
||||||
>
|
: files.map((file) => {
|
||||||
<Link
|
if (!file) return null
|
||||||
to="/projects/$projectId/files/$fileId"
|
const isActive = file.id === currentAssetId
|
||||||
params={{ projectId, fileId: file.id }}
|
return (
|
||||||
search={{ version: undefined }}
|
<div
|
||||||
className={cn(
|
key={file.id}
|
||||||
'rounded-lg border overflow-hidden flex items-center justify-center transition-all bg-muted/30 block relative',
|
ref={file.id === currentAssetId ? activeItemRef : null}
|
||||||
isActive
|
className="flex-shrink-0"
|
||||||
? 'w-[62px] h-[62px] opacity-100'
|
>
|
||||||
: 'w-[52px] h-[52px] opacity-60 hover:opacity-100',
|
<Link
|
||||||
)}
|
to="/projects/$projectId/files/$fileId"
|
||||||
>
|
params={{ projectId, fileId: file.id }}
|
||||||
<CarouselFilePreview item={file} />
|
search={{ version: undefined }}
|
||||||
{file.agent && (
|
className={cn(
|
||||||
<span
|
'rounded-lg border overflow-hidden flex items-center justify-center transition-all bg-muted/30 block relative',
|
||||||
className="absolute top-1 right-1 z-10 pointer-events-none select-none rounded bg-black/60 px-1 py-0.5 text-[10px] font-medium leading-none text-white"
|
isActive
|
||||||
title={file.agent.name}
|
? 'w-[62px] h-[62px] opacity-100'
|
||||||
data-testid="carousel-agent-badge"
|
: 'w-[52px] h-[52px] opacity-60 hover:opacity-100',
|
||||||
|
)}
|
||||||
>
|
>
|
||||||
AI
|
<CarouselFilePreview item={file} />
|
||||||
</span>
|
{file.agent && (
|
||||||
)}
|
<span
|
||||||
</Link>
|
className="absolute top-1 right-1 z-10 pointer-events-none select-none rounded bg-black/60 px-1 py-0.5 text-[10px] font-medium leading-none text-white"
|
||||||
</div>
|
title={file.agent.name}
|
||||||
)
|
data-testid="carousel-agent-badge"
|
||||||
})}
|
>
|
||||||
|
AI
|
||||||
|
</span>
|
||||||
|
)}
|
||||||
|
</Link>
|
||||||
|
</div>
|
||||||
|
)
|
||||||
|
})}
|
||||||
|
|
||||||
{/* Infinite Scroll Trigger */}
|
{/* Infinite Scroll Trigger */}
|
||||||
{hasMore && (
|
{!isLoading && hasMore && (
|
||||||
<div
|
<div
|
||||||
ref={ref}
|
ref={ref}
|
||||||
className="px-2 md:px-0 py-2 md:py-4 flex justify-center items-center h-full md:w-full flex-shrink-0"
|
className="px-2 md:px-0 py-2 md:py-4 flex justify-center items-center h-full md:w-full flex-shrink-0"
|
||||||
|
|||||||
@@ -0,0 +1,38 @@
|
|||||||
|
// @vitest-environment happy-dom
|
||||||
|
import React from 'react'
|
||||||
|
import { cleanup, render, screen } from '@testing-library/react'
|
||||||
|
import { afterEach, describe, expect, it } from 'vitest'
|
||||||
|
import {
|
||||||
|
FileDetailSkeleton,
|
||||||
|
MobileFileBrowserContentSkeleton,
|
||||||
|
ProjectFolderSkeleton,
|
||||||
|
} from './loading-skeletons'
|
||||||
|
|
||||||
|
describe('loading-skeletons', () => {
|
||||||
|
afterEach(() => {
|
||||||
|
cleanup()
|
||||||
|
})
|
||||||
|
|
||||||
|
it('renders MobileFileBrowserContentSkeleton with card layout', () => {
|
||||||
|
render(<MobileFileBrowserContentSkeleton />)
|
||||||
|
const skeleton = screen.getByTestId('mobile-file-browser-loading-skeleton')
|
||||||
|
expect(skeleton).toBeDefined()
|
||||||
|
|
||||||
|
// Assert cards with aspect-square are rendered
|
||||||
|
const aspectSquareElements = skeleton.querySelectorAll('.aspect-square')
|
||||||
|
expect(aspectSquareElements.length).toBe(3)
|
||||||
|
})
|
||||||
|
|
||||||
|
it('renders ProjectFolderSkeleton containing desktop and mobile layouts', () => {
|
||||||
|
const { container } = render(<ProjectFolderSkeleton />)
|
||||||
|
expect(screen.getByTestId('mobile-file-browser-loading-skeleton')).toBeDefined()
|
||||||
|
expect(container.querySelector('[data-testid="file-browser-loading-skeleton"]')).toBeDefined()
|
||||||
|
})
|
||||||
|
|
||||||
|
it('renders FileDetailSkeleton without top nav duplicate', () => {
|
||||||
|
const { container } = render(<FileDetailSkeleton />)
|
||||||
|
// Left sidebar carousel skeleton should exist on desktop
|
||||||
|
const carouselCards = container.querySelectorAll('.w-24 .rounded-lg')
|
||||||
|
expect(carouselCards.length).toBe(6)
|
||||||
|
})
|
||||||
|
})
|
||||||
@@ -2,46 +2,38 @@ import { Skeleton } from '@/ui/components/ui/skeleton'
|
|||||||
|
|
||||||
export function ProjectFolderSkeleton() {
|
export function ProjectFolderSkeleton() {
|
||||||
return (
|
return (
|
||||||
<div className="flex h-screen flex-col bg-background min-h-0">
|
<div className="flex flex-1 overflow-hidden bg-background min-h-0">
|
||||||
{/* Top navigation/breadcrumbs placeholder */}
|
{/* Sidebar (Folder tree placeholder) */}
|
||||||
<div className="flex h-14 items-center justify-between border-b px-6 shrink-0">
|
<div className="w-[240px] border-r p-4 space-y-4 hidden md:block shrink-0">
|
||||||
<div className="flex items-center gap-2">
|
<div className="flex items-center gap-2">
|
||||||
|
<Skeleton className="h-4 w-4 rounded" />
|
||||||
<Skeleton className="h-4 w-24" />
|
<Skeleton className="h-4 w-24" />
|
||||||
<span className="text-muted-foreground">/</span>
|
|
||||||
<Skeleton className="h-4 w-32" />
|
|
||||||
</div>
|
</div>
|
||||||
<div className="flex items-center gap-2">
|
<div className="pl-4 space-y-3">
|
||||||
<Skeleton className="h-8 w-8 rounded-md" />
|
<div className="flex items-center gap-2">
|
||||||
<Skeleton className="h-8 w-20 rounded-md" />
|
<Skeleton className="h-3 w-3 rounded" />
|
||||||
|
<Skeleton className="h-3 w-28" />
|
||||||
|
</div>
|
||||||
|
<div className="flex items-center gap-2">
|
||||||
|
<Skeleton className="h-3 w-3 rounded" />
|
||||||
|
<Skeleton className="h-3 w-20" />
|
||||||
|
</div>
|
||||||
|
<div className="flex items-center gap-2">
|
||||||
|
<Skeleton className="h-3 w-3 rounded" />
|
||||||
|
<Skeleton className="h-3 w-24" />
|
||||||
|
</div>
|
||||||
</div>
|
</div>
|
||||||
</div>
|
</div>
|
||||||
|
|
||||||
<div className="flex flex-1 overflow-hidden">
|
{/* Main content area */}
|
||||||
{/* Sidebar (Folder tree placeholder) */}
|
<div className="flex-1 overflow-y-auto">
|
||||||
<div className="w-[240px] border-r p-4 space-y-4 hidden md:block shrink-0">
|
{/* Mobile: matches MobileFileBrowserContentSkeleton */}
|
||||||
<div className="flex items-center gap-2">
|
<div className="block md:hidden">
|
||||||
<Skeleton className="h-4 w-4 rounded" />
|
<MobileFileBrowserContentSkeleton />
|
||||||
<Skeleton className="h-4 w-24" />
|
|
||||||
</div>
|
|
||||||
<div className="pl-4 space-y-3">
|
|
||||||
<div className="flex items-center gap-2">
|
|
||||||
<Skeleton className="h-3 w-3 rounded" />
|
|
||||||
<Skeleton className="h-3 w-28" />
|
|
||||||
</div>
|
|
||||||
<div className="flex items-center gap-2">
|
|
||||||
<Skeleton className="h-3 w-3 rounded" />
|
|
||||||
<Skeleton className="h-3 w-20" />
|
|
||||||
</div>
|
|
||||||
<div className="flex items-center gap-2">
|
|
||||||
<Skeleton className="h-3 w-3 rounded" />
|
|
||||||
<Skeleton className="h-3 w-24" />
|
|
||||||
</div>
|
|
||||||
</div>
|
|
||||||
</div>
|
</div>
|
||||||
|
|
||||||
{/* File Browser area */}
|
{/* Desktop: file browser toolbar + card grid */}
|
||||||
<div className="flex-1 p-6 space-y-6 overflow-y-auto">
|
<div className="hidden md:block p-6 space-y-6">
|
||||||
{/* File browser toolbar */}
|
|
||||||
<div className="flex items-center justify-between border-b pb-4">
|
<div className="flex items-center justify-between border-b pb-4">
|
||||||
<div className="flex items-center gap-4">
|
<div className="flex items-center gap-4">
|
||||||
<Skeleton className="h-5 w-40" />
|
<Skeleton className="h-5 w-40" />
|
||||||
@@ -53,27 +45,7 @@ export function ProjectFolderSkeleton() {
|
|||||||
<Skeleton className="h-8 w-32 rounded" />
|
<Skeleton className="h-8 w-32 rounded" />
|
||||||
</div>
|
</div>
|
||||||
</div>
|
</div>
|
||||||
|
<FileBrowserContentSkeleton />
|
||||||
{/* Cards Grid */}
|
|
||||||
<div className="space-y-4">
|
|
||||||
<div className="flex items-center gap-2">
|
|
||||||
<Skeleton className="h-4 w-24" />
|
|
||||||
</div>
|
|
||||||
<div className="grid grid-cols-1 gap-4 sm:grid-cols-2 md:grid-cols-3 lg:grid-cols-4 xl:grid-cols-5">
|
|
||||||
{Array.from({ length: 10 }).map((_, i) => (
|
|
||||||
<div key={i} className="flex flex-col rounded-lg border bg-card p-3 space-y-3">
|
|
||||||
<Skeleton className="aspect-square w-full rounded-md" />
|
|
||||||
<div className="space-y-2">
|
|
||||||
<Skeleton className="h-4 w-3/4" />
|
|
||||||
<div className="flex justify-between items-center">
|
|
||||||
<Skeleton className="h-3 w-1/4" />
|
|
||||||
<Skeleton className="h-3 w-1/3" />
|
|
||||||
</div>
|
|
||||||
</div>
|
|
||||||
</div>
|
|
||||||
))}
|
|
||||||
</div>
|
|
||||||
</div>
|
|
||||||
</div>
|
</div>
|
||||||
</div>
|
</div>
|
||||||
</div>
|
</div>
|
||||||
@@ -82,54 +54,69 @@ export function ProjectFolderSkeleton() {
|
|||||||
|
|
||||||
export function FileDetailSkeleton() {
|
export function FileDetailSkeleton() {
|
||||||
return (
|
return (
|
||||||
<div className="h-screen flex flex-col bg-background">
|
<div className="h-full flex-1 flex flex-col bg-background overflow-hidden">
|
||||||
{/* Top navigation */}
|
{/* Mobile-only view: matches MobileFileDetail */}
|
||||||
<div className="flex h-14 items-center justify-between border-b px-6 shrink-0">
|
<div className="flex md:hidden flex-col h-full w-full overflow-hidden">
|
||||||
<div className="flex items-center gap-2">
|
{/* Mobile File Header placeholder */}
|
||||||
<Skeleton className="h-4 w-16" />
|
<div className="h-14 flex items-center justify-between border-b px-4 shrink-0 bg-card">
|
||||||
<span className="text-muted-foreground">/</span>
|
<div className="flex items-center gap-2">
|
||||||
<Skeleton className="h-4 w-28" />
|
<Skeleton className="h-8 w-8 rounded-full" />
|
||||||
<span className="text-muted-foreground">/</span>
|
<Skeleton className="h-4 w-32" />
|
||||||
<Skeleton className="h-4 w-32" />
|
</div>
|
||||||
|
<div className="flex items-center gap-2">
|
||||||
|
<Skeleton className="h-7 w-7 rounded" />
|
||||||
|
<Skeleton className="h-7 w-7 rounded" />
|
||||||
|
</div>
|
||||||
</div>
|
</div>
|
||||||
<div className="flex items-center gap-2">
|
{/* Media area placeholder */}
|
||||||
<Skeleton className="h-8 w-20 rounded" />
|
<div className="flex-1 min-h-0 bg-muted/20 flex items-center justify-center relative p-4">
|
||||||
|
<Skeleton className="w-full max-w-sm aspect-video rounded-lg" />
|
||||||
|
</div>
|
||||||
|
{/* Bottom sheet placeholder */}
|
||||||
|
<div className="h-[45%] border-t bg-card rounded-t-xl p-4 flex flex-col gap-3 shrink-0">
|
||||||
|
<div className="flex items-center justify-between border-b pb-2">
|
||||||
|
<div className="flex gap-4">
|
||||||
|
<Skeleton className="h-4 w-16" />
|
||||||
|
<Skeleton className="h-4 w-16" />
|
||||||
|
</div>
|
||||||
|
</div>
|
||||||
|
<div className="space-y-3 flex-1">
|
||||||
|
<Skeleton className="h-12 w-full rounded" />
|
||||||
|
<Skeleton className="h-12 w-full rounded" />
|
||||||
|
</div>
|
||||||
</div>
|
</div>
|
||||||
</div>
|
</div>
|
||||||
|
|
||||||
<div className="flex flex-1 overflow-hidden">
|
{/* Desktop view: Left Carousel (96px) + Center Full-Bleed Viewer + Right Sidebar (360px) */}
|
||||||
{/* Left Pane (Version stack) */}
|
<div className="hidden md:flex h-full flex-1 overflow-hidden">
|
||||||
<div className="w-[280px] border-r p-4 flex flex-col gap-4 shrink-0 hidden md:flex">
|
{/* Left Carousel Skeleton (96px / w-24) */}
|
||||||
<Skeleton className="h-5 w-24" />
|
<div className="w-24 bg-gray-100 dark:bg-gray-950 flex flex-col items-center py-4 gap-3 shrink-0 border-r">
|
||||||
<div className="space-y-3 flex-1 overflow-y-auto">
|
{Array.from({ length: 6 }).map((_, i) => (
|
||||||
{Array.from({ length: 4 }).map((_, i) => (
|
<Skeleton key={i} className="w-[52px] h-[52px] rounded-lg shrink-0" />
|
||||||
<div key={i} className="flex gap-3 p-2 rounded border">
|
))}
|
||||||
<Skeleton className="h-12 w-12 rounded bg-muted shrink-0" />
|
|
||||||
<div className="space-y-2 flex-1">
|
|
||||||
<Skeleton className="h-3 w-2/3" />
|
|
||||||
<Skeleton className="h-2 w-1/2" />
|
|
||||||
</div>
|
|
||||||
</div>
|
|
||||||
))}
|
|
||||||
</div>
|
|
||||||
</div>
|
</div>
|
||||||
|
|
||||||
{/* Center Pane (Viewer area) */}
|
{/* Center Viewer Area */}
|
||||||
<div className="flex-1 bg-muted/20 p-6 flex flex-col justify-between relative min-w-0">
|
<div className="flex-1 bg-muted/10 relative flex flex-col min-w-0 justify-between">
|
||||||
<div className="flex-1 flex items-center justify-center">
|
<div className="flex-1 flex items-center justify-center p-8">
|
||||||
<Skeleton className="w-full max-w-4xl aspect-video rounded-lg shadow-lg" />
|
<Skeleton className="w-full max-w-4xl aspect-video rounded-lg shadow-sm" />
|
||||||
</div>
|
</div>
|
||||||
<div className="mt-4 flex items-center justify-between shrink-0">
|
{/* Bottom video control bar placeholder */}
|
||||||
<div className="flex items-center gap-4">
|
<div className="h-12 border-t px-4 flex items-center justify-between bg-card shrink-0">
|
||||||
<Skeleton className="h-8 w-8 rounded-full" />
|
<div className="flex items-center gap-3">
|
||||||
<Skeleton className="h-4 w-32" />
|
<Skeleton className="h-6 w-6 rounded" />
|
||||||
|
<Skeleton className="h-4 w-20" />
|
||||||
|
</div>
|
||||||
|
<Skeleton className="h-3 flex-1 mx-6" />
|
||||||
|
<div className="flex items-center gap-2">
|
||||||
|
<Skeleton className="h-6 w-6 rounded" />
|
||||||
|
<Skeleton className="h-6 w-6 rounded" />
|
||||||
</div>
|
</div>
|
||||||
<Skeleton className="h-4 w-24" />
|
|
||||||
</div>
|
</div>
|
||||||
</div>
|
</div>
|
||||||
|
|
||||||
{/* Right Pane (Metadata and Comments) */}
|
{/* Right Sidebar Skeleton (360px) */}
|
||||||
<div className="w-[360px] border-l p-4 flex flex-col gap-6 shrink-0 hidden lg:flex bg-card">
|
<div className="w-[360px] border-l p-4 hidden lg:flex flex-col gap-6 shrink-0 bg-card">
|
||||||
{/* Metadata Section */}
|
{/* Metadata Section */}
|
||||||
<div className="space-y-4">
|
<div className="space-y-4">
|
||||||
<Skeleton className="h-5 w-32" />
|
<Skeleton className="h-5 w-32" />
|
||||||
@@ -214,18 +201,30 @@ export function FileBrowserContentSkeleton({
|
|||||||
export function MobileFileBrowserContentSkeleton() {
|
export function MobileFileBrowserContentSkeleton() {
|
||||||
return (
|
return (
|
||||||
<div
|
<div
|
||||||
className="p-3 space-y-3 max-w-lg mx-auto w-full"
|
className="p-3 pb-24 max-w-lg mx-auto w-full"
|
||||||
data-testid="mobile-file-browser-loading-skeleton"
|
data-testid="mobile-file-browser-loading-skeleton"
|
||||||
>
|
>
|
||||||
{Array.from({ length: 6 }).map((_, i) => (
|
<div className="flex items-center gap-2 mb-3">
|
||||||
<div key={i} className="flex items-center gap-3 p-3 rounded-lg border bg-card">
|
<Skeleton className="h-4 w-4 rounded" />
|
||||||
<Skeleton className="h-10 w-10 rounded-md shrink-0" />
|
<Skeleton className="h-4 w-28 rounded" />
|
||||||
<div className="space-y-2 flex-1">
|
</div>
|
||||||
<Skeleton className="h-4 w-3/4" />
|
<div className="grid grid-cols-1 gap-4 w-full">
|
||||||
<Skeleton className="h-3 w-1/3" />
|
{Array.from({ length: 3 }).map((_, i) => (
|
||||||
|
<div
|
||||||
|
key={i}
|
||||||
|
className="flex flex-col overflow-hidden rounded-xl border border-border bg-card m-1"
|
||||||
|
>
|
||||||
|
<Skeleton className="aspect-square w-full rounded-none" />
|
||||||
|
<div className="p-3 space-y-2">
|
||||||
|
<Skeleton className="h-4 w-3/4" />
|
||||||
|
<div className="flex justify-between items-center pt-1">
|
||||||
|
<Skeleton className="h-3 w-1/3" />
|
||||||
|
<Skeleton className="h-3 w-1/4" />
|
||||||
|
</div>
|
||||||
|
</div>
|
||||||
</div>
|
</div>
|
||||||
</div>
|
))}
|
||||||
))}
|
</div>
|
||||||
</div>
|
</div>
|
||||||
)
|
)
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -0,0 +1,84 @@
|
|||||||
|
// @vitest-environment happy-dom
|
||||||
|
import React from 'react'
|
||||||
|
import { cleanup, render, screen } from '@testing-library/react'
|
||||||
|
import { afterEach, beforeEach, describe, expect, it, vi } from 'vitest'
|
||||||
|
import { QueryClient, QueryClientProvider } from '@tanstack/react-query'
|
||||||
|
import { TopNav } from './top-nav'
|
||||||
|
import { useTopNavStore } from '@/ui/stores/top-nav'
|
||||||
|
|
||||||
|
let mockPathname = '/projects/proj-1'
|
||||||
|
let mockIsMobile = false
|
||||||
|
|
||||||
|
vi.mock('@tanstack/react-router', () => ({
|
||||||
|
Link: ({ children, to, ...props }: { children: React.ReactNode; to: string }) => (
|
||||||
|
<a href={to} {...props}>
|
||||||
|
{children}
|
||||||
|
</a>
|
||||||
|
),
|
||||||
|
useNavigate: () => vi.fn(),
|
||||||
|
useRouterState: ({ select }: { select: (s: { location: { pathname: string } }) => string }) =>
|
||||||
|
select({ location: { pathname: mockPathname } }),
|
||||||
|
}))
|
||||||
|
|
||||||
|
vi.mock('@/ui/hooks/use-mobile', () => ({
|
||||||
|
useIsMobile: () => mockIsMobile,
|
||||||
|
}))
|
||||||
|
|
||||||
|
describe('TopNav component', () => {
|
||||||
|
const queryClient = new QueryClient({
|
||||||
|
defaultOptions: {
|
||||||
|
queries: {
|
||||||
|
retry: false,
|
||||||
|
},
|
||||||
|
},
|
||||||
|
})
|
||||||
|
|
||||||
|
beforeEach(() => {
|
||||||
|
useTopNavStore.getState().clearProjectState()
|
||||||
|
mockPathname = '/projects/proj-1'
|
||||||
|
mockIsMobile = false
|
||||||
|
})
|
||||||
|
|
||||||
|
afterEach(() => {
|
||||||
|
cleanup()
|
||||||
|
vi.clearAllMocks()
|
||||||
|
})
|
||||||
|
|
||||||
|
it('renders TopNavBreadcrumbSkeleton on project routes when projectState is not loaded', () => {
|
||||||
|
mockPathname = '/projects/proj-1'
|
||||||
|
const { container } = render(
|
||||||
|
<QueryClientProvider client={queryClient}>
|
||||||
|
<TopNav />
|
||||||
|
</QueryClientProvider>,
|
||||||
|
)
|
||||||
|
|
||||||
|
expect(screen.getByTestId('top-nav-breadcrumb-skeleton')).toBeDefined()
|
||||||
|
// Ensure center ShumaiLogo is NOT rendered
|
||||||
|
expect(container.querySelector('.text-orange-600')).toBeNull()
|
||||||
|
})
|
||||||
|
|
||||||
|
it('renders TeamHeader with logo on non-project routes when projectState is not loaded', () => {
|
||||||
|
mockPathname = '/teams/team-1'
|
||||||
|
const { container } = render(
|
||||||
|
<QueryClientProvider client={queryClient}>
|
||||||
|
<TopNav />
|
||||||
|
</QueryClientProvider>,
|
||||||
|
)
|
||||||
|
|
||||||
|
expect(screen.queryByTestId('top-nav-breadcrumb-skeleton')).toBeNull()
|
||||||
|
// TeamHeader contains ShumaiLogo with text-orange-600
|
||||||
|
expect(container.querySelector('.text-orange-600')).not.toBeNull()
|
||||||
|
})
|
||||||
|
|
||||||
|
it('returns null on mobile when navigating file routes', () => {
|
||||||
|
mockPathname = '/projects/proj-1/files/file-1'
|
||||||
|
mockIsMobile = true
|
||||||
|
const { container } = render(
|
||||||
|
<QueryClientProvider client={queryClient}>
|
||||||
|
<TopNav />
|
||||||
|
</QueryClientProvider>,
|
||||||
|
)
|
||||||
|
|
||||||
|
expect(container.firstChild).toBeNull()
|
||||||
|
})
|
||||||
|
})
|
||||||
@@ -5,6 +5,28 @@ import { useUiStore } from '@/ui/stores/ui'
|
|||||||
import { useChatbotStore } from '@/ui/stores/chatbot'
|
import { useChatbotStore } from '@/ui/stores/chatbot'
|
||||||
import { useUserMetadataStore } from '@/ui/stores/user-metadata'
|
import { useUserMetadataStore } from '@/ui/stores/user-metadata'
|
||||||
import { useIsMobile } from '@/ui/hooks/use-mobile'
|
import { useIsMobile } from '@/ui/hooks/use-mobile'
|
||||||
|
import { Skeleton } from '@/ui/components/ui/skeleton'
|
||||||
|
import { useRouterState } from '@tanstack/react-router'
|
||||||
|
|
||||||
|
export function TopNavBreadcrumbSkeleton() {
|
||||||
|
return (
|
||||||
|
<div
|
||||||
|
className="flex h-14 flex-nowrap items-center justify-between gap-2 border-b border-border bg-card px-4 py-2 flex-shrink-0"
|
||||||
|
data-testid="top-nav-breadcrumb-skeleton"
|
||||||
|
>
|
||||||
|
<div className="flex min-w-0 flex-1 items-center gap-2 overflow-hidden">
|
||||||
|
<Skeleton className="h-5 w-5 rounded md:hidden shrink-0 -ml-1 mr-1" />
|
||||||
|
<Skeleton className="h-4 w-20 md:w-28 shrink-0" />
|
||||||
|
<span className="text-muted-foreground text-xs">/</span>
|
||||||
|
<Skeleton className="h-4 w-24 md:w-36 shrink-0" />
|
||||||
|
</div>
|
||||||
|
<div className="hidden md:flex items-center gap-2 shrink-0">
|
||||||
|
<Skeleton className="h-8 w-20 rounded-md" />
|
||||||
|
<Skeleton className="h-8 w-8 rounded-md" />
|
||||||
|
</div>
|
||||||
|
</div>
|
||||||
|
)
|
||||||
|
}
|
||||||
|
|
||||||
export function TopNav() {
|
export function TopNav() {
|
||||||
const { projectState } = useTopNavStore()
|
const { projectState } = useTopNavStore()
|
||||||
@@ -12,12 +34,16 @@ export function TopNav() {
|
|||||||
const { isChatbotOpen, setIsChatbotOpen } = useChatbotStore()
|
const { isChatbotOpen, setIsChatbotOpen } = useChatbotStore()
|
||||||
const hideAgent = useUserMetadataStore((s) => Boolean(s.metadata['appearance.hideAgent']))
|
const hideAgent = useUserMetadataStore((s) => Boolean(s.metadata['appearance.hideAgent']))
|
||||||
const isMobile = useIsMobile()
|
const isMobile = useIsMobile()
|
||||||
|
const pathname = useRouterState({ select: (s) => s.location.pathname })
|
||||||
|
|
||||||
if (isMobile && projectState?.fileId) {
|
if (isMobile && (projectState?.fileId || pathname.includes('/files/'))) {
|
||||||
return null
|
return null
|
||||||
}
|
}
|
||||||
|
|
||||||
if (!projectState) {
|
if (!projectState) {
|
||||||
|
if (pathname.startsWith('/projects/')) {
|
||||||
|
return <TopNavBreadcrumbSkeleton />
|
||||||
|
}
|
||||||
return <TeamHeader />
|
return <TeamHeader />
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@@ -346,6 +346,15 @@ describe('CompareVideoPane', () => {
|
|||||||
'[data-testid="compare-video-area"] video',
|
'[data-testid="compare-video-area"] video',
|
||||||
) as HTMLVideoElement
|
) as HTMLVideoElement
|
||||||
expect(video.getAttribute('poster')).toBe('https://cdn.example.com/compare-poster.jpg')
|
expect(video.getAttribute('poster')).toBe('https://cdn.example.com/compare-poster.jpg')
|
||||||
|
expect(video.className).toContain('blur-md')
|
||||||
|
expect(video.className).toContain('scale-105')
|
||||||
|
|
||||||
|
act(() => {
|
||||||
|
video.dispatchEvent(new Event('play'))
|
||||||
|
})
|
||||||
|
|
||||||
|
expect(video.className).not.toContain('blur-md')
|
||||||
|
expect(video.className).not.toContain('scale-105')
|
||||||
})
|
})
|
||||||
|
|
||||||
it('shows loading spinner initially, transitions on loadeddata, and blocks play while loading', () => {
|
it('shows loading spinner initially, transitions on loadeddata, and blocks play while loading', () => {
|
||||||
|
|||||||
@@ -718,7 +718,7 @@ export const CompareVideoPane = forwardRef<ComparePaneHandle, CompareVideoPanePr
|
|||||||
{/* Native Video Layer (Hardware-accelerated, full HDR EDR) */}
|
{/* Native Video Layer (Hardware-accelerated, full HDR EDR) */}
|
||||||
{!isAudio && (
|
{!isAudio && (
|
||||||
<div
|
<div
|
||||||
className="absolute pointer-events-none"
|
className="absolute pointer-events-none overflow-hidden"
|
||||||
style={{
|
style={{
|
||||||
left: 0,
|
left: 0,
|
||||||
top: 0,
|
top: 0,
|
||||||
@@ -730,7 +730,10 @@ export const CompareVideoPane = forwardRef<ComparePaneHandle, CompareVideoPanePr
|
|||||||
>
|
>
|
||||||
<video
|
<video
|
||||||
ref={videoRef}
|
ref={videoRef}
|
||||||
className="w-full h-full block object-contain pointer-events-none"
|
className={cn(
|
||||||
|
'w-full h-full block object-contain pointer-events-none',
|
||||||
|
!hasStartedPlaying && file.preview?.thumbnailUrl && 'blur-md scale-105',
|
||||||
|
)}
|
||||||
playsInline
|
playsInline
|
||||||
preload="auto"
|
preload="auto"
|
||||||
poster={file.preview?.thumbnailUrl || undefined}
|
poster={file.preview?.thumbnailUrl || undefined}
|
||||||
|
|||||||
@@ -567,7 +567,7 @@ describe('VideoViewer', () => {
|
|||||||
expect(settingsButton?.textContent).not.toContain('1920p')
|
expect(settingsButton?.textContent).not.toContain('1920p')
|
||||||
})
|
})
|
||||||
|
|
||||||
it('sets poster on video element from file.preview.thumbnailUrl', () => {
|
it('sets poster on video element from file.preview.thumbnailUrl and blurs until playback starts', () => {
|
||||||
const videoWithThumb: AssetInfo = {
|
const videoWithThumb: AssetInfo = {
|
||||||
id: 'video-thumb',
|
id: 'video-thumb',
|
||||||
name: 'thumb.mp4',
|
name: 'thumb.mp4',
|
||||||
@@ -597,6 +597,15 @@ describe('VideoViewer', () => {
|
|||||||
const { container } = render(<VideoViewer file={videoWithThumb} />)
|
const { container } = render(<VideoViewer file={videoWithThumb} />)
|
||||||
const video = container.querySelector('[data-testid="video-area"] video') as HTMLVideoElement
|
const video = container.querySelector('[data-testid="video-area"] video') as HTMLVideoElement
|
||||||
expect(video.getAttribute('poster')).toBe('https://cdn.example.com/poster.jpg')
|
expect(video.getAttribute('poster')).toBe('https://cdn.example.com/poster.jpg')
|
||||||
|
expect(video.className).toContain('blur-md')
|
||||||
|
expect(video.className).toContain('scale-105')
|
||||||
|
|
||||||
|
act(() => {
|
||||||
|
video.dispatchEvent(new Event('play'))
|
||||||
|
})
|
||||||
|
|
||||||
|
expect(video.className).not.toContain('blur-md')
|
||||||
|
expect(video.className).not.toContain('scale-105')
|
||||||
})
|
})
|
||||||
|
|
||||||
it('shows loading spinner initially and transitions to play overlay on loadeddata', () => {
|
it('shows loading spinner initially and transitions to play overlay on loadeddata', () => {
|
||||||
|
|||||||
@@ -1018,7 +1018,7 @@ const VideoViewer = React.forwardRef<MediaController, FileViewerProps>(
|
|||||||
{/* Native Video Layer (Hardware-accelerated, full HDR EDR) */}
|
{/* Native Video Layer (Hardware-accelerated, full HDR EDR) */}
|
||||||
{!isAudio && (
|
{!isAudio && (
|
||||||
<div
|
<div
|
||||||
className="absolute pointer-events-none"
|
className="absolute pointer-events-none overflow-hidden"
|
||||||
style={{
|
style={{
|
||||||
left: 0,
|
left: 0,
|
||||||
top: 0,
|
top: 0,
|
||||||
@@ -1030,7 +1030,10 @@ const VideoViewer = React.forwardRef<MediaController, FileViewerProps>(
|
|||||||
>
|
>
|
||||||
<video
|
<video
|
||||||
ref={videoRef}
|
ref={videoRef}
|
||||||
className="w-full h-full block object-contain pointer-events-none"
|
className={cn(
|
||||||
|
'w-full h-full block object-contain pointer-events-none',
|
||||||
|
!hasStartedPlaying && data.preview?.thumbnailUrl && 'blur-md scale-105',
|
||||||
|
)}
|
||||||
playsInline
|
playsInline
|
||||||
preload="auto"
|
preload="auto"
|
||||||
poster={data.preview?.thumbnailUrl || undefined}
|
poster={data.preview?.thumbnailUrl || undefined}
|
||||||
|
|||||||
@@ -85,7 +85,8 @@ function FileViewPage() {
|
|||||||
files: AssetInfo[]
|
files: AssetInfo[]
|
||||||
nextCursor?: string
|
nextCursor?: string
|
||||||
folderId?: string
|
folderId?: string
|
||||||
}>({ show: false, files: [], nextCursor: undefined, folderId: undefined })
|
}>({ show: true, files: [], nextCursor: undefined, folderId: undefined })
|
||||||
|
const [isCarouselLoading, setIsCarouselLoading] = useState(true)
|
||||||
const $patchMetadata = client.api.files[':fileId'].metadata.$patch
|
const $patchMetadata = client.api.files[':fileId'].metadata.$patch
|
||||||
const { mutate: patchMetadata } = useMutation<
|
const { mutate: patchMetadata } = useMutation<
|
||||||
InferResponseType<typeof $patchMetadata>,
|
InferResponseType<typeof $patchMetadata>,
|
||||||
@@ -382,9 +383,11 @@ function FileViewPage() {
|
|||||||
useEffect(() => {
|
useEffect(() => {
|
||||||
if (!parentFolderId || !activeFileId) return
|
if (!parentFolderId || !activeFileId) return
|
||||||
if (carouselState.folderId === parentFolderId) {
|
if (carouselState.folderId === parentFolderId) {
|
||||||
|
setIsCarouselLoading(false)
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
|
|
||||||
|
setIsCarouselLoading(true)
|
||||||
let isMounted = true
|
let isMounted = true
|
||||||
|
|
||||||
const fetchCarouselData = async () => {
|
const fetchCarouselData = async () => {
|
||||||
@@ -446,32 +449,30 @@ function FileViewPage() {
|
|||||||
}
|
}
|
||||||
|
|
||||||
if (isMounted) {
|
if (isMounted) {
|
||||||
if (found) {
|
const fallbackFiles = fileData ? [fileData as unknown as AssetInfo] : []
|
||||||
setCarouselState({
|
const finalFiles = found ? allFiles : fallbackFiles
|
||||||
show: true,
|
setCarouselState({
|
||||||
files: allFiles,
|
show: true,
|
||||||
nextCursor: lastCursor,
|
files: finalFiles,
|
||||||
folderId: parentFolderId,
|
nextCursor: found ? lastCursor : undefined,
|
||||||
})
|
folderId: parentFolderId,
|
||||||
} else {
|
})
|
||||||
setCarouselState({
|
|
||||||
show: false,
|
|
||||||
files: [],
|
|
||||||
nextCursor: undefined,
|
|
||||||
folderId: parentFolderId,
|
|
||||||
})
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
} catch (err) {
|
} catch (err) {
|
||||||
console.error(err)
|
console.error(err)
|
||||||
if (isMounted) {
|
if (isMounted) {
|
||||||
|
const fallbackFiles = fileData ? [fileData as unknown as AssetInfo] : []
|
||||||
setCarouselState({
|
setCarouselState({
|
||||||
show: false,
|
show: true,
|
||||||
files: [],
|
files: fallbackFiles,
|
||||||
nextCursor: undefined,
|
nextCursor: undefined,
|
||||||
folderId: parentFolderId,
|
folderId: parentFolderId,
|
||||||
})
|
})
|
||||||
}
|
}
|
||||||
|
} finally {
|
||||||
|
if (isMounted) {
|
||||||
|
setIsCarouselLoading(false)
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -480,7 +481,7 @@ function FileViewPage() {
|
|||||||
return () => {
|
return () => {
|
||||||
isMounted = false
|
isMounted = false
|
||||||
}
|
}
|
||||||
}, [parentFolderId, activeFileId, carouselState.folderId])
|
}, [parentFolderId, activeFileId, carouselState.folderId, fileData])
|
||||||
|
|
||||||
useEffect(() => {
|
useEffect(() => {
|
||||||
setCurrentTime(0)
|
setCurrentTime(0)
|
||||||
@@ -711,15 +712,14 @@ function FileViewPage() {
|
|||||||
annotations={annotations}
|
annotations={annotations}
|
||||||
startTime={startTime}
|
startTime={startTime}
|
||||||
>
|
>
|
||||||
{carouselState.show && (
|
<FileViewerLeftSidebar
|
||||||
<FileViewerLeftSidebar
|
projectId={projectId}
|
||||||
projectId={projectId}
|
currentAssetId={activeFileId}
|
||||||
currentAssetId={activeFileId}
|
parentFolderId={parentFolderId}
|
||||||
parentFolderId={parentFolderId}
|
initialFiles={carouselState.files}
|
||||||
initialFiles={carouselState.files}
|
initialNextCursor={carouselState.nextCursor}
|
||||||
initialNextCursor={carouselState.nextCursor}
|
isLoading={isCarouselLoading}
|
||||||
/>
|
/>
|
||||||
)}
|
|
||||||
</FileViewer>
|
</FileViewer>
|
||||||
)}
|
)}
|
||||||
</div>
|
</div>
|
||||||
|
|||||||
@@ -1,6 +1,8 @@
|
|||||||
import { createFileRoute } from '@tanstack/react-router'
|
import { createFileRoute } from '@tanstack/react-router'
|
||||||
|
import { FileDetailSkeleton } from '@/ui/components/loading-skeletons'
|
||||||
|
|
||||||
export const Route = createFileRoute('/projects/$projectId/files/$fileId')({
|
export const Route = createFileRoute('/projects/$projectId/files/$fileId')({
|
||||||
|
pendingComponent: () => <FileDetailSkeleton />,
|
||||||
validateSearch: (search: Record<string, unknown>) => {
|
validateSearch: (search: Record<string, unknown>) => {
|
||||||
return {
|
return {
|
||||||
version: (search.version as string) || undefined,
|
version: (search.version as string) || undefined,
|
||||||
|
|||||||
Reference in New Issue
Block a user