From ea201ad19fd63b2e6e86a36607625643707fedfa Mon Sep 17 00:00:00 2001 From: yiling Date: Sat, 18 Jul 2026 11:20:13 +0800 Subject: [PATCH] feat(webui): support custom timestamp formatting for PDF viewer comments (P9) --- packages/webui/components/chat/message-card.tsx | 10 ++++++++-- .../webui/components/chat/message-input.tsx | 17 ++++++++++++++--- .../components/file-viewer-right-sidebar.tsx | 3 +++ packages/webui/components/viewers/pdf/index.tsx | 1 + packages/webui/components/viewers/types.ts | 1 + 5 files changed, 27 insertions(+), 5 deletions(-) diff --git a/packages/webui/components/chat/message-card.tsx b/packages/webui/components/chat/message-card.tsx index 7c6d0cb7..9bd9f4d4 100644 --- a/packages/webui/components/chat/message-card.tsx +++ b/packages/webui/components/chat/message-card.tsx @@ -51,6 +51,7 @@ interface MessageCardProps { onSelect?: () => void frameRate?: number startTimecode?: string + formatTimestamp?: (second: number) => string rootParentId?: string } @@ -111,6 +112,7 @@ export const MessageCard: React.FC = ({ onSelect, frameRate, startTimecode, + formatTimestamp, }) => { const message = initialMessage const hasDrawInfo = @@ -124,10 +126,14 @@ export const MessageCard: React.FC = ({ const { videoTimeDisplayMode } = useUiStore() const displayTime = React.useMemo(() => { - if (message.second === null || message.second === undefined || !frameRate) return '' + if (message.second === null || message.second === undefined) return '' + if (formatTimestamp) { + return formatTimestamp(message.second) + } + if (!frameRate) return '' const frameIndex = Math.round(message.second * frameRate) return formatTimecode(frameIndex, frameRate, videoTimeDisplayMode, startTimecode) - }, [message.second, frameRate, videoTimeDisplayMode, startTimecode]) + }, [message.second, frameRate, videoTimeDisplayMode, startTimecode, formatTimestamp]) const { data: me } = useQuery({ queryKey: ['teams', teamId, 'me'], diff --git a/packages/webui/components/chat/message-input.tsx b/packages/webui/components/chat/message-input.tsx index 4435d381..fe0309da 100644 --- a/packages/webui/components/chat/message-input.tsx +++ b/packages/webui/components/chat/message-input.tsx @@ -57,6 +57,7 @@ interface ChatInputProps { currentTime?: number frameRate?: number startTimecode?: string + formatTimestamp?: (second: number) => string onTyping?: () => void } @@ -88,6 +89,7 @@ export const ChatInput = React.forwardRef( currentTime, frameRate, startTimecode, + formatTimestamp, onTyping, }, ref, @@ -98,10 +100,14 @@ export const ChatInput = React.forwardRef( const { videoTimeDisplayMode } = useUiStore() const displayTime = React.useMemo(() => { - if (currentTime === undefined || !frameRate) return '' + if (currentTime === undefined) return '' + if (formatTimestamp) { + return formatTimestamp(currentTime) + } + if (!frameRate) return '' const frameIndex = Math.round(currentTime * frameRate) return formatTimecode(frameIndex, frameRate, videoTimeDisplayMode, startTimecode) - }, [currentTime, frameRate, videoTimeDisplayMode, startTimecode]) + }, [currentTime, frameRate, videoTimeDisplayMode, startTimecode, formatTimestamp]) const { teamId, ensureTeamIdForProject } = useTeamContextStore() const { members: storeMembers, loading: membersLoading, fetchMembers } = useMemberStore() @@ -135,7 +141,12 @@ export const ChatInput = React.forwardRef( const [hasContent, setHasContent] = useState(false) const paddingLeftClass = React.useMemo(() => { - if (!isTimestampEnabled || currentTime === undefined || !frameRate || hasContent) { + if ( + !isTimestampEnabled || + currentTime === undefined || + (!formatTimestamp && !frameRate) || + hasContent + ) { return '' } if (videoTimeDisplayMode === 'timecode') { diff --git a/packages/webui/components/file-viewer-right-sidebar.tsx b/packages/webui/components/file-viewer-right-sidebar.tsx index a1a36947..c9cfead1 100644 --- a/packages/webui/components/file-viewer-right-sidebar.tsx +++ b/packages/webui/components/file-viewer-right-sidebar.tsx @@ -355,6 +355,7 @@ export function FileViewerRightSidebar({ onReply={setReplyingTo} onViewAttachment={setViewingAttachment} hasReplies={!!comment.replies?.length} + formatTimestamp={viewerDef?.commentsConfig?.formatTimestamp} frameRate={ viewerDef?.commentsConfig?.hasTimestamp ? file?.media?.metadata?.frameRate || 30 @@ -381,6 +382,7 @@ export function FileViewerRightSidebar({ onViewAttachment={setViewingAttachment} hasReplies={false} isLastReply={index === (comment.replies?.length ?? 0) - 1} + formatTimestamp={viewerDef?.commentsConfig?.formatTimestamp} frameRate={ viewerDef?.commentsConfig?.hasTimestamp ? file?.media?.metadata?.frameRate || 30 @@ -419,6 +421,7 @@ export function FileViewerRightSidebar({ hideAnnotationControl={hideAnnotationControl} disableMentions={isPublic} currentTime={viewerDef?.commentsConfig?.hasTimestamp ? currentTime : undefined} + formatTimestamp={viewerDef?.commentsConfig?.formatTimestamp} frameRate={ viewerDef?.commentsConfig?.hasTimestamp ? file?.media?.metadata?.frameRate || 30 diff --git a/packages/webui/components/viewers/pdf/index.tsx b/packages/webui/components/viewers/pdf/index.tsx index c58ef0a2..6cab3f46 100644 --- a/packages/webui/components/viewers/pdf/index.tsx +++ b/packages/webui/components/viewers/pdf/index.tsx @@ -10,5 +10,6 @@ export const pdfTypeDefinition: FileTypeDefinition = { hasTimestamp: true, hasAnnotations: true, hasAiBots: true, + formatTimestamp: (second: number) => `P${Math.round(second)}`, }, } diff --git a/packages/webui/components/viewers/types.ts b/packages/webui/components/viewers/types.ts index 1137a0d2..d6471c2b 100644 --- a/packages/webui/components/viewers/types.ts +++ b/packages/webui/components/viewers/types.ts @@ -49,5 +49,6 @@ export interface FileTypeDefinition { hasTimestamp?: boolean hasAnnotations?: boolean hasAiBots?: boolean + formatTimestamp?: (second: number) => string } }