mirror of
https://github.com/shumaiOne/shumai.git
synced 2026-12-05 15:44:28 +00:00
feat(webui): render bottom bar for all file types and layout carousel above it
This commit is contained in:
@@ -2,7 +2,7 @@ import { useScreenSize } from '@/ui/hooks/useScreenSize'
|
|||||||
import { getBestTranscode } from '@/ui/lib/media'
|
import { getBestTranscode } from '@/ui/lib/media'
|
||||||
import type { AssetInfo } from '@shumai/dtos'
|
import type { AssetInfo } from '@shumai/dtos'
|
||||||
import { Check, Copy, Download, Minus, Plus } from 'lucide-react'
|
import { Check, Copy, Download, Minus, Plus } from 'lucide-react'
|
||||||
import type { RefObject } from 'react'
|
import type { ReactNode, RefObject } from 'react'
|
||||||
import { useEffect, useRef, useState } from 'react'
|
import { useEffect, useRef, useState } from 'react'
|
||||||
import type Player from 'video.js/dist/types/player'
|
import type Player from 'video.js/dist/types/player'
|
||||||
import DrawingCanvas from './drawing-canvas'
|
import DrawingCanvas from './drawing-canvas'
|
||||||
@@ -18,6 +18,7 @@ type FileViewerProps = {
|
|||||||
onPause?: () => void
|
onPause?: () => void
|
||||||
onTimeUpdate?: (time: number) => void
|
onTimeUpdate?: (time: number) => void
|
||||||
annotations?: Annotation[]
|
annotations?: Annotation[]
|
||||||
|
children?: ReactNode
|
||||||
}
|
}
|
||||||
|
|
||||||
export function FileViewer({
|
export function FileViewer({
|
||||||
@@ -27,6 +28,7 @@ export function FileViewer({
|
|||||||
onPause,
|
onPause,
|
||||||
onTimeUpdate,
|
onTimeUpdate,
|
||||||
annotations,
|
annotations,
|
||||||
|
children,
|
||||||
}: FileViewerProps) {
|
}: FileViewerProps) {
|
||||||
const { width: screenWidth } = useScreenSize()
|
const { width: screenWidth } = useScreenSize()
|
||||||
const isImage = file.mediaType?.startsWith('image/')
|
const isImage = file.mediaType?.startsWith('image/')
|
||||||
@@ -186,10 +188,28 @@ export function FileViewer({
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
if (!bestUrl) {
|
const isUnsupported = !bestUrl || (!isImage && !isVideo)
|
||||||
|
|
||||||
|
if (isUnsupported) {
|
||||||
return (
|
return (
|
||||||
<div className="flex flex-1 items-center justify-center">
|
<div className="flex flex-col flex-1 h-full overflow-hidden bg-gray-100 dark:bg-gray-950 relative">
|
||||||
<p className="text-muted-foreground">Preview unavailable</p>
|
<div className="flex-1 flex min-h-0 relative">
|
||||||
|
{children}
|
||||||
|
<div className="flex-1 flex items-center justify-center">
|
||||||
|
<p className="text-muted-foreground">Preview unavailable</p>
|
||||||
|
</div>
|
||||||
|
</div>
|
||||||
|
<div className="relative px-4 py-3 bg-card border-t border-gray-200 dark:border-gray-700 z-10 flex items-center justify-end gap-2 transition-colors duration-200">
|
||||||
|
<button
|
||||||
|
onClick={handleDownload}
|
||||||
|
disabled={!file.media?.original?.downloadUrl}
|
||||||
|
className="flex items-center gap-1.5 text-xs font-medium px-3 py-1.5 rounded bg-gray-200/50 dark:bg-white/10 hover:bg-gray-300 dark:hover:bg-gray-600 text-gray-700 dark:text-gray-200 transition-colors border border-transparent disabled:opacity-50 animate-in fade-in zoom-in-95 duration-200"
|
||||||
|
title="Download original file"
|
||||||
|
>
|
||||||
|
<Download size={14} />
|
||||||
|
Download
|
||||||
|
</button>
|
||||||
|
</div>
|
||||||
</div>
|
</div>
|
||||||
)
|
)
|
||||||
}
|
}
|
||||||
@@ -201,26 +221,29 @@ export function FileViewer({
|
|||||||
<div className="flex flex-col flex-1 h-full overflow-hidden bg-gray-100 dark:bg-gray-950 relative">
|
<div className="flex flex-col flex-1 h-full overflow-hidden bg-gray-100 dark:bg-gray-950 relative">
|
||||||
{isImage && (
|
{isImage && (
|
||||||
<>
|
<>
|
||||||
<div ref={containerRef} className="flex-1 relative overflow-hidden">
|
<div className="flex-1 flex min-h-0 relative">
|
||||||
<DrawingCanvas
|
{children}
|
||||||
width={conW}
|
<div ref={containerRef} className="flex-1 relative overflow-hidden">
|
||||||
height={conH}
|
<DrawingCanvas
|
||||||
mediaDimensions={{
|
width={conW}
|
||||||
width: imgW,
|
height={conH}
|
||||||
height: imgH,
|
mediaDimensions={{
|
||||||
}}
|
width: imgW,
|
||||||
imageUrl={bestUrl}
|
height: imgH,
|
||||||
annotations={displayAnnotations}
|
}}
|
||||||
scale={zoom}
|
imageUrl={bestUrl}
|
||||||
offset={pan}
|
annotations={displayAnnotations}
|
||||||
onPan={setPan}
|
scale={zoom}
|
||||||
className="absolute inset-0 z-0"
|
offset={pan}
|
||||||
// Drawing Props
|
onPan={setPan}
|
||||||
isDrawing={isDrawing}
|
className="absolute inset-0 z-0"
|
||||||
currentTool={currentTool}
|
// Drawing Props
|
||||||
currentColor={currentColor}
|
isDrawing={isDrawing}
|
||||||
onAddAnnotation={addAnnotation}
|
currentTool={currentTool}
|
||||||
/>
|
currentColor={currentColor}
|
||||||
|
onAddAnnotation={addAnnotation}
|
||||||
|
/>
|
||||||
|
</div>
|
||||||
</div>
|
</div>
|
||||||
{/* Zoom Toolbar */}
|
{/* Zoom Toolbar */}
|
||||||
<div className="relative px-4 py-3 bg-card border-t border-gray-200 dark:border-gray-700 z-10 flex items-center justify-end gap-2 transition-colors duration-200">
|
<div className="relative px-4 py-3 bg-card border-t border-gray-200 dark:border-gray-700 z-10 flex items-center justify-end gap-2 transition-colors duration-200">
|
||||||
@@ -278,7 +301,9 @@ export function FileViewer({
|
|||||||
onPause={onPause}
|
onPause={onPause}
|
||||||
onTimeUpdate={onTimeUpdate}
|
onTimeUpdate={onTimeUpdate}
|
||||||
annotations={displayAnnotations}
|
annotations={displayAnnotations}
|
||||||
/>
|
>
|
||||||
|
{children}
|
||||||
|
</VideoPlayer>
|
||||||
)}
|
)}
|
||||||
</div>
|
</div>
|
||||||
)
|
)
|
||||||
|
|||||||
@@ -53,6 +53,7 @@ interface VideoPlayerProps {
|
|||||||
onPause?: () => void
|
onPause?: () => void
|
||||||
onTimeUpdate?: (time: number) => void
|
onTimeUpdate?: (time: number) => void
|
||||||
annotations?: Annotation[]
|
annotations?: Annotation[]
|
||||||
|
children?: React.ReactNode
|
||||||
}
|
}
|
||||||
|
|
||||||
type DisplayTranscode = VideoTranscode & { resolution: string }
|
type DisplayTranscode = VideoTranscode & { resolution: string }
|
||||||
@@ -310,6 +311,7 @@ const VideoPlayer: React.FC<VideoPlayerProps> = ({
|
|||||||
onPause,
|
onPause,
|
||||||
onTimeUpdate,
|
onTimeUpdate,
|
||||||
annotations,
|
annotations,
|
||||||
|
children,
|
||||||
}) => {
|
}) => {
|
||||||
const localPlayerRef = useRef<Player | null>(null)
|
const localPlayerRef = useRef<Player | null>(null)
|
||||||
const playerRef = passedPlayerRef || localPlayerRef
|
const playerRef = passedPlayerRef || localPlayerRef
|
||||||
@@ -797,49 +799,54 @@ const VideoPlayer: React.FC<VideoPlayerProps> = ({
|
|||||||
onMouseMove={handleMouseMove}
|
onMouseMove={handleMouseMove}
|
||||||
onMouseLeave={handleMouseLeave}
|
onMouseLeave={handleMouseLeave}
|
||||||
>
|
>
|
||||||
{/* Video Area */}
|
<div className="flex-1 flex min-h-0 relative">
|
||||||
<div
|
{/* Render Carousel/Sidebar here if not fullscreen */}
|
||||||
ref={containerRef}
|
{!state.isFullScreen && children}
|
||||||
className={cn(
|
|
||||||
'w-full bg-black cursor-pointer relative flex items-center justify-center overflow-hidden flex-1 min-h-0',
|
|
||||||
)}
|
|
||||||
onClick={togglePlay}
|
|
||||||
data-vjs-player
|
|
||||||
>
|
|
||||||
{/* Hidden VideoJS container */}
|
|
||||||
<div ref={videoContainerRef} className="absolute inset-0 z-[-1]" />
|
|
||||||
|
|
||||||
{/* Drawing Canvas (Visible) */}
|
{/* Video Area */}
|
||||||
{videoHtmlEl && containerSize.width > 0 && (
|
<div
|
||||||
<DrawingCanvas
|
ref={containerRef}
|
||||||
width={containerSize.width}
|
className={cn(
|
||||||
height={containerSize.height}
|
'flex-1 bg-black cursor-pointer relative flex items-center justify-center overflow-hidden min-h-0',
|
||||||
mediaDimensions={{
|
)}
|
||||||
width: vidW,
|
onClick={togglePlay}
|
||||||
height: vidH,
|
data-vjs-player
|
||||||
}}
|
>
|
||||||
videoElement={videoHtmlEl}
|
{/* Hidden VideoJS container */}
|
||||||
annotations={displayAnnotations}
|
<div ref={videoContainerRef} className="absolute inset-0 z-[-1]" />
|
||||||
scale={scale}
|
|
||||||
offset={{ x: panX, y: panY }}
|
|
||||||
className="absolute inset-0"
|
|
||||||
onClick={togglePlay}
|
|
||||||
// Drawing Props
|
|
||||||
isDrawing={isDrawing}
|
|
||||||
currentTool={currentTool}
|
|
||||||
currentColor={currentColor}
|
|
||||||
onAddAnnotation={addAnnotation}
|
|
||||||
/>
|
|
||||||
)}
|
|
||||||
|
|
||||||
{/* Big Play Button Overlay (when paused) */}
|
{/* Drawing Canvas (Visible) */}
|
||||||
{!state.isPlaying && !isDrawing && (
|
{videoHtmlEl && containerSize.width > 0 && (
|
||||||
<div className="absolute inset-0 flex items-center justify-center bg-black/20 pointer-events-none z-10">
|
<DrawingCanvas
|
||||||
<div className="w-20 h-20 bg-white/10 backdrop-blur-sm rounded-full flex items-center justify-center border-2 border-white/30 animate-pulse">
|
width={containerSize.width}
|
||||||
<Play className="w-10 h-10 text-white ml-1 fill-white" />
|
height={containerSize.height}
|
||||||
|
mediaDimensions={{
|
||||||
|
width: vidW,
|
||||||
|
height: vidH,
|
||||||
|
}}
|
||||||
|
videoElement={videoHtmlEl}
|
||||||
|
annotations={displayAnnotations}
|
||||||
|
scale={scale}
|
||||||
|
offset={{ x: panX, y: panY }}
|
||||||
|
className="absolute inset-0"
|
||||||
|
onClick={togglePlay}
|
||||||
|
// Drawing Props
|
||||||
|
isDrawing={isDrawing}
|
||||||
|
currentTool={currentTool}
|
||||||
|
currentColor={currentColor}
|
||||||
|
onAddAnnotation={addAnnotation}
|
||||||
|
/>
|
||||||
|
)}
|
||||||
|
|
||||||
|
{/* Big Play Button Overlay (when paused) */}
|
||||||
|
{!state.isPlaying && !isDrawing && (
|
||||||
|
<div className="absolute inset-0 flex items-center justify-center bg-black/20 pointer-events-none z-10">
|
||||||
|
<div className="w-20 h-20 bg-white/10 backdrop-blur-sm rounded-full flex items-center justify-center border-2 border-white/30 animate-pulse">
|
||||||
|
<Play className="w-10 h-10 text-white ml-1 fill-white" />
|
||||||
|
</div>
|
||||||
</div>
|
</div>
|
||||||
</div>
|
)}
|
||||||
)}
|
</div>
|
||||||
</div>
|
</div>
|
||||||
|
|
||||||
<ControlBar
|
<ControlBar
|
||||||
|
|||||||
@@ -310,15 +310,6 @@ function FileViewPage() {
|
|||||||
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">
|
||||||
{carouselState.show && (
|
|
||||||
<FileViewerLeftSidebar
|
|
||||||
projectId={projectId}
|
|
||||||
currentAssetId={activeFileId}
|
|
||||||
parentFolderId={parentFolderId}
|
|
||||||
initialFiles={carouselState.files}
|
|
||||||
initialNextCursor={carouselState.nextCursor}
|
|
||||||
/>
|
|
||||||
)}
|
|
||||||
<div className="flex-1 relative">
|
<div className="flex-1 relative">
|
||||||
{isFetching && (
|
{isFetching && (
|
||||||
<div className="absolute inset-0 z-10 flex items-center justify-center bg-background/50">
|
<div className="absolute inset-0 z-10 flex items-center justify-center bg-background/50">
|
||||||
@@ -331,7 +322,17 @@ function FileViewPage() {
|
|||||||
onPlay={handlePlay}
|
onPlay={handlePlay}
|
||||||
onTimeUpdate={setCurrentTime}
|
onTimeUpdate={setCurrentTime}
|
||||||
annotations={annotations}
|
annotations={annotations}
|
||||||
/>
|
>
|
||||||
|
{carouselState.show && (
|
||||||
|
<FileViewerLeftSidebar
|
||||||
|
projectId={projectId}
|
||||||
|
currentAssetId={activeFileId}
|
||||||
|
parentFolderId={parentFolderId}
|
||||||
|
initialFiles={carouselState.files}
|
||||||
|
initialNextCursor={carouselState.nextCursor}
|
||||||
|
/>
|
||||||
|
)}
|
||||||
|
</FileViewer>
|
||||||
</div>
|
</div>
|
||||||
<ResizeHandle
|
<ResizeHandle
|
||||||
onResize={(delta) => {
|
onResize={(delta) => {
|
||||||
|
|||||||
Reference in New Issue
Block a user