mirror of
https://github.com/shumaiOne/shumai.git
synced 2026-11-23 22:19:48 +00:00
feat(webui): add compare versions view for version stacks
Add a Compare Versions mode to the file detail page (authenticated and public share) that splits the viewer into two 50/50 panes showing two versions side by side. - Breadcrumb file menu gains a Compare Versions entry (version stacks with >=2 versions); the file segment is hidden in compare mode. - URL-driven state (compare/cmpLeft/cmpRight/cmpActive) on both file routes so the view is refresh/share-safe. - Per-side topbar with filename, version, version-switch dropdown, an active-side highlight, and an X exit button. - Shared control bar reflects the active pane; for same-type media it coordinates both panes (play/pause, seek, frame-step, zoom, pan sync), seekbar length matches the active side while the shorter side holds its last frame; only the active side plays audio; resolution/download apply to the active side; fullscreen covers the whole compare view. - Right sidebar (comments/fields) binds to the active side; comment selection seeks the active pane and annotations/comments can be created. - Reuses useFramePlayer + DrawingCanvas without modifying the existing single-file video player. - Unit tests for compare selection/clamp logic.
This commit is contained in:
@@ -90,6 +90,7 @@ Add any additional context, caveats, or follow-up work.
|
||||
- `bun run format`
|
||||
- `bun run typecheck`
|
||||
- `bun run test`
|
||||
- `bun run test:e2e`
|
||||
|
||||
- **Backend Testing Mandate**: Every backend feature, service method, workflow, and activity MUST be accompanied by comprehensive tests. Logic-heavy code without corresponding test coverage is considered incomplete.
|
||||
|
||||
|
||||
@@ -23,7 +23,7 @@ import { cn } from '@/ui/lib/utils'
|
||||
import { m } from '@/ui/paraglide/messages.js'
|
||||
import type { AncestorFolder } from '@shumai/dtos'
|
||||
import { Link, useNavigate } from '@tanstack/react-router'
|
||||
import { Check, ChevronDown, FileIcon, History, LayoutGrid, List } from 'lucide-react'
|
||||
import { Check, ChevronDown, Columns2, FileIcon, History, LayoutGrid, List } from 'lucide-react'
|
||||
|
||||
interface BreadcrumbNavProps {
|
||||
teamId: string
|
||||
@@ -62,6 +62,9 @@ interface BreadcrumbNavProps {
|
||||
previewUrl?: string | null
|
||||
creator?: { id: string; name: string | null } | null
|
||||
}>
|
||||
compareMode?: boolean
|
||||
canCompareVersions?: boolean
|
||||
onCompareVersions?: () => void
|
||||
}
|
||||
|
||||
export function BreadcrumbNav({
|
||||
@@ -83,6 +86,9 @@ export function BreadcrumbNav({
|
||||
shareId,
|
||||
downloadInfo,
|
||||
versions,
|
||||
compareMode = false,
|
||||
canCompareVersions = false,
|
||||
onCompareVersions,
|
||||
}: BreadcrumbNavProps) {
|
||||
const navigate = useNavigate()
|
||||
const { canEdit } = usePermissions(projectId)
|
||||
@@ -176,7 +182,7 @@ export function BreadcrumbNav({
|
||||
)}
|
||||
</div>
|
||||
))}
|
||||
{!isRootFolder && (
|
||||
{!isRootFolder && !compareMode && (
|
||||
<div className="flex items-center gap-1">
|
||||
<span className="text-muted-foreground">/</span>
|
||||
{currentAsset.type === 'folder' ? (
|
||||
@@ -263,6 +269,16 @@ export function BreadcrumbNav({
|
||||
</DropdownMenuItem>
|
||||
)}
|
||||
|
||||
{canCompareVersions && onCompareVersions && (
|
||||
<>
|
||||
<DropdownMenuSeparator />
|
||||
<DropdownMenuItem onClick={() => onCompareVersions()}>
|
||||
<Columns2 className="h-4 w-4" />
|
||||
<span>{m.compare_versions()}</span>
|
||||
</DropdownMenuItem>
|
||||
</>
|
||||
)}
|
||||
|
||||
{versions && versions.length > 0 && (
|
||||
<>
|
||||
<DropdownMenuSeparator />
|
||||
|
||||
@@ -0,0 +1,296 @@
|
||||
import {
|
||||
DropdownMenu,
|
||||
DropdownMenuContent,
|
||||
DropdownMenuItem,
|
||||
DropdownMenuLabel,
|
||||
DropdownMenuTrigger,
|
||||
} from '@/ui/components/ui/dropdown-menu'
|
||||
import { Slider } from '@/ui/components/ui/slider'
|
||||
import { cn } from '@/ui/lib/utils'
|
||||
import ProgressBar from '@/ui/components/viewers/progress-bar'
|
||||
import { formatTime, formatTimecode } from '@/ui/components/viewers/utils'
|
||||
import { useUiStore } from '@/ui/stores/ui'
|
||||
import type { MediaMetadata } from '@shumai/dtos'
|
||||
import {
|
||||
Download,
|
||||
Maximize,
|
||||
Minimize,
|
||||
Minus,
|
||||
Pause,
|
||||
Play,
|
||||
Plus,
|
||||
Repeat,
|
||||
Settings,
|
||||
Volume2,
|
||||
VolumeX,
|
||||
} from 'lucide-react'
|
||||
import type { PaneReportedState } from './types'
|
||||
|
||||
const PLAYBACK_RATES = [0.5, 1, 1.5, 2]
|
||||
|
||||
interface CompareControlBarProps {
|
||||
activeState: PaneReportedState | null
|
||||
previewUrl?: string
|
||||
metadata?: MediaMetadata
|
||||
startTimecode?: string | null
|
||||
isFullScreen: boolean
|
||||
onTogglePlay: () => void
|
||||
onToggleLoop: () => void
|
||||
onSeek: (frame: number) => void
|
||||
onVolumeChange: (volume: number) => void
|
||||
onToggleMute: () => void
|
||||
onChangePlaybackRate: (rate: number) => void
|
||||
onChangeResolution: (resolution: string) => void
|
||||
onZoomIn: () => void
|
||||
onZoomOut: () => void
|
||||
onFit: () => void
|
||||
onDownload: (key?: string) => void
|
||||
onToggleFullScreen: () => void
|
||||
}
|
||||
|
||||
export function CompareControlBar({
|
||||
activeState,
|
||||
previewUrl,
|
||||
metadata,
|
||||
startTimecode,
|
||||
isFullScreen,
|
||||
onTogglePlay,
|
||||
onToggleLoop,
|
||||
onSeek,
|
||||
onVolumeChange,
|
||||
onToggleMute,
|
||||
onChangePlaybackRate,
|
||||
onChangeResolution,
|
||||
onZoomIn,
|
||||
onZoomOut,
|
||||
onFit,
|
||||
onDownload,
|
||||
onToggleFullScreen,
|
||||
}: CompareControlBarProps) {
|
||||
const { videoTimeDisplayMode, setVideoTimeDisplayMode } = useUiStore()
|
||||
|
||||
const fullscreenButton = (
|
||||
<button
|
||||
onClick={onToggleFullScreen}
|
||||
className="text-foreground transition-colors hover:text-primary"
|
||||
title="Fullscreen"
|
||||
>
|
||||
{isFullScreen ? <Minimize className="h-5 w-5" /> : <Maximize className="h-5 w-5" />}
|
||||
</button>
|
||||
)
|
||||
|
||||
const zoomControls = (
|
||||
<div className="mr-auto flex items-center gap-1 rounded-md bg-muted/60 p-0.5">
|
||||
<button
|
||||
onClick={onZoomOut}
|
||||
className="rounded p-1.5 text-foreground transition-colors hover:bg-muted"
|
||||
title="Zoom Out"
|
||||
>
|
||||
<Minus size={16} />
|
||||
</button>
|
||||
<span className="w-12 text-center font-mono text-xs font-medium text-foreground select-none">
|
||||
{Math.round((activeState?.zoom ?? 1) * 100)}%
|
||||
</span>
|
||||
<button
|
||||
onClick={onZoomIn}
|
||||
className="rounded p-1.5 text-foreground transition-colors hover:bg-muted"
|
||||
title="Zoom In"
|
||||
>
|
||||
<Plus size={16} />
|
||||
</button>
|
||||
<button
|
||||
onClick={onFit}
|
||||
className="rounded px-2 py-1 text-xs font-medium text-foreground transition-colors hover:bg-muted"
|
||||
>
|
||||
Fit
|
||||
</button>
|
||||
</div>
|
||||
)
|
||||
|
||||
// Image (or unsupported) control bar
|
||||
if (!activeState || activeState.kind !== 'video' || !activeState.video) {
|
||||
return (
|
||||
<div className="relative z-10 flex items-center justify-end gap-2 border-t border-border bg-card px-4 py-3">
|
||||
{activeState?.kind === 'image' && zoomControls}
|
||||
{activeState?.kind === 'image' && (
|
||||
<button
|
||||
onClick={() => onDownload()}
|
||||
className="flex items-center gap-1.5 rounded bg-muted/60 px-3 py-1.5 text-xs font-medium text-foreground transition-colors hover:bg-muted"
|
||||
title="Download"
|
||||
>
|
||||
<Download size={14} />
|
||||
Download
|
||||
</button>
|
||||
)}
|
||||
{fullscreenButton}
|
||||
</div>
|
||||
)
|
||||
}
|
||||
|
||||
const video = activeState.video
|
||||
const displayTotalFrames = Math.max(0, video.totalFrames - 1)
|
||||
const displayString =
|
||||
videoTimeDisplayMode === 'frames'
|
||||
? `${video.currentFrame} / ${displayTotalFrames} fr`
|
||||
: videoTimeDisplayMode === 'standard'
|
||||
? `${formatTimecode(video.currentFrame, video.frameRate, 'standard')} / ${formatTime(video.totalFrames / video.frameRate)}`
|
||||
: `${formatTimecode(video.currentFrame, video.frameRate, videoTimeDisplayMode, startTimecode)} / ${formatTimecode(displayTotalFrames, video.frameRate, videoTimeDisplayMode, startTimecode)}`
|
||||
|
||||
const cycleTimeDisplay = () => {
|
||||
const modes: Array<'standard' | 'timecode' | 'frames'> = ['standard', 'timecode', 'frames']
|
||||
const idx = modes.indexOf(videoTimeDisplayMode as 'standard' | 'timecode' | 'frames')
|
||||
setVideoTimeDisplayMode(modes[(idx + 1) % modes.length])
|
||||
}
|
||||
|
||||
const previewResolutions = video.resolutions.filter((r) => !r.isRaw)
|
||||
|
||||
return (
|
||||
<div className="relative z-10 flex flex-col gap-2 border-t border-border bg-card px-4 py-2">
|
||||
<ProgressBar
|
||||
totalFrames={video.totalFrames}
|
||||
currentFrame={video.currentFrame}
|
||||
fps={video.frameRate}
|
||||
previewUrl={previewUrl}
|
||||
onSeek={onSeek}
|
||||
buffered={video.buffered}
|
||||
metadata={metadata}
|
||||
/>
|
||||
<div className="flex items-center gap-3">
|
||||
<button
|
||||
onClick={onTogglePlay}
|
||||
className="text-foreground transition-colors hover:text-primary"
|
||||
title={video.isPlaying ? 'Pause' : 'Play'}
|
||||
>
|
||||
{video.isPlaying ? (
|
||||
<Pause className="h-6 w-6 fill-current" />
|
||||
) : (
|
||||
<Play className="h-6 w-6 fill-current" />
|
||||
)}
|
||||
</button>
|
||||
|
||||
<button
|
||||
onClick={onToggleLoop}
|
||||
className={cn(
|
||||
'transition-colors hover:text-primary',
|
||||
video.isLooping ? 'text-primary' : 'text-foreground',
|
||||
)}
|
||||
title="Loop"
|
||||
>
|
||||
<Repeat className="h-5 w-5" />
|
||||
</button>
|
||||
|
||||
{/* Volume */}
|
||||
<div className="flex items-center gap-1.5">
|
||||
<button
|
||||
onClick={onToggleMute}
|
||||
className="text-foreground transition-colors hover:text-primary"
|
||||
title={video.isMuted ? 'Unmute' : 'Mute'}
|
||||
>
|
||||
{video.isMuted || video.volume === 0 ? (
|
||||
<VolumeX className="h-5 w-5" />
|
||||
) : (
|
||||
<Volume2 className="h-5 w-5" />
|
||||
)}
|
||||
</button>
|
||||
<Slider
|
||||
value={[video.isMuted ? 0 : video.volume]}
|
||||
max={1}
|
||||
step={0.05}
|
||||
onValueChange={(vals) => onVolumeChange(vals[0] ?? 0)}
|
||||
className="w-20"
|
||||
/>
|
||||
</div>
|
||||
|
||||
<button
|
||||
onClick={cycleTimeDisplay}
|
||||
className="font-mono text-xs font-medium text-foreground tabular-nums"
|
||||
title="Toggle time display"
|
||||
>
|
||||
{displayString}
|
||||
</button>
|
||||
|
||||
<div className="ml-auto flex items-center gap-3">
|
||||
{zoomControls}
|
||||
|
||||
{/* Playback rate */}
|
||||
<DropdownMenu>
|
||||
<DropdownMenuTrigger className="rounded border border-border px-2 py-0.5 text-sm font-semibold text-foreground transition-colors hover:bg-muted">
|
||||
{video.playbackRate}x
|
||||
</DropdownMenuTrigger>
|
||||
<DropdownMenuContent className="flex flex-col">
|
||||
{PLAYBACK_RATES.map((rate) => (
|
||||
<DropdownMenuItem
|
||||
key={rate}
|
||||
onClick={() => onChangePlaybackRate(rate)}
|
||||
className={cn(
|
||||
'px-2 py-1 text-xs',
|
||||
video.playbackRate === rate
|
||||
? 'bg-primary text-primary-foreground'
|
||||
: 'text-foreground',
|
||||
)}
|
||||
>
|
||||
{rate}x
|
||||
</DropdownMenuItem>
|
||||
))}
|
||||
</DropdownMenuContent>
|
||||
</DropdownMenu>
|
||||
|
||||
{/* Resolution */}
|
||||
{previewResolutions.length > 0 && (
|
||||
<DropdownMenu>
|
||||
<DropdownMenuTrigger className="flex items-center gap-1 rounded border border-border px-2 py-0.5 text-sm font-semibold text-foreground transition-colors hover:bg-muted">
|
||||
<Settings className="h-3.5 w-3.5" />
|
||||
<span>{video.currentResolution}</span>
|
||||
</DropdownMenuTrigger>
|
||||
<DropdownMenuContent>
|
||||
<DropdownMenuLabel>Quality</DropdownMenuLabel>
|
||||
{previewResolutions.map((res) => (
|
||||
<DropdownMenuItem
|
||||
key={res.resolution}
|
||||
onClick={() => onChangeResolution(res.resolution)}
|
||||
className={cn(
|
||||
'flex w-full items-center justify-between',
|
||||
video.currentResolution === res.resolution
|
||||
? 'font-medium text-primary'
|
||||
: 'text-foreground',
|
||||
)}
|
||||
>
|
||||
<span>{res.resolution}</span>
|
||||
<span className="pl-5 text-xs text-muted-foreground">
|
||||
{res.width}x{res.height}
|
||||
</span>
|
||||
</DropdownMenuItem>
|
||||
))}
|
||||
</DropdownMenuContent>
|
||||
</DropdownMenu>
|
||||
)}
|
||||
|
||||
{/* Download */}
|
||||
<DropdownMenu>
|
||||
<DropdownMenuTrigger
|
||||
className="text-foreground transition-colors hover:text-primary"
|
||||
title="Download"
|
||||
>
|
||||
<Download className="h-5 w-5" />
|
||||
</DropdownMenuTrigger>
|
||||
<DropdownMenuContent>
|
||||
<DropdownMenuLabel>Download</DropdownMenuLabel>
|
||||
{video.resolutions.map((res) => (
|
||||
<DropdownMenuItem
|
||||
key={res.resolution}
|
||||
onClick={() => onDownload(res.key)}
|
||||
className="flex w-full items-center justify-between px-3 py-2 text-sm text-foreground"
|
||||
>
|
||||
<span>{res.resolution}</span>
|
||||
<span className="text-xs text-muted-foreground">{res.isRaw ? 'RAW' : 'MP4'}</span>
|
||||
</DropdownMenuItem>
|
||||
))}
|
||||
</DropdownMenuContent>
|
||||
</DropdownMenu>
|
||||
|
||||
{fullscreenButton}
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
)
|
||||
}
|
||||
@@ -0,0 +1,218 @@
|
||||
import { client } from '@/ui/api/client'
|
||||
import DrawingCanvas from '@/ui/components/drawing-canvas'
|
||||
import { useScreenSize } from '@/ui/hooks/useScreenSize'
|
||||
import { getBestTranscode } from '@/ui/lib/media'
|
||||
import { useAnnotationStore } from '@/ui/stores/annotation-store'
|
||||
import type { Annotation } from '@/ui/types'
|
||||
import type { AssetInfo } from '@shumai/dtos'
|
||||
import { forwardRef, useCallback, useEffect, useImperativeHandle, useRef, useState } from 'react'
|
||||
import type { ComparePaneHandle, PaneReportedState } from './types'
|
||||
|
||||
interface CompareImagePaneProps {
|
||||
file: AssetInfo
|
||||
shareId?: string
|
||||
isActive: boolean
|
||||
annotations: Annotation[]
|
||||
onStateChange: (state: PaneReportedState) => void
|
||||
onUserPan?: (dx: number, dy: number) => void
|
||||
onActivate?: () => void
|
||||
}
|
||||
|
||||
const MIN_ZOOM = 0.01
|
||||
const MAX_ZOOM = 50
|
||||
|
||||
export const CompareImagePane = forwardRef<ComparePaneHandle, CompareImagePaneProps>(
|
||||
function CompareImagePane(
|
||||
{ file, shareId, isActive, annotations, onStateChange, onUserPan, onActivate },
|
||||
ref,
|
||||
) {
|
||||
const { width: screenWidth } = useScreenSize()
|
||||
const {
|
||||
isDrawing,
|
||||
currentTool,
|
||||
currentColor,
|
||||
addAnnotation,
|
||||
annotations: draftAnnotations,
|
||||
} = useAnnotationStore()
|
||||
|
||||
const [containerSize, setContainerSize] = useState({ width: 0, height: 0 })
|
||||
const [zoom, setZoom] = useState(1)
|
||||
const [pan, setPan] = useState({ x: 0, y: 0 })
|
||||
|
||||
const observerRef = useRef<ResizeObserver | null>(null)
|
||||
const zoomRef = useRef(zoom)
|
||||
zoomRef.current = zoom
|
||||
const panRef = useRef(pan)
|
||||
panRef.current = pan
|
||||
|
||||
const containerRef = useCallback((node: HTMLDivElement | null) => {
|
||||
if (observerRef.current) {
|
||||
observerRef.current.disconnect()
|
||||
observerRef.current = null
|
||||
}
|
||||
if (node !== null) {
|
||||
const observer = new ResizeObserver((entries) => {
|
||||
const entry = entries[0]
|
||||
if (entry) {
|
||||
setContainerSize({
|
||||
width: entry.contentRect.width,
|
||||
height: entry.contentRect.height,
|
||||
})
|
||||
}
|
||||
})
|
||||
observer.observe(node)
|
||||
observerRef.current = observer
|
||||
}
|
||||
}, [])
|
||||
|
||||
const imgW = file.media?.metadata?.originalWidth ?? 1920
|
||||
const imgH = file.media?.metadata?.originalHeight ?? 1080
|
||||
const conW = containerSize.width
|
||||
const conH = containerSize.height
|
||||
|
||||
let baseScale = 1
|
||||
if (conW > 0 && conH > 0) {
|
||||
baseScale = Math.min(conW / imgW, conH / imgH)
|
||||
}
|
||||
|
||||
// Fit on mount / container resize / file change
|
||||
useEffect(() => {
|
||||
if (conW > 0 && conH > 0) {
|
||||
setZoom(baseScale)
|
||||
setPan({
|
||||
x: (conW - imgW * baseScale) / 2,
|
||||
y: (conH - imgH * baseScale) / 2,
|
||||
})
|
||||
}
|
||||
}, [file.id, conW, conH, baseScale, imgW, imgH])
|
||||
|
||||
const applyZoom = useCallback(
|
||||
(factor: number) => {
|
||||
const cx = conW / 2
|
||||
const cy = conH / 2
|
||||
const cur = zoomRef.current
|
||||
const newZoom = cur * factor
|
||||
if (newZoom < MIN_ZOOM || newZoom > MAX_ZOOM) return
|
||||
const curPan = panRef.current
|
||||
setPan({
|
||||
x: cx - (cx - curPan.x) * (newZoom / cur),
|
||||
y: cy - (cy - curPan.y) * (newZoom / cur),
|
||||
})
|
||||
setZoom(newZoom)
|
||||
},
|
||||
[conW, conH],
|
||||
)
|
||||
|
||||
const fit = useCallback(() => {
|
||||
setZoom(baseScale)
|
||||
setPan({
|
||||
x: (conW - imgW * baseScale) / 2,
|
||||
y: (conH - imgH * baseScale) / 2,
|
||||
})
|
||||
}, [baseScale, conW, conH, imgW, imgH])
|
||||
|
||||
let bestUrl = file.media?.original?.downloadUrl
|
||||
const bestTranscode = getBestTranscode(file.media?.imageTranscodes, screenWidth)
|
||||
if (bestTranscode?.url) {
|
||||
bestUrl = bestTranscode.url
|
||||
}
|
||||
|
||||
const handleDownload = useCallback(async () => {
|
||||
const key = file.media?.original?.key
|
||||
if (!key || !file.id) return
|
||||
try {
|
||||
const res = shareId
|
||||
? await client.api.shares[':shareId'].files[':fileId']['download-url'].$post({
|
||||
param: { shareId, fileId: file.id },
|
||||
json: { key },
|
||||
})
|
||||
: await client.api.files['download-url'].$post({
|
||||
json: { key, assetId: file.id },
|
||||
})
|
||||
if (!res.ok) return
|
||||
const { url } = await res.json()
|
||||
const link = document.createElement('a')
|
||||
link.href = url
|
||||
link.download = ''
|
||||
document.body.appendChild(link)
|
||||
link.click()
|
||||
document.body.removeChild(link)
|
||||
} catch {
|
||||
// silently fail
|
||||
}
|
||||
}, [file.id, file.media?.original?.key, shareId])
|
||||
|
||||
useImperativeHandle(
|
||||
ref,
|
||||
(): ComparePaneHandle => ({
|
||||
getKind: () => 'image',
|
||||
play: () => {},
|
||||
pause: () => {},
|
||||
togglePlay: () => {},
|
||||
seekToFrame: () => {},
|
||||
seekToSecond: () => {},
|
||||
stepFrame: () => {},
|
||||
setMuted: () => {},
|
||||
setVolume: () => {},
|
||||
setPlaybackRate: () => {},
|
||||
toggleLoop: () => {},
|
||||
changeResolution: () => {},
|
||||
zoomBy: (factor) => applyZoom(factor),
|
||||
fit,
|
||||
panBy: (dx, dy) => setPan((p) => ({ x: p.x + dx, y: p.y + dy })),
|
||||
download: handleDownload,
|
||||
}),
|
||||
[applyZoom, fit, handleDownload],
|
||||
)
|
||||
|
||||
// Report state upward
|
||||
useEffect(() => {
|
||||
onStateChange({ kind: 'image', zoom })
|
||||
}, [zoom, onStateChange])
|
||||
|
||||
const displayAnnotations = [...annotations, ...(isActive ? draftAnnotations : [])]
|
||||
|
||||
const handlePan = useCallback(
|
||||
(newOffset: { x: number; y: number }) => {
|
||||
const prev = panRef.current
|
||||
const dx = newOffset.x - prev.x
|
||||
const dy = newOffset.y - prev.y
|
||||
setPan(newOffset)
|
||||
if (dx !== 0 || dy !== 0) onUserPan?.(dx, dy)
|
||||
},
|
||||
[onUserPan],
|
||||
)
|
||||
|
||||
if (!bestUrl) {
|
||||
return (
|
||||
<div className="flex flex-1 items-center justify-center bg-gray-100 dark:bg-gray-950">
|
||||
<p className="text-muted-foreground">Preview unavailable</p>
|
||||
</div>
|
||||
)
|
||||
}
|
||||
|
||||
return (
|
||||
<div
|
||||
ref={containerRef}
|
||||
className="relative flex-1 overflow-hidden bg-gray-100 dark:bg-gray-950"
|
||||
onMouseDown={onActivate}
|
||||
>
|
||||
<DrawingCanvas
|
||||
width={conW}
|
||||
height={conH}
|
||||
mediaDimensions={{ width: imgW, height: imgH }}
|
||||
imageUrl={bestUrl}
|
||||
annotations={displayAnnotations}
|
||||
scale={zoom}
|
||||
offset={pan}
|
||||
onPan={handlePan}
|
||||
className="absolute inset-0 z-0"
|
||||
isDrawing={isActive && isDrawing}
|
||||
currentTool={currentTool}
|
||||
currentColor={currentColor}
|
||||
onAddAnnotation={isActive ? addAnnotation : undefined}
|
||||
/>
|
||||
</div>
|
||||
)
|
||||
},
|
||||
)
|
||||
@@ -0,0 +1,139 @@
|
||||
import {
|
||||
DropdownMenu,
|
||||
DropdownMenuContent,
|
||||
DropdownMenuItem,
|
||||
DropdownMenuTrigger,
|
||||
} from '@/ui/components/ui/dropdown-menu'
|
||||
import { cn } from '@/ui/lib/utils'
|
||||
import { m } from '@/ui/paraglide/messages.js'
|
||||
import { Check, ChevronDown, FileIcon, X } from 'lucide-react'
|
||||
import type { CompareSide } from './types'
|
||||
|
||||
interface VersionItem {
|
||||
id: string
|
||||
version: number
|
||||
name?: string | null
|
||||
previewUrl?: string | null
|
||||
creator?: { id: string; name: string | null } | null
|
||||
}
|
||||
|
||||
interface ComparePaneTopbarProps {
|
||||
side: CompareSide
|
||||
fileName: string
|
||||
version?: number
|
||||
activeVersionId: string
|
||||
versions: VersionItem[]
|
||||
isActive: boolean
|
||||
onActivate: () => void
|
||||
onSwitchVersion: (versionId: string) => void
|
||||
onExit: () => void
|
||||
}
|
||||
|
||||
export function ComparePaneTopbar({
|
||||
side,
|
||||
fileName,
|
||||
version,
|
||||
activeVersionId,
|
||||
versions,
|
||||
isActive,
|
||||
onActivate,
|
||||
onSwitchVersion,
|
||||
onExit,
|
||||
}: ComparePaneTopbarProps) {
|
||||
const exitButton = (
|
||||
<button
|
||||
onClick={onExit}
|
||||
title={m.exit_compare()}
|
||||
className="flex-shrink-0 rounded p-1 text-muted-foreground transition-colors hover:bg-accent hover:text-foreground"
|
||||
>
|
||||
<X className="h-4 w-4" />
|
||||
</button>
|
||||
)
|
||||
|
||||
const label = (
|
||||
<button
|
||||
onClick={onActivate}
|
||||
className="flex min-w-0 items-center gap-1 rounded px-2 py-1 text-sm font-medium text-foreground transition-colors hover:bg-accent hover:text-accent-foreground"
|
||||
>
|
||||
<span className="truncate">{fileName}</span>
|
||||
{version !== undefined && (
|
||||
<span className="flex-shrink-0 rounded border border-border px-1 py-0 text-xs">
|
||||
v{version}
|
||||
</span>
|
||||
)}
|
||||
</button>
|
||||
)
|
||||
|
||||
const versionDropdown = (
|
||||
<DropdownMenu>
|
||||
<DropdownMenuTrigger
|
||||
onClick={onActivate}
|
||||
title={m.switch_version()}
|
||||
className="flex-shrink-0 rounded p-1 text-muted-foreground transition-colors hover:bg-accent hover:text-foreground"
|
||||
>
|
||||
<ChevronDown className="h-4 w-4" />
|
||||
</DropdownMenuTrigger>
|
||||
<DropdownMenuContent align={side === 'left' ? 'start' : 'end'} className="w-80 p-1">
|
||||
<div className="flex max-h-96 flex-col gap-1 overflow-y-auto">
|
||||
{versions.map((v) => {
|
||||
const isCurrent = v.id === activeVersionId
|
||||
return (
|
||||
<DropdownMenuItem
|
||||
key={v.id}
|
||||
onClick={() => onSwitchVersion(v.id)}
|
||||
className="flex cursor-pointer items-center gap-3 rounded-md px-3 py-2"
|
||||
>
|
||||
<div className="flex min-w-[2rem] flex-shrink-0 items-center justify-center rounded-full bg-muted px-2 py-0.5 text-xs font-semibold text-muted-foreground select-none">
|
||||
v{v.version}
|
||||
</div>
|
||||
<div className="flex h-10 w-16 flex-shrink-0 items-center justify-center overflow-hidden rounded-md border border-border bg-muted">
|
||||
{v.previewUrl ? (
|
||||
<img
|
||||
src={v.previewUrl}
|
||||
alt={v.name || undefined}
|
||||
className="h-full w-full object-cover"
|
||||
/>
|
||||
) : (
|
||||
<FileIcon className="h-4 w-4 text-muted-foreground" />
|
||||
)}
|
||||
</div>
|
||||
<div className="flex min-w-0 flex-1 flex-col text-left">
|
||||
<span className="truncate text-sm font-semibold text-foreground">{v.name}</span>
|
||||
<span className="truncate text-xs text-muted-foreground">
|
||||
{v.creator?.name || 'Unknown'}
|
||||
</span>
|
||||
</div>
|
||||
{isCurrent && <Check className="ml-auto h-4 w-4 flex-shrink-0 text-primary" />}
|
||||
</DropdownMenuItem>
|
||||
)
|
||||
})}
|
||||
</div>
|
||||
</DropdownMenuContent>
|
||||
</DropdownMenu>
|
||||
)
|
||||
|
||||
return (
|
||||
<div
|
||||
onMouseDown={onActivate}
|
||||
className={cn(
|
||||
'flex h-10 flex-shrink-0 items-center gap-1 border-b bg-card px-2',
|
||||
isActive ? 'border-b-2 border-primary' : 'border-border',
|
||||
)}
|
||||
>
|
||||
{side === 'left' ? (
|
||||
<>
|
||||
{exitButton}
|
||||
{label}
|
||||
{versionDropdown}
|
||||
</>
|
||||
) : (
|
||||
<>
|
||||
{label}
|
||||
{versionDropdown}
|
||||
<div className="ml-auto" />
|
||||
{exitButton}
|
||||
</>
|
||||
)}
|
||||
</div>
|
||||
)
|
||||
}
|
||||
@@ -0,0 +1,82 @@
|
||||
import { describe, it, expect } from 'vitest'
|
||||
import { kindOf, pickDefaultCompareVersions, clampFrame, isSameType } from './compare-utils'
|
||||
|
||||
describe('compare-utils', () => {
|
||||
describe('kindOf', () => {
|
||||
it('classifies image media types', () => {
|
||||
expect(kindOf('image/png')).toBe('image')
|
||||
expect(kindOf('image/webp')).toBe('image')
|
||||
})
|
||||
|
||||
it('classifies video media types', () => {
|
||||
expect(kindOf('video/mp4')).toBe('video')
|
||||
expect(kindOf('video/quicktime')).toBe('video')
|
||||
})
|
||||
|
||||
it('returns unsupported for missing or unknown types', () => {
|
||||
expect(kindOf(null)).toBe('unsupported')
|
||||
expect(kindOf(undefined)).toBe('unsupported')
|
||||
expect(kindOf('application/pdf')).toBe('unsupported')
|
||||
})
|
||||
})
|
||||
|
||||
describe('pickDefaultCompareVersions', () => {
|
||||
it('picks latest and latest-1 regardless of input order', () => {
|
||||
const versions = [
|
||||
{ id: 'a', version: 1 },
|
||||
{ id: 'c', version: 3 },
|
||||
{ id: 'b', version: 2 },
|
||||
]
|
||||
const pair = pickDefaultCompareVersions(versions)
|
||||
expect(pair).not.toBeNull()
|
||||
expect(pair!.left.id).toBe('c') // v3 (latest)
|
||||
expect(pair!.right.id).toBe('b') // v2 (latest - 1)
|
||||
})
|
||||
|
||||
it('returns null when fewer than two versions', () => {
|
||||
expect(pickDefaultCompareVersions([{ id: 'a', version: 1 }])).toBeNull()
|
||||
expect(pickDefaultCompareVersions([])).toBeNull()
|
||||
expect(pickDefaultCompareVersions(undefined)).toBeNull()
|
||||
expect(pickDefaultCompareVersions(null)).toBeNull()
|
||||
})
|
||||
|
||||
it('does not mutate the input array', () => {
|
||||
const versions = [
|
||||
{ id: 'a', version: 1 },
|
||||
{ id: 'b', version: 2 },
|
||||
]
|
||||
pickDefaultCompareVersions(versions)
|
||||
expect(versions.map((v) => v.id)).toEqual(['a', 'b'])
|
||||
})
|
||||
})
|
||||
|
||||
describe('clampFrame', () => {
|
||||
it('clamps to the last frame when beyond total (shorter side holds last frame)', () => {
|
||||
expect(clampFrame(500, 100)).toBe(99)
|
||||
})
|
||||
|
||||
it('clamps negative frames to zero', () => {
|
||||
expect(clampFrame(-5, 100)).toBe(0)
|
||||
})
|
||||
|
||||
it('passes through in-range frames', () => {
|
||||
expect(clampFrame(42, 100)).toBe(42)
|
||||
})
|
||||
|
||||
it('handles zero-length safely', () => {
|
||||
expect(clampFrame(10, 0)).toBe(0)
|
||||
})
|
||||
})
|
||||
|
||||
describe('isSameType', () => {
|
||||
it('true only for matching, supported kinds', () => {
|
||||
expect(isSameType('video', 'video')).toBe(true)
|
||||
expect(isSameType('image', 'image')).toBe(true)
|
||||
})
|
||||
|
||||
it('false for mismatched or unsupported kinds', () => {
|
||||
expect(isSameType('video', 'image')).toBe(false)
|
||||
expect(isSameType('unsupported', 'unsupported')).toBe(false)
|
||||
})
|
||||
})
|
||||
})
|
||||
@@ -0,0 +1,37 @@
|
||||
import type { PaneKind } from './types'
|
||||
|
||||
/** Classify an asset's media type into a compare pane kind. */
|
||||
export function kindOf(mediaType: string | null | undefined): PaneKind {
|
||||
if (!mediaType) return 'unsupported'
|
||||
if (mediaType.startsWith('image/')) return 'image'
|
||||
if (mediaType.startsWith('video/')) return 'video'
|
||||
return 'unsupported'
|
||||
}
|
||||
|
||||
interface VersionLike {
|
||||
id: string
|
||||
version: number
|
||||
}
|
||||
|
||||
/**
|
||||
* Given a version stack's versions, pick the default compare pair:
|
||||
* left = latest (highest version number), right = latest - 1.
|
||||
* Returns null if fewer than two versions exist.
|
||||
*/
|
||||
export function pickDefaultCompareVersions(
|
||||
versions: ReadonlyArray<VersionLike> | undefined | null,
|
||||
): { left: VersionLike; right: VersionLike } | null {
|
||||
if (!versions || versions.length < 2) return null
|
||||
const sorted = [...versions].sort((a, b) => b.version - a.version)
|
||||
return { left: sorted[0], right: sorted[1] }
|
||||
}
|
||||
|
||||
/** Clamp a frame index into the valid range [0, totalFrames - 1]. */
|
||||
export function clampFrame(frame: number, totalFrames: number): number {
|
||||
return Math.max(0, Math.min(frame, Math.max(0, totalFrames - 1)))
|
||||
}
|
||||
|
||||
/** True when both panes hold the same (non-unsupported) media kind. */
|
||||
export function isSameType(left: PaneKind, right: PaneKind): boolean {
|
||||
return left === right && left !== 'unsupported'
|
||||
}
|
||||
@@ -0,0 +1,461 @@
|
||||
import { client } from '@/ui/api/client'
|
||||
import DrawingCanvas from '@/ui/components/drawing-canvas'
|
||||
import { cn } from '@/ui/lib/utils'
|
||||
import { useAnnotationStore } from '@/ui/stores/annotation-store'
|
||||
import type { Annotation } from '@/ui/types'
|
||||
import type { AssetInfo } from '@shumai/dtos'
|
||||
import { Play } from 'lucide-react'
|
||||
import { forwardRef, useCallback, useEffect, useImperativeHandle, useRef, useState } from 'react'
|
||||
import videojs from 'video.js'
|
||||
import type Player from 'video.js/dist/types/player'
|
||||
import { useFramePlayer } from '@/ui/components/viewers/use-frame-player'
|
||||
import { clampFrame as clampFrameUtil } from './compare-utils'
|
||||
import type { ComparePaneHandle, DisplayTranscode, PaneReportedState } from './types'
|
||||
|
||||
interface CompareVideoPaneProps {
|
||||
file: AssetInfo
|
||||
shareId?: string
|
||||
isActive: boolean
|
||||
/** Whether this pane's audio should be muted (only the active side plays audio). */
|
||||
muted: boolean
|
||||
volume: number
|
||||
annotations: Annotation[]
|
||||
onStateChange: (state: PaneReportedState) => void
|
||||
onActivate?: () => void
|
||||
onRequestTogglePlay?: () => void
|
||||
/** Called with the current playhead time in seconds (used only for the active pane). */
|
||||
onTimeUpdate?: (second: number) => void
|
||||
onPlay?: () => void
|
||||
}
|
||||
|
||||
function computeResolutions(file: AssetInfo): DisplayTranscode[] {
|
||||
const original: DisplayTranscode | null = file.media?.original?.downloadUrl
|
||||
? {
|
||||
id: 'original',
|
||||
url: file.media.original.downloadUrl,
|
||||
key: file.media.original.key ?? '',
|
||||
width: file.media?.metadata?.originalWidth ?? 0,
|
||||
height: file.media?.metadata?.originalHeight ?? 0,
|
||||
size: 0,
|
||||
isRaw: true,
|
||||
resolution: 'Original',
|
||||
}
|
||||
: null
|
||||
|
||||
const transcodes: DisplayTranscode[] = (file.media?.videoTranscodes ?? []).map((t) => {
|
||||
const longSide = Math.max(t.width, t.height)
|
||||
let resolution = `${t.height}p`
|
||||
if (longSide >= 3840) resolution = '2160p'
|
||||
else if (longSide >= 1920) resolution = '1080p'
|
||||
else if (longSide >= 1280) resolution = '720p'
|
||||
else if (longSide >= 960) resolution = '540p'
|
||||
else if (longSide >= 640) resolution = '360p'
|
||||
else if (longSide >= 320) resolution = '180p'
|
||||
return { ...t, resolution: t.isRaw ? 'Original' : resolution }
|
||||
})
|
||||
|
||||
const hasOriginalTranscode = transcodes.some((t) => t.isRaw)
|
||||
if (!hasOriginalTranscode && original) {
|
||||
return [...transcodes, original]
|
||||
}
|
||||
return transcodes
|
||||
}
|
||||
|
||||
export const CompareVideoPane = forwardRef<ComparePaneHandle, CompareVideoPaneProps>(
|
||||
function CompareVideoPane(
|
||||
{
|
||||
file,
|
||||
shareId,
|
||||
isActive,
|
||||
muted,
|
||||
volume,
|
||||
annotations,
|
||||
onStateChange,
|
||||
onActivate,
|
||||
onRequestTogglePlay,
|
||||
onTimeUpdate,
|
||||
onPlay,
|
||||
},
|
||||
ref,
|
||||
) {
|
||||
const playerRef = useRef<Player | null>(null)
|
||||
const videoContainerRef = useRef<HTMLDivElement>(null)
|
||||
const containerRef = useRef<HTMLDivElement>(null)
|
||||
const videoRef = useRef<HTMLVideoElement | null>(null)
|
||||
const [videoHtmlEl, setVideoHtmlEl] = useState<HTMLVideoElement | undefined>(undefined)
|
||||
|
||||
const {
|
||||
isDrawing,
|
||||
currentTool,
|
||||
currentColor,
|
||||
addAnnotation,
|
||||
annotations: draftAnnotations,
|
||||
} = useAnnotationStore()
|
||||
|
||||
const [containerSize, setContainerSize] = useState({ width: 0, height: 0 })
|
||||
const [zoom, setZoom] = useState(1)
|
||||
const [hasManuallyZoomed, setHasManuallyZoomed] = useState(false)
|
||||
const [pan, setPan] = useState<{ x: number; y: number } | null>(null)
|
||||
|
||||
const [isPlaying, setIsPlaying] = useState(false)
|
||||
const [isLooping, setIsLooping] = useState(false)
|
||||
const [playbackRate, setPlaybackRate] = useState(1)
|
||||
const [buffered, setBuffered] = useState(0)
|
||||
const [playerVolume, setPlayerVolume] = useState(volume)
|
||||
const [playerMuted, setPlayerMuted] = useState(muted)
|
||||
const [isPlayerReady, setIsPlayerReady] = useState(false)
|
||||
|
||||
const metadata = file.media?.metadata
|
||||
const frameRate = metadata?.frameRate || 30
|
||||
const dbTotalFrames = metadata?.totalFrames || 0
|
||||
const containerDuration = metadata?.duration || 0
|
||||
const videoDuration = dbTotalFrames / frameRate
|
||||
const frameDuration = 1 / frameRate
|
||||
const totalFrames =
|
||||
containerDuration - videoDuration > 0.5 * frameDuration
|
||||
? Math.round(containerDuration * frameRate)
|
||||
: dbTotalFrames
|
||||
|
||||
const resolutions = computeResolutions(file)
|
||||
const previewResolutions = resolutions.filter((r) => !r.isRaw)
|
||||
const initialRes = previewResolutions[0] ?? resolutions[0]
|
||||
const [currentResolution, setCurrentResolution] = useState(initialRes?.resolution ?? 'Original')
|
||||
const currentSrcRef = useRef(initialRes?.url)
|
||||
|
||||
const { currentFrame, seekToFrame } = useFramePlayer(videoRef, frameRate, totalFrames)
|
||||
|
||||
const zoomRef = useRef(zoom)
|
||||
zoomRef.current = zoom
|
||||
const currentFrameRef = useRef(currentFrame)
|
||||
currentFrameRef.current = currentFrame
|
||||
|
||||
// Resize observer
|
||||
useEffect(() => {
|
||||
if (!containerRef.current) return
|
||||
const observer = new ResizeObserver((entries) => {
|
||||
const entry = entries[0]
|
||||
if (entry) {
|
||||
setContainerSize({ width: entry.contentRect.width, height: entry.contentRect.height })
|
||||
}
|
||||
})
|
||||
observer.observe(containerRef.current)
|
||||
return () => observer.disconnect()
|
||||
}, [])
|
||||
|
||||
const vidW = metadata?.originalWidth ?? 1920
|
||||
const vidH = metadata?.originalHeight ?? 1080
|
||||
|
||||
// Auto-fit zoom
|
||||
useEffect(() => {
|
||||
if (containerSize.width > 0 && containerSize.height > 0 && !hasManuallyZoomed) {
|
||||
const scale = Math.min(containerSize.width / vidW, containerSize.height / vidH)
|
||||
setZoom(scale)
|
||||
}
|
||||
}, [containerSize.width, containerSize.height, vidW, vidH, hasManuallyZoomed])
|
||||
|
||||
// Initialize video.js
|
||||
useEffect(() => {
|
||||
if (!videoContainerRef.current) return
|
||||
const videoElement = document.createElement('video-js')
|
||||
videoElement.classList.add('vjs-big-play-centered', '!h-full', '!w-full')
|
||||
videoElement.style.opacity = '0'
|
||||
videoElement.style.pointerEvents = 'none'
|
||||
videoContainerRef.current.appendChild(videoElement)
|
||||
|
||||
const player = (playerRef.current = videojs(videoElement, {
|
||||
controls: false,
|
||||
autoplay: false,
|
||||
preload: 'auto',
|
||||
playsinline: true,
|
||||
sources: [{ src: currentSrcRef.current ?? '', type: 'video/mp4' }],
|
||||
}))
|
||||
|
||||
const htmlVid = videoElement.querySelector('video')
|
||||
if (htmlVid) {
|
||||
setVideoHtmlEl(htmlVid)
|
||||
videoRef.current = htmlVid
|
||||
} else {
|
||||
player.ready(() => {
|
||||
const techEl = player.tech({ iWillNotUseThisInPlugins: true })?.el() as HTMLVideoElement
|
||||
if (techEl) {
|
||||
setVideoHtmlEl(techEl)
|
||||
videoRef.current = techEl
|
||||
}
|
||||
})
|
||||
}
|
||||
|
||||
player.on('play', () => {
|
||||
setIsPlaying(true)
|
||||
onPlay?.()
|
||||
})
|
||||
player.on('pause', () => setIsPlaying(false))
|
||||
player.on('ended', () => setIsPlaying(false))
|
||||
player.on('loadedmetadata', () => setIsPlayerReady(true))
|
||||
player.on('loadstart', () => setIsPlayerReady(false))
|
||||
player.on('timeupdate', () => {
|
||||
const playerDuration = player.duration() || containerDuration || 0
|
||||
const bufferedEnd = player.bufferedEnd()
|
||||
if (playerDuration > 0) setBuffered((bufferedEnd / playerDuration) * 100)
|
||||
})
|
||||
player.on('volumechange', () => {
|
||||
setPlayerVolume(player.volume() || 0)
|
||||
setPlayerMuted(player.muted() || false)
|
||||
})
|
||||
player.on('ratechange', () => setPlaybackRate(player.playbackRate() || 1))
|
||||
|
||||
return () => {
|
||||
if (player && !player.isDisposed()) {
|
||||
player.dispose()
|
||||
playerRef.current = null
|
||||
videoRef.current = null
|
||||
}
|
||||
}
|
||||
}, [file.id])
|
||||
|
||||
// Apply muted / volume (audio routing: only active side unmuted)
|
||||
useEffect(() => {
|
||||
const player = playerRef.current
|
||||
if (!player || !isPlayerReady) return
|
||||
player.muted(muted)
|
||||
player.volume(volume)
|
||||
}, [muted, volume, isPlayerReady])
|
||||
|
||||
// Report state upward
|
||||
useEffect(() => {
|
||||
const state: PaneReportedState = {
|
||||
kind: 'video',
|
||||
zoom,
|
||||
video: {
|
||||
frameRate,
|
||||
totalFrames,
|
||||
currentFrame,
|
||||
isPlaying,
|
||||
volume: playerVolume,
|
||||
isMuted: playerMuted,
|
||||
playbackRate,
|
||||
isLooping,
|
||||
currentResolution,
|
||||
resolutions,
|
||||
buffered,
|
||||
},
|
||||
}
|
||||
onStateChange(state)
|
||||
}, [
|
||||
zoom,
|
||||
frameRate,
|
||||
totalFrames,
|
||||
currentFrame,
|
||||
isPlaying,
|
||||
playerVolume,
|
||||
playerMuted,
|
||||
playbackRate,
|
||||
isLooping,
|
||||
currentResolution,
|
||||
buffered,
|
||||
])
|
||||
|
||||
// Propagate active playhead time
|
||||
useEffect(() => {
|
||||
if (isActive) onTimeUpdate?.(currentFrame / frameRate)
|
||||
}, [currentFrame, frameRate, isActive, onTimeUpdate])
|
||||
|
||||
const applyZoom = useCallback((factor: number) => {
|
||||
const cur = zoomRef.current
|
||||
const newZoom = cur * factor
|
||||
if (newZoom < 0.01 || newZoom > 50) return
|
||||
setZoom(newZoom)
|
||||
setHasManuallyZoomed(true)
|
||||
}, [])
|
||||
|
||||
const fit = useCallback(() => {
|
||||
setHasManuallyZoomed(false)
|
||||
setPan(null)
|
||||
}, [])
|
||||
|
||||
const clampFrame = useCallback(
|
||||
(frame: number) => clampFrameUtil(frame, totalFrames),
|
||||
[totalFrames],
|
||||
)
|
||||
|
||||
const handleDownload = useCallback(
|
||||
async (key?: string) => {
|
||||
const dlKey = key ?? file.media?.original?.key
|
||||
if (!dlKey || !file.id) return
|
||||
try {
|
||||
const res = shareId
|
||||
? await client.api.shares[':shareId'].files[':fileId']['download-url'].$post({
|
||||
param: { shareId, fileId: file.id },
|
||||
json: { key: dlKey },
|
||||
})
|
||||
: await client.api.files['download-url'].$post({
|
||||
json: { key: dlKey, assetId: file.id },
|
||||
})
|
||||
if (!res.ok) return
|
||||
const { url } = await res.json()
|
||||
const link = document.createElement('a')
|
||||
link.href = url
|
||||
link.download = ''
|
||||
document.body.appendChild(link)
|
||||
link.click()
|
||||
document.body.removeChild(link)
|
||||
} catch {
|
||||
// silently fail
|
||||
}
|
||||
},
|
||||
[file.id, file.media?.original?.key, shareId],
|
||||
)
|
||||
|
||||
const changeResolution = useCallback(
|
||||
(resolution: string) => {
|
||||
const player = playerRef.current
|
||||
if (!player) return
|
||||
const target = resolutions.find((r) => r.resolution === resolution)
|
||||
if (!target) return
|
||||
const wasPlaying = !player.paused()
|
||||
const currentT = player.currentTime()
|
||||
setCurrentResolution(resolution)
|
||||
currentSrcRef.current = target.url
|
||||
player.src({ type: 'video/mp4', src: target.url })
|
||||
player.one('loadedmetadata', () => {
|
||||
player.currentTime(currentT)
|
||||
if (wasPlaying) {
|
||||
const p = player.play()
|
||||
if (p !== undefined) p.catch(() => {})
|
||||
}
|
||||
})
|
||||
},
|
||||
[resolutions],
|
||||
)
|
||||
|
||||
useImperativeHandle(
|
||||
ref,
|
||||
(): ComparePaneHandle => ({
|
||||
getKind: () => 'video',
|
||||
play: () => {
|
||||
const p = playerRef.current?.play()
|
||||
if (p !== undefined) p.catch(() => {})
|
||||
},
|
||||
pause: () => playerRef.current?.pause(),
|
||||
togglePlay: () => {
|
||||
const player = playerRef.current
|
||||
if (!player) return
|
||||
if (player.paused() || player.ended()) {
|
||||
const p = player.play()
|
||||
if (p !== undefined) p.catch(() => {})
|
||||
} else {
|
||||
player.pause()
|
||||
}
|
||||
},
|
||||
seekToFrame: (frame) => seekToFrame(clampFrame(frame)),
|
||||
seekToSecond: (second) => {
|
||||
const frame = Math.floor(second * frameRate + 0.45)
|
||||
seekToFrame(clampFrame(frame))
|
||||
},
|
||||
stepFrame: (delta) => seekToFrame(clampFrame(currentFrameRef.current + delta)),
|
||||
setMuted: (m) => playerRef.current?.muted(m),
|
||||
setVolume: (v) => {
|
||||
const player = playerRef.current
|
||||
if (!player) return
|
||||
player.volume(v)
|
||||
if (v > 0 && player.muted()) player.muted(false)
|
||||
else if (v === 0 && !player.muted()) player.muted(true)
|
||||
},
|
||||
setPlaybackRate: (rate) => playerRef.current?.playbackRate(rate),
|
||||
toggleLoop: () => {
|
||||
const player = playerRef.current
|
||||
if (!player) return
|
||||
const next = !player.loop()
|
||||
player.loop(next)
|
||||
setIsLooping(next)
|
||||
},
|
||||
changeResolution,
|
||||
zoomBy: applyZoom,
|
||||
fit,
|
||||
panBy: (dx, dy) =>
|
||||
setPan((p) => {
|
||||
const scale = zoomRef.current
|
||||
const base = p ?? {
|
||||
x: (containerSize.width - vidW * scale) / 2,
|
||||
y: (containerSize.height - vidH * scale) / 2,
|
||||
}
|
||||
return { x: base.x + dx, y: base.y + dy }
|
||||
}),
|
||||
download: (key?: string) => handleDownload(key),
|
||||
}),
|
||||
[
|
||||
seekToFrame,
|
||||
clampFrame,
|
||||
frameRate,
|
||||
applyZoom,
|
||||
fit,
|
||||
changeResolution,
|
||||
handleDownload,
|
||||
containerSize.width,
|
||||
containerSize.height,
|
||||
vidW,
|
||||
vidH,
|
||||
],
|
||||
)
|
||||
|
||||
const displayAnnotations = [...annotations, ...(isActive ? draftAnnotations : [])]
|
||||
|
||||
const scale = zoom
|
||||
const defaultPanX = (containerSize.width - vidW * scale) / 2
|
||||
const defaultPanY = (containerSize.height - vidH * scale) / 2
|
||||
const panX = pan?.x ?? defaultPanX
|
||||
const panY = pan?.y ?? defaultPanY
|
||||
|
||||
const handleAreaClick = useCallback(() => {
|
||||
if (useAnnotationStore.getState().isDrawing) return
|
||||
onActivate?.()
|
||||
onRequestTogglePlay?.()
|
||||
}, [onActivate, onRequestTogglePlay])
|
||||
|
||||
if (!file.media?.original?.downloadUrl || !metadata) {
|
||||
return (
|
||||
<div className="flex h-full w-full items-center justify-center bg-black">
|
||||
<p className="text-muted-foreground">Media is not available.</p>
|
||||
</div>
|
||||
)
|
||||
}
|
||||
|
||||
return (
|
||||
<div
|
||||
ref={containerRef}
|
||||
className={cn(
|
||||
'relative flex flex-1 cursor-pointer items-center justify-center overflow-hidden bg-black',
|
||||
)}
|
||||
onClick={handleAreaClick}
|
||||
data-testid="compare-video-area"
|
||||
>
|
||||
<div ref={videoContainerRef} className="absolute inset-0 z-[-1]" />
|
||||
|
||||
{videoHtmlEl && containerSize.width > 0 && (
|
||||
<DrawingCanvas
|
||||
width={containerSize.width}
|
||||
height={containerSize.height}
|
||||
mediaDimensions={{ width: vidW, height: vidH }}
|
||||
videoElement={videoHtmlEl}
|
||||
annotations={displayAnnotations}
|
||||
scale={scale}
|
||||
offset={{ x: panX, y: panY }}
|
||||
className="absolute inset-0"
|
||||
onClick={handleAreaClick}
|
||||
isDrawing={isActive && isDrawing}
|
||||
currentTool={currentTool}
|
||||
currentColor={currentColor}
|
||||
onAddAnnotation={isActive ? addAnnotation : undefined}
|
||||
/>
|
||||
)}
|
||||
|
||||
{!isPlaying && !isDrawing && (
|
||||
<div className="pointer-events-none absolute inset-0 z-10 flex items-center justify-center bg-black/20">
|
||||
<div className="flex h-16 w-16 items-center justify-center rounded-full border-2 border-white/30 bg-white/10 backdrop-blur-sm">
|
||||
<Play className="ml-1 h-8 w-8 fill-white text-white" />
|
||||
</div>
|
||||
</div>
|
||||
)}
|
||||
</div>
|
||||
)
|
||||
},
|
||||
)
|
||||
@@ -0,0 +1,356 @@
|
||||
import { client } from '@/ui/api/client'
|
||||
import type { Annotation } from '@/ui/types'
|
||||
import type { AssetInfo } from '@shumai/dtos'
|
||||
import { useQuery } from '@tanstack/react-query'
|
||||
import { Loader2 } from 'lucide-react'
|
||||
import { useCallback, useEffect, useMemo, useRef, useState } from 'react'
|
||||
import { CompareControlBar } from './compare-control-bar'
|
||||
import { CompareImagePane } from './compare-image-pane'
|
||||
import { ComparePaneTopbar } from './compare-pane-topbar'
|
||||
import { CompareVideoPane } from './compare-video-pane'
|
||||
import { kindOf, isSameType } from './compare-utils'
|
||||
import type { ComparePaneHandle, CompareSide, PaneKind, PaneReportedState } from './types'
|
||||
|
||||
interface VersionItem {
|
||||
id: string
|
||||
version: number
|
||||
name?: string | null
|
||||
previewUrl?: string | null
|
||||
creator?: { id: string; name: string | null } | null
|
||||
}
|
||||
|
||||
interface CompareViewerProps {
|
||||
isPublic?: boolean
|
||||
shareId?: string
|
||||
versions: VersionItem[]
|
||||
leftId: string
|
||||
rightId: string
|
||||
activeSide: CompareSide
|
||||
annotations: Annotation[]
|
||||
/** Bumped nonce requests the active pane seek to `second` (comment navigation). */
|
||||
seekRequest?: { second: number; nonce: number }
|
||||
onActiveSideChange: (side: CompareSide) => void
|
||||
onSwitchVersion: (side: CompareSide, versionId: string) => void
|
||||
onExit: () => void
|
||||
onActiveAssetChange: (asset: AssetInfo | null) => void
|
||||
onPlay?: () => void
|
||||
onTimeUpdate?: (second: number) => void
|
||||
}
|
||||
|
||||
function useCompareAsset(id: string, isPublic: boolean, shareId?: string) {
|
||||
return useQuery({
|
||||
queryKey: isPublic
|
||||
? ['public-share-file', shareId, id, localStorage.getItem(`share_pwd_${shareId}`) || '']
|
||||
: ['files', id],
|
||||
queryFn: async () => {
|
||||
if (isPublic) {
|
||||
const password = localStorage.getItem(`share_pwd_${shareId}`) || ''
|
||||
const res = await client.api.shares[':shareId'].files[':fileId'].$get(
|
||||
{ param: { shareId: shareId!, fileId: id } },
|
||||
{ headers: { 'x-share-password': password } },
|
||||
)
|
||||
if (!res.ok) throw new Error('Failed to fetch version asset')
|
||||
return (await res.json()) as unknown as AssetInfo
|
||||
}
|
||||
const res = await client.api.files[':fileId'].$get({ param: { fileId: id } })
|
||||
if (!res.ok) throw new Error('Failed to fetch version asset')
|
||||
return (await res.json()) as unknown as AssetInfo
|
||||
},
|
||||
enabled: !!id && (!isPublic || !!shareId),
|
||||
})
|
||||
}
|
||||
|
||||
export function CompareViewer({
|
||||
isPublic = false,
|
||||
shareId,
|
||||
versions,
|
||||
leftId,
|
||||
rightId,
|
||||
activeSide,
|
||||
annotations,
|
||||
seekRequest,
|
||||
onActiveSideChange,
|
||||
onSwitchVersion,
|
||||
onExit,
|
||||
onActiveAssetChange,
|
||||
onPlay,
|
||||
onTimeUpdate,
|
||||
}: CompareViewerProps) {
|
||||
const rootRef = useRef<HTMLDivElement>(null)
|
||||
const leftRef = useRef<ComparePaneHandle | null>(null)
|
||||
const rightRef = useRef<ComparePaneHandle | null>(null)
|
||||
|
||||
const [leftState, setLeftState] = useState<PaneReportedState | null>(null)
|
||||
const [rightState, setRightState] = useState<PaneReportedState | null>(null)
|
||||
const [userVolume, setUserVolume] = useState(1)
|
||||
const [userMuted, setUserMuted] = useState(false)
|
||||
const [isFullScreen, setIsFullScreen] = useState(false)
|
||||
|
||||
const { data: leftAsset, isLoading: leftLoading } = useCompareAsset(leftId, isPublic, shareId)
|
||||
const { data: rightAsset, isLoading: rightLoading } = useCompareAsset(rightId, isPublic, shareId)
|
||||
|
||||
const leftKind = kindOf(leftAsset?.mediaType)
|
||||
const rightKind = kindOf(rightAsset?.mediaType)
|
||||
const sameType = isSameType(leftKind, rightKind)
|
||||
|
||||
const activeAsset = activeSide === 'left' ? leftAsset : rightAsset
|
||||
const activeState = activeSide === 'left' ? leftState : rightState
|
||||
|
||||
const getActive = useCallback(
|
||||
() => (activeSide === 'left' ? leftRef.current : rightRef.current),
|
||||
[activeSide],
|
||||
)
|
||||
const getOther = useCallback(
|
||||
() => (activeSide === 'left' ? rightRef.current : leftRef.current),
|
||||
[activeSide],
|
||||
)
|
||||
|
||||
// Bind right sidebar to active asset
|
||||
useEffect(() => {
|
||||
onActiveAssetChange(activeAsset ?? null)
|
||||
}, [activeAsset, onActiveAssetChange])
|
||||
|
||||
// Comment-driven seek on the active pane
|
||||
useEffect(() => {
|
||||
if (!seekRequest) return
|
||||
const active = getActive()
|
||||
active?.seekToSecond(seekRequest.second)
|
||||
active?.pause()
|
||||
if (sameType) {
|
||||
const other = getOther()
|
||||
other?.seekToSecond(seekRequest.second)
|
||||
other?.pause()
|
||||
}
|
||||
}, [seekRequest?.nonce])
|
||||
|
||||
// Fullscreen tracking
|
||||
useEffect(() => {
|
||||
const onFs = () => setIsFullScreen(!!document.fullscreenElement)
|
||||
document.addEventListener('fullscreenchange', onFs)
|
||||
return () => document.removeEventListener('fullscreenchange', onFs)
|
||||
}, [])
|
||||
|
||||
const handleStateChangeLeft = useCallback((s: PaneReportedState) => setLeftState(s), [])
|
||||
const handleStateChangeRight = useCallback((s: PaneReportedState) => setRightState(s), [])
|
||||
|
||||
const applyBoth = useCallback(
|
||||
(fn: (h: ComparePaneHandle) => void) => {
|
||||
const active = getActive()
|
||||
if (active) fn(active)
|
||||
if (sameType) {
|
||||
const other = getOther()
|
||||
if (other) fn(other)
|
||||
}
|
||||
},
|
||||
[getActive, getOther, sameType],
|
||||
)
|
||||
|
||||
// --- Control handlers ---
|
||||
const handleTogglePlay = useCallback(() => {
|
||||
const shouldPlay = !activeState?.video?.isPlaying
|
||||
applyBoth((h) => (shouldPlay ? h.play() : h.pause()))
|
||||
}, [activeState?.video?.isPlaying, applyBoth])
|
||||
|
||||
const handleSeek = useCallback(
|
||||
(frame: number) => applyBoth((h) => h.seekToFrame(frame)),
|
||||
[applyBoth],
|
||||
)
|
||||
|
||||
const handleToggleLoop = useCallback(() => getActive()?.toggleLoop(), [getActive])
|
||||
|
||||
const handleVolumeChange = useCallback((v: number) => {
|
||||
setUserVolume(v)
|
||||
setUserMuted(v === 0)
|
||||
}, [])
|
||||
|
||||
const handleToggleMute = useCallback(() => setUserMuted((m) => !m), [])
|
||||
|
||||
const handlePlaybackRate = useCallback(
|
||||
(rate: number) => applyBoth((h) => h.setPlaybackRate(rate)),
|
||||
[applyBoth],
|
||||
)
|
||||
|
||||
const handleChangeResolution = useCallback(
|
||||
(resolution: string) => getActive()?.changeResolution(resolution),
|
||||
[getActive],
|
||||
)
|
||||
|
||||
const handleZoomIn = useCallback(() => applyBoth((h) => h.zoomBy(1.2)), [applyBoth])
|
||||
const handleZoomOut = useCallback(() => applyBoth((h) => h.zoomBy(0.8)), [applyBoth])
|
||||
const handleFit = useCallback(() => applyBoth((h) => h.fit()), [applyBoth])
|
||||
const handleDownload = useCallback(
|
||||
(key?: string) => {
|
||||
getActive()?.download(key)
|
||||
},
|
||||
[getActive],
|
||||
)
|
||||
|
||||
const handleToggleFullScreen = useCallback(() => {
|
||||
if (!rootRef.current) return
|
||||
if (!document.fullscreenElement) {
|
||||
rootRef.current.requestFullscreen()
|
||||
} else {
|
||||
document.exitFullscreen()
|
||||
}
|
||||
}, [])
|
||||
|
||||
const handleUserPanLeft = useCallback(
|
||||
(dx: number, dy: number) => {
|
||||
if (sameType) rightRef.current?.panBy(dx, dy)
|
||||
},
|
||||
[sameType],
|
||||
)
|
||||
const handleUserPanRight = useCallback(
|
||||
(dx: number, dy: number) => {
|
||||
if (sameType) leftRef.current?.panBy(dx, dy)
|
||||
},
|
||||
[sameType],
|
||||
)
|
||||
|
||||
const handleRequestTogglePlay = useCallback(() => handleTogglePlay(), [handleTogglePlay])
|
||||
|
||||
const versionOf = useCallback(
|
||||
(id: string) => versions.find((v) => v.id === id)?.version,
|
||||
[versions],
|
||||
)
|
||||
|
||||
const activePreviewUrl = useMemo(
|
||||
() => activeAsset?.media?.videoPreview?.url,
|
||||
[activeAsset?.media?.videoPreview?.url],
|
||||
)
|
||||
|
||||
const renderPane = (side: CompareSide, asset: AssetInfo, kind: PaneKind) => {
|
||||
const isActive = activeSide === side
|
||||
const paneRef = side === 'left' ? leftRef : rightRef
|
||||
const onStateChange = side === 'left' ? handleStateChangeLeft : handleStateChangeRight
|
||||
const onUserPan = side === 'left' ? handleUserPanLeft : handleUserPanRight
|
||||
const paneAnnotations = isActive ? annotations : []
|
||||
|
||||
if (kind === 'video') {
|
||||
return (
|
||||
<CompareVideoPane
|
||||
key={asset.id}
|
||||
ref={paneRef}
|
||||
file={asset}
|
||||
shareId={shareId}
|
||||
isActive={isActive}
|
||||
muted={isActive ? userMuted : true}
|
||||
volume={userVolume}
|
||||
annotations={paneAnnotations}
|
||||
onStateChange={onStateChange}
|
||||
onActivate={() => onActiveSideChange(side)}
|
||||
onRequestTogglePlay={handleRequestTogglePlay}
|
||||
onTimeUpdate={onTimeUpdate}
|
||||
onPlay={onPlay}
|
||||
/>
|
||||
)
|
||||
}
|
||||
if (kind === 'image') {
|
||||
return (
|
||||
<CompareImagePane
|
||||
key={asset.id}
|
||||
ref={paneRef}
|
||||
file={asset}
|
||||
shareId={shareId}
|
||||
isActive={isActive}
|
||||
annotations={paneAnnotations}
|
||||
onStateChange={onStateChange}
|
||||
onUserPan={onUserPan}
|
||||
onActivate={() => onActiveSideChange(side)}
|
||||
/>
|
||||
)
|
||||
}
|
||||
return (
|
||||
<div className="flex flex-1 items-center justify-center bg-gray-100 dark:bg-gray-950">
|
||||
<p className="text-muted-foreground">Preview unavailable</p>
|
||||
</div>
|
||||
)
|
||||
}
|
||||
|
||||
const bothLoaded = !!leftAsset && !!rightAsset
|
||||
const isLoading = leftLoading || rightLoading
|
||||
|
||||
return (
|
||||
<div ref={rootRef} className="flex h-full flex-1 flex-col bg-background">
|
||||
<div className="flex min-h-0 flex-1">
|
||||
{/* Left pane */}
|
||||
<div className="flex min-w-0 flex-1 flex-col border-r border-border">
|
||||
{leftAsset && (
|
||||
<ComparePaneTopbar
|
||||
side="left"
|
||||
fileName={leftAsset.name}
|
||||
version={versionOf(leftId)}
|
||||
activeVersionId={leftId}
|
||||
versions={versions}
|
||||
isActive={activeSide === 'left'}
|
||||
onActivate={() => onActiveSideChange('left')}
|
||||
onSwitchVersion={(vid) => onSwitchVersion('left', vid)}
|
||||
onExit={onExit}
|
||||
/>
|
||||
)}
|
||||
<div className="relative flex min-h-0 flex-1">
|
||||
{leftAsset ? (
|
||||
renderPane('left', leftAsset, leftKind)
|
||||
) : (
|
||||
<div className="flex flex-1 items-center justify-center">
|
||||
<Loader2 className="h-6 w-6 animate-spin text-foreground" />
|
||||
</div>
|
||||
)}
|
||||
</div>
|
||||
</div>
|
||||
|
||||
{/* Right pane */}
|
||||
<div className="flex min-w-0 flex-1 flex-col">
|
||||
{rightAsset && (
|
||||
<ComparePaneTopbar
|
||||
side="right"
|
||||
fileName={rightAsset.name}
|
||||
version={versionOf(rightId)}
|
||||
activeVersionId={rightId}
|
||||
versions={versions}
|
||||
isActive={activeSide === 'right'}
|
||||
onActivate={() => onActiveSideChange('right')}
|
||||
onSwitchVersion={(vid) => onSwitchVersion('right', vid)}
|
||||
onExit={onExit}
|
||||
/>
|
||||
)}
|
||||
<div className="relative flex min-h-0 flex-1">
|
||||
{rightAsset ? (
|
||||
renderPane('right', rightAsset, rightKind)
|
||||
) : (
|
||||
<div className="flex flex-1 items-center justify-center">
|
||||
<Loader2 className="h-6 w-6 animate-spin text-foreground" />
|
||||
</div>
|
||||
)}
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
|
||||
{isLoading && !bothLoaded && (
|
||||
<div className="absolute inset-0 z-10 flex items-center justify-center bg-background/30">
|
||||
<Loader2 className="h-8 w-8 animate-spin text-foreground" />
|
||||
</div>
|
||||
)}
|
||||
|
||||
<CompareControlBar
|
||||
activeState={activeState}
|
||||
previewUrl={activePreviewUrl}
|
||||
metadata={activeAsset?.media?.metadata}
|
||||
startTimecode={activeAsset?.media?.metadata?.startTimecode}
|
||||
isFullScreen={isFullScreen}
|
||||
onTogglePlay={handleTogglePlay}
|
||||
onToggleLoop={handleToggleLoop}
|
||||
onSeek={handleSeek}
|
||||
onVolumeChange={handleVolumeChange}
|
||||
onToggleMute={handleToggleMute}
|
||||
onChangePlaybackRate={handlePlaybackRate}
|
||||
onChangeResolution={handleChangeResolution}
|
||||
onZoomIn={handleZoomIn}
|
||||
onZoomOut={handleZoomOut}
|
||||
onFit={handleFit}
|
||||
onDownload={handleDownload}
|
||||
onToggleFullScreen={handleToggleFullScreen}
|
||||
/>
|
||||
</div>
|
||||
)
|
||||
}
|
||||
@@ -0,0 +1,55 @@
|
||||
import type { VideoTranscode } from '@shumai/dtos'
|
||||
|
||||
export type PaneKind = 'image' | 'video' | 'unsupported'
|
||||
|
||||
export type CompareSide = 'left' | 'right'
|
||||
|
||||
export type DisplayTranscode = VideoTranscode & { resolution: string }
|
||||
|
||||
/**
|
||||
* Reactive state a pane reports upward so the shared control bar can render.
|
||||
* `video` is populated only for video panes.
|
||||
*/
|
||||
export interface PaneReportedState {
|
||||
kind: PaneKind
|
||||
zoom: number
|
||||
video?: {
|
||||
frameRate: number
|
||||
totalFrames: number
|
||||
currentFrame: number
|
||||
isPlaying: boolean
|
||||
volume: number
|
||||
isMuted: boolean
|
||||
playbackRate: number
|
||||
isLooping: boolean
|
||||
currentResolution: string
|
||||
resolutions: DisplayTranscode[]
|
||||
buffered: number
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Imperative command surface exposed by each pane via ref. The shared control
|
||||
* bar dispatches to the active pane (and, when media types match, to both).
|
||||
*/
|
||||
export interface ComparePaneHandle {
|
||||
getKind: () => PaneKind
|
||||
// Playback (video only; no-ops for images)
|
||||
play: () => void
|
||||
pause: () => void
|
||||
togglePlay: () => void
|
||||
seekToFrame: (frame: number) => void
|
||||
seekToSecond: (second: number) => void
|
||||
stepFrame: (delta: number) => void
|
||||
setMuted: (muted: boolean) => void
|
||||
setVolume: (volume: number) => void
|
||||
setPlaybackRate: (rate: number) => void
|
||||
toggleLoop: () => void
|
||||
changeResolution: (resolution: string) => void
|
||||
// Zoom / pan (image + video)
|
||||
zoomBy: (factor: number) => void
|
||||
fit: () => void
|
||||
panBy: (dx: number, dy: number) => void
|
||||
// Download active side's original/selected media
|
||||
download: (key?: string) => void
|
||||
}
|
||||
@@ -16,6 +16,8 @@ import { Lock, AlertCircle, Loader2 } from 'lucide-react'
|
||||
import type { AncestorFolder, AssetInfoPaginatedList, AssetInfo, CommentInfo } from '@shumai/dtos'
|
||||
import { FieldInfo } from '@shumai/dtos'
|
||||
import { FileViewer } from './file-viewer'
|
||||
import { CompareViewer } from './compare/compare-viewer'
|
||||
import { pickDefaultCompareVersions } from './compare/compare-utils'
|
||||
import type Player from 'video.js/dist/types/player'
|
||||
import type { Annotation } from '@/ui/types'
|
||||
|
||||
@@ -26,6 +28,10 @@ interface PublicShareManagerProps {
|
||||
initialFolderId?: string
|
||||
initialFileId?: string
|
||||
startTime?: number
|
||||
compare?: boolean
|
||||
compareLeftId?: string
|
||||
compareRightId?: string
|
||||
compareActiveSide?: 'left' | 'right'
|
||||
}
|
||||
|
||||
interface PublicShareInfo {
|
||||
@@ -46,8 +52,13 @@ export function PublicShareManager({
|
||||
initialFolderId,
|
||||
initialFileId,
|
||||
startTime,
|
||||
compare,
|
||||
compareLeftId,
|
||||
compareRightId,
|
||||
compareActiveSide = 'left',
|
||||
}: PublicShareManagerProps) {
|
||||
const navigate = useNavigate()
|
||||
const isCompareMode = !!compare && !!compareLeftId && !!compareRightId
|
||||
const [password, setPassword] = useState(() => {
|
||||
return localStorage.getItem(`share_pwd_${shareId}`) || ''
|
||||
})
|
||||
@@ -129,6 +140,10 @@ export function PublicShareManager({
|
||||
const [annotations, setAnnotations] = useState<Annotation[]>([])
|
||||
const [currentTime, setCurrentTime] = useState(0)
|
||||
const [selectedCommentId, setSelectedCommentId] = useState<string | null>(null)
|
||||
const [compareActiveAsset, setCompareActiveAsset] = useState<AssetInfo | null>(null)
|
||||
const [seekRequest, setSeekRequest] = useState<{ second: number; nonce: number } | undefined>(
|
||||
undefined,
|
||||
)
|
||||
|
||||
const {
|
||||
data: foldersData,
|
||||
@@ -307,6 +322,13 @@ export function PublicShareManager({
|
||||
setAnnotations([])
|
||||
}
|
||||
|
||||
if (isCompareMode) {
|
||||
if (comment.second !== null && comment.second !== undefined) {
|
||||
setSeekRequest({ second: comment.second, nonce: Date.now() })
|
||||
}
|
||||
return
|
||||
}
|
||||
|
||||
if (comment.second !== null && comment.second !== undefined) {
|
||||
if (videoRef.current) {
|
||||
videoRef.current.currentTime(comment.second)
|
||||
@@ -324,6 +346,24 @@ export function PublicShareManager({
|
||||
setSelectedCommentId(null)
|
||||
}
|
||||
|
||||
const updateCompareSearch = (patch: Record<string, unknown>) => {
|
||||
if (!viewingFileId) return
|
||||
navigate({
|
||||
to: '/share/$shareId/files/$fileId',
|
||||
params: { shareId, fileId: viewingFileId },
|
||||
search: (p: Record<string, unknown>) => ({ ...p, ...patch }),
|
||||
})
|
||||
}
|
||||
|
||||
const handleCompareExit = () => {
|
||||
updateCompareSearch({
|
||||
compare: undefined,
|
||||
cmpLeft: undefined,
|
||||
cmpRight: undefined,
|
||||
cmpActive: undefined,
|
||||
})
|
||||
}
|
||||
|
||||
const { setProjectState, clearProjectState } = useTopNavStore()
|
||||
|
||||
useEffect(() => {
|
||||
@@ -364,6 +404,24 @@ export function PublicShareManager({
|
||||
onFolderClick: handleBreadcrumbClick,
|
||||
isRightSidebarCollapsed,
|
||||
onRightSidebarToggle: () => setIsRightSidebarCollapsed((prev) => !prev),
|
||||
versions: viewingFileData?.versionStack?.versions,
|
||||
compareMode: isCompareMode,
|
||||
canCompareVersions: (viewingFileData?.versionStack?.versions?.length ?? 0) >= 2,
|
||||
onCompareVersions: () => {
|
||||
const pair = pickDefaultCompareVersions(viewingFileData?.versionStack?.versions)
|
||||
if (!pair || !viewingFileId) return
|
||||
navigate({
|
||||
to: '/share/$shareId/files/$fileId',
|
||||
params: { shareId, fileId: viewingFileId },
|
||||
search: (p: Record<string, unknown>) => ({
|
||||
...p,
|
||||
compare: true,
|
||||
cmpLeft: pair.left.id,
|
||||
cmpRight: pair.right.id,
|
||||
cmpActive: 'left' as const,
|
||||
}),
|
||||
})
|
||||
},
|
||||
})
|
||||
}
|
||||
|
||||
@@ -378,6 +436,9 @@ export function PublicShareManager({
|
||||
setProjectState,
|
||||
clearProjectState,
|
||||
isRightSidebarCollapsed,
|
||||
isCompareMode,
|
||||
navigate,
|
||||
shareId,
|
||||
])
|
||||
|
||||
let content
|
||||
@@ -456,21 +517,44 @@ export function PublicShareManager({
|
||||
<div className="flex flex-1 overflow-hidden relative">
|
||||
{viewingFileId ? (
|
||||
<div className="flex-1 relative bg-muted/30">
|
||||
{isViewingFileLoading && (
|
||||
{isViewingFileLoading && !isCompareMode && (
|
||||
<div className="absolute inset-0 z-10 flex items-center justify-center bg-background/50">
|
||||
<Loader2 className="h-8 w-8 animate-spin text-foreground" />
|
||||
</div>
|
||||
)}
|
||||
{viewingFileData && (
|
||||
<FileViewer
|
||||
file={viewingFileData}
|
||||
videoRef={videoRef}
|
||||
{isCompareMode && compareLeftId && compareRightId ? (
|
||||
<CompareViewer
|
||||
isPublic
|
||||
shareId={shareId}
|
||||
versions={viewingFileData?.versionStack?.versions ?? []}
|
||||
leftId={compareLeftId}
|
||||
rightId={compareRightId}
|
||||
activeSide={compareActiveSide}
|
||||
annotations={annotations}
|
||||
seekRequest={seekRequest}
|
||||
onActiveSideChange={(side) => updateCompareSearch({ cmpActive: side })}
|
||||
onSwitchVersion={(side, versionId) =>
|
||||
updateCompareSearch(
|
||||
side === 'left' ? { cmpLeft: versionId } : { cmpRight: versionId },
|
||||
)
|
||||
}
|
||||
onExit={handleCompareExit}
|
||||
onActiveAssetChange={setCompareActiveAsset}
|
||||
onPlay={handlePlay}
|
||||
onTimeUpdate={setCurrentTime}
|
||||
annotations={annotations}
|
||||
startTime={startTime}
|
||||
shareId={shareId}
|
||||
/>
|
||||
) : (
|
||||
viewingFileData && (
|
||||
<FileViewer
|
||||
file={viewingFileData}
|
||||
videoRef={videoRef}
|
||||
onPlay={handlePlay}
|
||||
onTimeUpdate={setCurrentTime}
|
||||
annotations={annotations}
|
||||
startTime={startTime}
|
||||
shareId={shareId}
|
||||
/>
|
||||
)
|
||||
)}
|
||||
</div>
|
||||
) : (
|
||||
@@ -520,7 +604,7 @@ export function PublicShareManager({
|
||||
<FileViewerRightSidebar
|
||||
teamId=""
|
||||
projectId={shareInfo.projectId}
|
||||
file={currentSelectedItem}
|
||||
file={isCompareMode ? compareActiveAsset : currentSelectedItem}
|
||||
onSaveField={() => {}}
|
||||
members={[]}
|
||||
readOnly={true}
|
||||
|
||||
@@ -24,6 +24,9 @@ export function TopNav() {
|
||||
isPublic,
|
||||
shareId,
|
||||
onFolderClick,
|
||||
compareMode,
|
||||
canCompareVersions,
|
||||
onCompareVersions,
|
||||
} = projectState
|
||||
|
||||
const isFileView = !!fileId
|
||||
@@ -91,6 +94,9 @@ export function TopNav() {
|
||||
downloadInfo={downloadInfo}
|
||||
versions={versions}
|
||||
onFolderClick={onFolderClick}
|
||||
compareMode={compareMode}
|
||||
canCompareVersions={canCompareVersions}
|
||||
onCompareVersions={onCompareVersions}
|
||||
/>
|
||||
)
|
||||
}
|
||||
|
||||
@@ -433,6 +433,9 @@
|
||||
|
||||
"versions": "Versions",
|
||||
"manage_versions": "Manage versions...",
|
||||
"compare_versions": "Compare Versions",
|
||||
"exit_compare": "Exit compare",
|
||||
"switch_version": "Switch version",
|
||||
"show_left_sidebar": "Show Left Sidebar",
|
||||
"hide_left_sidebar": "Hide Left Sidebar",
|
||||
"show_right_sidebar": "Show Right Sidebar",
|
||||
|
||||
@@ -433,6 +433,9 @@
|
||||
|
||||
"versions": "版本",
|
||||
"manage_versions": "管理版本...",
|
||||
"compare_versions": "对比版本",
|
||||
"exit_compare": "退出对比",
|
||||
"switch_version": "切换版本",
|
||||
"show_left_sidebar": "显示左侧边栏",
|
||||
"hide_left_sidebar": "隐藏左侧边栏",
|
||||
"show_right_sidebar": "显示右侧边栏",
|
||||
|
||||
+3
@@ -411,6 +411,9 @@ export * from "./auth_feature_teams.js";
|
||||
export * from "./auth_community_cta.js";
|
||||
export * from "./versions.js";
|
||||
export * from "./manage_versions.js";
|
||||
export * from "./compare_versions.js";
|
||||
export * from "./exit_compare.js";
|
||||
export * from "./switch_version.js";
|
||||
export * from "./show_left_sidebar.js";
|
||||
export * from "./hide_left_sidebar.js";
|
||||
export * from "./show_right_sidebar.js";
|
||||
|
||||
+3
@@ -413,6 +413,9 @@ export * from './auth_feature_teams.js'
|
||||
export * from './auth_community_cta.js'
|
||||
export * from './versions.js'
|
||||
export * from './manage_versions.js'
|
||||
export * from './compare_versions.js'
|
||||
export * from './exit_compare.js'
|
||||
export * from './switch_version.js'
|
||||
export * from './show_left_sidebar.js'
|
||||
export * from './hide_left_sidebar.js'
|
||||
export * from './show_right_sidebar.js'
|
||||
|
||||
+16
@@ -0,0 +1,16 @@
|
||||
/**
|
||||
* | output |
|
||||
* | --- |
|
||||
* | "Compare Versions" |
|
||||
*
|
||||
* @param {Compare_VersionsInputs} inputs
|
||||
* @param {{ locale?: "en" | "zh" }} options
|
||||
* @returns {LocalizedString}
|
||||
*/
|
||||
export const compare_versions: ((inputs?: Compare_VersionsInputs, options?: {
|
||||
locale?: "en" | "zh";
|
||||
}) => LocalizedString) & import("../runtime.js").MessageMetadata<Compare_VersionsInputs, {
|
||||
locale?: "en" | "zh";
|
||||
}, {}>;
|
||||
export type LocalizedString = import("../runtime.js").LocalizedString;
|
||||
export type Compare_VersionsInputs = {};
|
||||
@@ -0,0 +1,29 @@
|
||||
/* eslint-disable */
|
||||
import { getLocale, experimentalStaticLocale } from '../runtime.js';
|
||||
|
||||
/** @typedef {import('../runtime.js').LocalizedString} LocalizedString */
|
||||
|
||||
/** @typedef {{}} Compare_VersionsInputs */
|
||||
|
||||
const en_compare_versions = /** @type {(inputs: Compare_VersionsInputs) => LocalizedString} */ () => {
|
||||
return /** @type {LocalizedString} */ (`Compare Versions`)
|
||||
};
|
||||
|
||||
const zh_compare_versions = /** @type {(inputs: Compare_VersionsInputs) => LocalizedString} */ () => {
|
||||
return /** @type {LocalizedString} */ (`对比版本`)
|
||||
};
|
||||
|
||||
/**
|
||||
* | output |
|
||||
* | --- |
|
||||
* | "Compare Versions" |
|
||||
*
|
||||
* @param {Compare_VersionsInputs} inputs
|
||||
* @param {{ locale?: "en" | "zh" }} options
|
||||
* @returns {LocalizedString}
|
||||
*/
|
||||
export const compare_versions = /** @type {((inputs?: Compare_VersionsInputs, options?: { locale?: "en" | "zh" }) => LocalizedString) & import('../runtime.js').MessageMetadata<Compare_VersionsInputs, { locale?: "en" | "zh" }, {}>} */ ((inputs = {}, options = {}) => {
|
||||
const locale = experimentalStaticLocale ?? options.locale ?? getLocale()
|
||||
if (locale === "en") return en_compare_versions(inputs)
|
||||
return zh_compare_versions(inputs)
|
||||
});
|
||||
+16
@@ -0,0 +1,16 @@
|
||||
/**
|
||||
* | output |
|
||||
* | --- |
|
||||
* | "Exit compare" |
|
||||
*
|
||||
* @param {Exit_CompareInputs} inputs
|
||||
* @param {{ locale?: "en" | "zh" }} options
|
||||
* @returns {LocalizedString}
|
||||
*/
|
||||
export const exit_compare: ((inputs?: Exit_CompareInputs, options?: {
|
||||
locale?: "en" | "zh";
|
||||
}) => LocalizedString) & import("../runtime.js").MessageMetadata<Exit_CompareInputs, {
|
||||
locale?: "en" | "zh";
|
||||
}, {}>;
|
||||
export type LocalizedString = import("../runtime.js").LocalizedString;
|
||||
export type Exit_CompareInputs = {};
|
||||
+29
@@ -0,0 +1,29 @@
|
||||
/* eslint-disable */
|
||||
import { getLocale, experimentalStaticLocale } from '../runtime.js';
|
||||
|
||||
/** @typedef {import('../runtime.js').LocalizedString} LocalizedString */
|
||||
|
||||
/** @typedef {{}} Exit_CompareInputs */
|
||||
|
||||
const en_exit_compare = /** @type {(inputs: Exit_CompareInputs) => LocalizedString} */ () => {
|
||||
return /** @type {LocalizedString} */ (`Exit compare`)
|
||||
};
|
||||
|
||||
const zh_exit_compare = /** @type {(inputs: Exit_CompareInputs) => LocalizedString} */ () => {
|
||||
return /** @type {LocalizedString} */ (`退出对比`)
|
||||
};
|
||||
|
||||
/**
|
||||
* | output |
|
||||
* | --- |
|
||||
* | "Exit compare" |
|
||||
*
|
||||
* @param {Exit_CompareInputs} inputs
|
||||
* @param {{ locale?: "en" | "zh" }} options
|
||||
* @returns {LocalizedString}
|
||||
*/
|
||||
export const exit_compare = /** @type {((inputs?: Exit_CompareInputs, options?: { locale?: "en" | "zh" }) => LocalizedString) & import('../runtime.js').MessageMetadata<Exit_CompareInputs, { locale?: "en" | "zh" }, {}>} */ ((inputs = {}, options = {}) => {
|
||||
const locale = experimentalStaticLocale ?? options.locale ?? getLocale()
|
||||
if (locale === "en") return en_exit_compare(inputs)
|
||||
return zh_exit_compare(inputs)
|
||||
});
|
||||
+16
@@ -0,0 +1,16 @@
|
||||
/**
|
||||
* | output |
|
||||
* | --- |
|
||||
* | "Switch version" |
|
||||
*
|
||||
* @param {Switch_VersionInputs} inputs
|
||||
* @param {{ locale?: "en" | "zh" }} options
|
||||
* @returns {LocalizedString}
|
||||
*/
|
||||
export const switch_version: ((inputs?: Switch_VersionInputs, options?: {
|
||||
locale?: "en" | "zh";
|
||||
}) => LocalizedString) & import("../runtime.js").MessageMetadata<Switch_VersionInputs, {
|
||||
locale?: "en" | "zh";
|
||||
}, {}>;
|
||||
export type LocalizedString = import("../runtime.js").LocalizedString;
|
||||
export type Switch_VersionInputs = {};
|
||||
+29
@@ -0,0 +1,29 @@
|
||||
/* eslint-disable */
|
||||
import { getLocale, experimentalStaticLocale } from '../runtime.js';
|
||||
|
||||
/** @typedef {import('../runtime.js').LocalizedString} LocalizedString */
|
||||
|
||||
/** @typedef {{}} Switch_VersionInputs */
|
||||
|
||||
const en_switch_version = /** @type {(inputs: Switch_VersionInputs) => LocalizedString} */ () => {
|
||||
return /** @type {LocalizedString} */ (`Switch version`)
|
||||
};
|
||||
|
||||
const zh_switch_version = /** @type {(inputs: Switch_VersionInputs) => LocalizedString} */ () => {
|
||||
return /** @type {LocalizedString} */ (`切换版本`)
|
||||
};
|
||||
|
||||
/**
|
||||
* | output |
|
||||
* | --- |
|
||||
* | "Switch version" |
|
||||
*
|
||||
* @param {Switch_VersionInputs} inputs
|
||||
* @param {{ locale?: "en" | "zh" }} options
|
||||
* @returns {LocalizedString}
|
||||
*/
|
||||
export const switch_version = /** @type {((inputs?: Switch_VersionInputs, options?: { locale?: "en" | "zh" }) => LocalizedString) & import('../runtime.js').MessageMetadata<Switch_VersionInputs, { locale?: "en" | "zh" }, {}>} */ ((inputs = {}, options = {}) => {
|
||||
const locale = experimentalStaticLocale ?? options.locale ?? getLocale()
|
||||
if (locale === "en") return en_switch_version(inputs)
|
||||
return zh_switch_version(inputs)
|
||||
});
|
||||
@@ -1,5 +1,7 @@
|
||||
import { client } from '@/ui/api/client'
|
||||
import { FileViewer } from '@/ui/components/file-viewer'
|
||||
import { CompareViewer } from '@/ui/components/compare/compare-viewer'
|
||||
import { pickDefaultCompareVersions } from '@/ui/components/compare/compare-utils'
|
||||
import { FileViewerLeftSidebar } from '@/ui/components/file-viewer-left-sidebar'
|
||||
import { m } from '@/ui/paraglide/messages.js'
|
||||
import { FileViewerRightSidebar } from '@/ui/components/file-viewer-right-sidebar'
|
||||
@@ -25,6 +27,10 @@ function FileViewPage() {
|
||||
const versionAssetId = search.version
|
||||
const startTime = search.start
|
||||
const activeFileId = versionAssetId || fileId
|
||||
const compareLeftId = search.cmpLeft
|
||||
const compareRightId = search.cmpRight
|
||||
const compareActiveSide = search.cmpActive ?? 'left'
|
||||
const isCompareMode = !!search.compare && !!compareLeftId && !!compareRightId
|
||||
|
||||
const videoRef = useRef<Player | null>(null)
|
||||
const { teamId, ensureTeamIdForProject } = useTeamContextStore()
|
||||
@@ -32,6 +38,10 @@ function FileViewPage() {
|
||||
const [annotations, setAnnotations] = useState<Annotation[]>([])
|
||||
const [currentTime, setCurrentTime] = useState(0)
|
||||
const [selectedCommentId, setSelectedCommentId] = useState<string | null>(null)
|
||||
const [compareActiveAsset, setCompareActiveAsset] = useState<AssetInfo | null>(null)
|
||||
const [seekRequest, setSeekRequest] = useState<{ second: number; nonce: number } | undefined>(
|
||||
undefined,
|
||||
)
|
||||
const [carouselState, setCarouselState] = useState<{
|
||||
show: boolean
|
||||
files: AssetInfo[]
|
||||
@@ -108,7 +118,7 @@ function FileViewPage() {
|
||||
if (!res.ok) throw new Error('Failed to fetch versions')
|
||||
return await res.json()
|
||||
},
|
||||
enabled: !!projectId && !!fileId && !!versionAssetId,
|
||||
enabled: !!projectId && !!fileId && (!!versionAssetId || isCompareMode),
|
||||
})
|
||||
|
||||
const { data: projectInfo } = useQuery({
|
||||
@@ -158,6 +168,24 @@ function FileViewPage() {
|
||||
})),
|
||||
},
|
||||
versions: versionsDataList,
|
||||
compareMode: isCompareMode,
|
||||
canCompareVersions: (versionsDataList?.length ?? 0) >= 2,
|
||||
onCompareVersions: () => {
|
||||
const pair = pickDefaultCompareVersions(versionsDataList)
|
||||
if (!pair) return
|
||||
navigate({
|
||||
to: '/projects/$projectId/files/$fileId',
|
||||
params: { projectId, fileId },
|
||||
search: (p: Record<string, unknown>) => ({
|
||||
...p,
|
||||
version: undefined,
|
||||
compare: true,
|
||||
cmpLeft: pair.left.id,
|
||||
cmpRight: pair.right.id,
|
||||
cmpActive: 'left' as const,
|
||||
}),
|
||||
})
|
||||
},
|
||||
onFolderClick: (id: string) => {
|
||||
navigate({
|
||||
to: '/projects/$projectId/folders/$folderId',
|
||||
@@ -176,6 +204,7 @@ function FileViewPage() {
|
||||
versionsDataList,
|
||||
activeFileId,
|
||||
fileId,
|
||||
isCompareMode,
|
||||
setProjectState,
|
||||
clearProjectState,
|
||||
navigate,
|
||||
@@ -270,6 +299,11 @@ function FileViewPage() {
|
||||
setAnnotations([])
|
||||
}, [fileData?.id])
|
||||
|
||||
useEffect(() => {
|
||||
setSelectedCommentId(null)
|
||||
setAnnotations([])
|
||||
}, [compareActiveAsset?.id])
|
||||
|
||||
if (isLoading && !fileData) {
|
||||
return <FileDetailSkeleton />
|
||||
}
|
||||
@@ -278,23 +312,45 @@ function FileViewPage() {
|
||||
return <div>{m.file_not_found()}</div>
|
||||
}
|
||||
|
||||
const sidebarFile = isCompareMode ? compareActiveAsset : (fileData as unknown as AssetInfo)
|
||||
const sidebarFileId = sidebarFile?.id ?? activeFileId
|
||||
|
||||
const handleSaveField = (fieldId: string, value: unknown) => {
|
||||
if (!teamId) return
|
||||
patchMetadata(
|
||||
{
|
||||
param: { fileId: activeFileId },
|
||||
param: { fileId: sidebarFileId },
|
||||
json: [{ key: fieldId, value }] as InferRequestType<typeof $patchMetadata>['json'],
|
||||
},
|
||||
{
|
||||
onSuccess: () => {
|
||||
queryClient.invalidateQueries({
|
||||
queryKey: ['files', activeFileId],
|
||||
queryKey: ['files', sidebarFileId],
|
||||
})
|
||||
},
|
||||
},
|
||||
)
|
||||
}
|
||||
|
||||
const updateCompareSearch = (patch: Record<string, unknown>) => {
|
||||
navigate({
|
||||
to: '/projects/$projectId/files/$fileId',
|
||||
params: { projectId, fileId },
|
||||
search: (p: Record<string, unknown>) => ({ ...p, ...patch }),
|
||||
})
|
||||
}
|
||||
|
||||
const handleCompareExit = () => {
|
||||
const activeId = compareActiveSide === 'left' ? compareLeftId : compareRightId
|
||||
updateCompareSearch({
|
||||
compare: undefined,
|
||||
cmpLeft: undefined,
|
||||
cmpRight: undefined,
|
||||
cmpActive: undefined,
|
||||
version: activeId,
|
||||
})
|
||||
}
|
||||
|
||||
const handleCommentSelect = (comment: CommentInfo) => {
|
||||
setSelectedCommentId(comment.id || null)
|
||||
const newAnnotations = comment.annotations as Annotation[]
|
||||
@@ -304,6 +360,13 @@ function FileViewPage() {
|
||||
setAnnotations([])
|
||||
}
|
||||
|
||||
if (isCompareMode) {
|
||||
if (comment.second !== null && comment.second !== undefined) {
|
||||
setSeekRequest({ second: comment.second, nonce: Date.now() })
|
||||
}
|
||||
return
|
||||
}
|
||||
|
||||
if (comment.second !== null && comment.second !== undefined) {
|
||||
if (videoRef.current) {
|
||||
videoRef.current.currentTime(comment.second)
|
||||
@@ -325,29 +388,50 @@ function FileViewPage() {
|
||||
<div className="h-full flex flex-1 flex-col bg-background">
|
||||
<div className="h-full flex flex-1 overflow-hidden">
|
||||
<div className="flex-1 relative">
|
||||
{isFetching && (
|
||||
{isFetching && !isCompareMode && (
|
||||
<div className="absolute inset-0 z-10 flex items-center justify-center bg-background/50">
|
||||
<Loader2 className="h-8 w-8 animate-spin text-foreground" />
|
||||
</div>
|
||||
)}
|
||||
<FileViewer
|
||||
file={fileData as unknown as AssetInfo}
|
||||
videoRef={videoRef}
|
||||
onPlay={handlePlay}
|
||||
onTimeUpdate={setCurrentTime}
|
||||
annotations={annotations}
|
||||
startTime={startTime}
|
||||
>
|
||||
{carouselState.show && (
|
||||
<FileViewerLeftSidebar
|
||||
projectId={projectId}
|
||||
currentAssetId={activeFileId}
|
||||
parentFolderId={parentFolderId}
|
||||
initialFiles={carouselState.files}
|
||||
initialNextCursor={carouselState.nextCursor}
|
||||
/>
|
||||
)}
|
||||
</FileViewer>
|
||||
{isCompareMode && compareLeftId && compareRightId ? (
|
||||
<CompareViewer
|
||||
versions={versionsDataList ?? []}
|
||||
leftId={compareLeftId}
|
||||
rightId={compareRightId}
|
||||
activeSide={compareActiveSide}
|
||||
annotations={annotations}
|
||||
seekRequest={seekRequest}
|
||||
onActiveSideChange={(side) => updateCompareSearch({ cmpActive: side })}
|
||||
onSwitchVersion={(side, versionId) =>
|
||||
updateCompareSearch(
|
||||
side === 'left' ? { cmpLeft: versionId } : { cmpRight: versionId },
|
||||
)
|
||||
}
|
||||
onExit={handleCompareExit}
|
||||
onActiveAssetChange={setCompareActiveAsset}
|
||||
onPlay={handlePlay}
|
||||
onTimeUpdate={setCurrentTime}
|
||||
/>
|
||||
) : (
|
||||
<FileViewer
|
||||
file={fileData as unknown as AssetInfo}
|
||||
videoRef={videoRef}
|
||||
onPlay={handlePlay}
|
||||
onTimeUpdate={setCurrentTime}
|
||||
annotations={annotations}
|
||||
startTime={startTime}
|
||||
>
|
||||
{carouselState.show && (
|
||||
<FileViewerLeftSidebar
|
||||
projectId={projectId}
|
||||
currentAssetId={activeFileId}
|
||||
parentFolderId={parentFolderId}
|
||||
initialFiles={carouselState.files}
|
||||
initialNextCursor={carouselState.nextCursor}
|
||||
/>
|
||||
)}
|
||||
</FileViewer>
|
||||
)}
|
||||
</div>
|
||||
<ResizeHandle
|
||||
onResize={(delta) => {
|
||||
@@ -359,12 +443,13 @@ function FileViewPage() {
|
||||
<FileViewerRightSidebar
|
||||
teamId={teamId}
|
||||
projectId={projectId}
|
||||
file={fileData as unknown as AssetInfo}
|
||||
file={sidebarFile}
|
||||
onSaveField={handleSaveField}
|
||||
members={members}
|
||||
onCommentSelect={handleCommentSelect}
|
||||
currentTime={currentTime}
|
||||
onTyping={() => {
|
||||
if (isCompareMode) return
|
||||
if (videoRef.current) {
|
||||
videoRef.current.pause()
|
||||
}
|
||||
@@ -383,6 +468,17 @@ export const Route = createFileRoute('/projects/$projectId/files/$fileId')({
|
||||
return {
|
||||
version: (search.version as string) || undefined,
|
||||
start: search.start ? Number(search.start) : undefined,
|
||||
} as { version?: string; start?: number }
|
||||
compare: search.compare === true || search.compare === 'true' || undefined,
|
||||
cmpLeft: (search.cmpLeft as string) || undefined,
|
||||
cmpRight: (search.cmpRight as string) || undefined,
|
||||
cmpActive: search.cmpActive === 'right' ? 'right' : undefined,
|
||||
} as {
|
||||
version?: string
|
||||
start?: number
|
||||
compare?: boolean
|
||||
cmpLeft?: string
|
||||
cmpRight?: string
|
||||
cmpActive?: 'left' | 'right'
|
||||
}
|
||||
},
|
||||
})
|
||||
|
||||
@@ -3,9 +3,19 @@ import { createFileRoute } from '@tanstack/react-router'
|
||||
|
||||
function PublicShareFilePage() {
|
||||
const { shareId, fileId } = Route.useParams()
|
||||
const { start } = Route.useSearch()
|
||||
const { start, compare, cmpLeft, cmpRight, cmpActive } = Route.useSearch()
|
||||
|
||||
return <PublicShareManager shareId={shareId} initialFileId={fileId} startTime={start} />
|
||||
return (
|
||||
<PublicShareManager
|
||||
shareId={shareId}
|
||||
initialFileId={fileId}
|
||||
startTime={start}
|
||||
compare={compare}
|
||||
compareLeftId={cmpLeft}
|
||||
compareRightId={cmpRight}
|
||||
compareActiveSide={cmpActive}
|
||||
/>
|
||||
)
|
||||
}
|
||||
|
||||
export const Route = createFileRoute('/share/$shareId/files/$fileId')({
|
||||
@@ -13,6 +23,16 @@ export const Route = createFileRoute('/share/$shareId/files/$fileId')({
|
||||
validateSearch: (search: Record<string, unknown>) => {
|
||||
return {
|
||||
start: search.start ? Number(search.start) : undefined,
|
||||
} as { start?: number }
|
||||
compare: search.compare === true || search.compare === 'true' || undefined,
|
||||
cmpLeft: (search.cmpLeft as string) || undefined,
|
||||
cmpRight: (search.cmpRight as string) || undefined,
|
||||
cmpActive: search.cmpActive === 'right' ? 'right' : undefined,
|
||||
} as {
|
||||
start?: number
|
||||
compare?: boolean
|
||||
cmpLeft?: string
|
||||
cmpRight?: string
|
||||
cmpActive?: 'left' | 'right'
|
||||
}
|
||||
},
|
||||
})
|
||||
|
||||
@@ -34,6 +34,10 @@ export interface TopNavProjectState {
|
||||
onFolderClick?: (folderId: string) => void
|
||||
isRightSidebarCollapsed?: boolean
|
||||
onRightSidebarToggle?: () => void
|
||||
// Compare Versions
|
||||
compareMode?: boolean
|
||||
canCompareVersions?: boolean
|
||||
onCompareVersions?: () => void
|
||||
}
|
||||
|
||||
interface TopNavStore {
|
||||
|
||||
Reference in New Issue
Block a user