Files
shumai/packages/webui/stores/top-nav.ts
T
yiling 6c3d3ea2b3 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.
2026-07-04 10:20:16 +08:00

68 lines
1.6 KiB
TypeScript

import { create } from 'zustand'
import type { AncestorFolder } from '@shumai/dtos'
export interface TopNavProjectState {
teamId: string
projectId: string
projectName: string
ancestorFolders: AncestorFolder[]
currentAsset: {
name?: string
type: 'file' | 'folder'
version?: number
}
isRootFolder: boolean
fileId?: string
downloadInfo?: {
originalKey?: string
videoTranscodes?: Array<{
key: string
width: number
height: number
isRaw?: boolean
}>
}
versions?: Array<{
id: string
version: number
name?: string | null
previewUrl?: string | null
creator?: { id: string; name: string | null } | null
}>
isPublic?: boolean
shareId?: string
onFolderClick?: (folderId: string) => void
isRightSidebarCollapsed?: boolean
onRightSidebarToggle?: () => void
// Compare Versions
compareMode?: boolean
canCompareVersions?: boolean
onCompareVersions?: () => void
}
interface TopNavStore {
projectState: TopNavProjectState | null
setProjectState: (state: TopNavProjectState | null) => void
clearProjectState: () => void
}
let timeoutId: ReturnType<typeof setTimeout> | null = null
export const useTopNavStore = create<TopNavStore>((set) => ({
projectState: null,
setProjectState: (state) => {
if (timeoutId) {
clearTimeout(timeoutId)
timeoutId = null
}
set({ projectState: state })
},
clearProjectState: () => {
if (timeoutId) clearTimeout(timeoutId)
timeoutId = setTimeout(() => {
set({ projectState: null })
timeoutId = null
}, 10) // Small debounce to prevent flicker during transitions
},
}))