mirror of
https://github.com/shumaiOne/shumai.git
synced 2026-11-24 15:39:06 +00:00
feat(video): add timestamp support to comments
This commit is contained in:
@@ -11,12 +11,13 @@ import {
|
||||
} from '@/ui/components/ui/dialog'
|
||||
import { Separator } from '@/ui/components/ui/separator'
|
||||
import { useQuery } from '@tanstack/react-query'
|
||||
import { Download, File, Terminal } from 'lucide-react'
|
||||
import { Download, File, Terminal, Clock } from 'lucide-react'
|
||||
import React from 'react'
|
||||
import { formatTimeAgo } from '@/ui/lib/time'
|
||||
import Markdown from 'react-markdown'
|
||||
import { Avatar, AvatarFallback } from '../ui/avatar'
|
||||
import { Skeleton } from '../ui/skeleton'
|
||||
import { formatTimestamp } from '../viewers/utils'
|
||||
|
||||
interface MessageCardProps {
|
||||
teamId?: string
|
||||
@@ -27,6 +28,8 @@ interface MessageCardProps {
|
||||
getUser: (id: string) => UserInfo
|
||||
onReply: (message: CommentInfo) => void
|
||||
onViewAttachment: (attachment: AttachmentInfo) => void
|
||||
onTimestampClick?: (seconds: number) => void
|
||||
frameRate?: number
|
||||
rootParentId?: string
|
||||
}
|
||||
|
||||
@@ -48,6 +51,8 @@ export const MessageCard: React.FC<MessageCardProps> = ({
|
||||
getUser,
|
||||
onReply,
|
||||
onViewAttachment,
|
||||
onTimestampClick,
|
||||
frameRate,
|
||||
}) => {
|
||||
const isRunning =
|
||||
!!initialMessage.sessionId &&
|
||||
@@ -153,6 +158,18 @@ export const MessageCard: React.FC<MessageCardProps> = ({
|
||||
<div className="flex-1 min-w-0">
|
||||
<div className="flex items-center gap-2 mb-1">
|
||||
<span className="font-semibold text-sm">{creator?.name || 'Unknown'}</span>
|
||||
{message.second !== null && message.second !== undefined && frameRate && (
|
||||
<button
|
||||
onClick={(e) => {
|
||||
e.stopPropagation()
|
||||
onTimestampClick?.(message.second!)
|
||||
}}
|
||||
className="bg-blue-100 dark:bg-blue-900/40 text-blue-600 dark:text-blue-300 px-2 py-0.5 rounded-full text-[10px] font-mono font-bold flex items-center gap-1 border border-blue-200 dark:border-blue-800 shadow-sm hover:bg-blue-200 dark:hover:bg-blue-900/60 transition-colors"
|
||||
>
|
||||
<Clock className="w-2.5 h-2.5" />
|
||||
{formatTimestamp(message.second, frameRate)}
|
||||
</button>
|
||||
)}
|
||||
<span className="text-xs text-gray-400">
|
||||
{new Date(message.createdAt!).toLocaleTimeString([], {
|
||||
hour: '2-digit',
|
||||
|
||||
@@ -8,6 +8,7 @@ import {
|
||||
ArrowUp,
|
||||
Brush,
|
||||
ChevronDown,
|
||||
Clock,
|
||||
FileIcon,
|
||||
Minus,
|
||||
Paperclip,
|
||||
@@ -24,6 +25,7 @@ import { Popover, PopoverContent, PopoverTrigger } from '../ui/popover'
|
||||
import { useAnnotationStore } from '@/ui/stores/annotation-store'
|
||||
import type { Annotation } from '@/ui/types'
|
||||
import { useMutation } from '@tanstack/react-query'
|
||||
import { formatTimestamp } from '../viewers/utils'
|
||||
|
||||
type UploadingFile = {
|
||||
id: string // A unique ID for the file, e.g., timestamp + name
|
||||
@@ -40,6 +42,7 @@ interface ChatInputProps {
|
||||
attachmentIds: string[],
|
||||
annotations?: Annotation[],
|
||||
replyToId?: string | null,
|
||||
second?: number | null,
|
||||
) => void
|
||||
replyingTo?: CommentInfo | null
|
||||
onCancelReply?: () => void
|
||||
@@ -48,6 +51,8 @@ interface ChatInputProps {
|
||||
initialText?: string
|
||||
hideAnnotationControl?: boolean
|
||||
disableMentions?: boolean
|
||||
currentTime?: number
|
||||
frameRate?: number
|
||||
}
|
||||
|
||||
const PREDEFINED_COLORS = [
|
||||
@@ -76,11 +81,14 @@ export const ChatInput = React.forwardRef<HTMLDivElement, ChatInputProps>(
|
||||
initialText = '',
|
||||
hideAnnotationControl = false,
|
||||
disableMentions = false,
|
||||
currentTime,
|
||||
frameRate,
|
||||
},
|
||||
ref,
|
||||
) => {
|
||||
const [uploadingFiles, setUploadingFiles] = useState<UploadingFile[]>([])
|
||||
const [viewingFile, setViewingFile] = useState<File | null>(null)
|
||||
const [isTimestampEnabled, setIsTimestampEnabled] = useState(true)
|
||||
|
||||
// Annotation Store
|
||||
const {
|
||||
@@ -395,7 +403,13 @@ export const ChatInput = React.forwardRef<HTMLDivElement, ChatInputProps>(
|
||||
// Allow sending if annotations exist, even if text is empty
|
||||
if (!processedText && successfulAttachmentIds.length === 0 && annotations.length === 0) return
|
||||
|
||||
onSendMessage(processedText, successfulAttachmentIds, annotations, replyingTo?.id)
|
||||
onSendMessage(
|
||||
processedText,
|
||||
successfulAttachmentIds,
|
||||
annotations,
|
||||
replyingTo?.id,
|
||||
isTimestampEnabled ? currentTime : undefined,
|
||||
)
|
||||
|
||||
// Reset editor
|
||||
editorRef.current.innerHTML = ''
|
||||
@@ -566,6 +580,15 @@ export const ChatInput = React.forwardRef<HTMLDivElement, ChatInputProps>(
|
||||
</div>
|
||||
)}
|
||||
|
||||
{isTimestampEnabled && currentTime !== undefined && frameRate !== undefined && (
|
||||
<div className="px-4 pt-3 flex">
|
||||
<div className="bg-blue-100 dark:bg-blue-900/40 text-blue-600 dark:text-blue-300 px-3 py-1 rounded-full text-xs font-mono font-bold flex items-center gap-1.5 border border-blue-200 dark:border-blue-800 shadow-sm animate-in fade-in zoom-in duration-200">
|
||||
<Clock className="w-3 h-3" />
|
||||
{formatTimestamp(currentTime, frameRate)}
|
||||
</div>
|
||||
</div>
|
||||
)}
|
||||
|
||||
<div className="w-full px-4 pt-1 pb-1">
|
||||
<div
|
||||
ref={editorRef}
|
||||
@@ -679,6 +702,15 @@ export const ChatInput = React.forwardRef<HTMLDivElement, ChatInputProps>(
|
||||
multiple
|
||||
onChange={handleFileSelect}
|
||||
/>
|
||||
<Button
|
||||
onClick={() => setIsTimestampEnabled(!isTimestampEnabled)}
|
||||
variant={isTimestampEnabled ? 'secondary' : 'ghost'}
|
||||
size="icon"
|
||||
className={`p-2 rounded-full cursor-pointer ${isTimestampEnabled ? 'text-blue-600 bg-blue-50 dark:bg-blue-900/20' : ''}`}
|
||||
title={isTimestampEnabled ? 'Disable Timestamp' : 'Enable Timestamp'}
|
||||
>
|
||||
<Clock className="w-4 h-4" />
|
||||
</Button>
|
||||
<Button
|
||||
onClick={() => fileInputRef.current?.click()}
|
||||
className="p-2 rounded-full cursor-pointer"
|
||||
|
||||
Reference in New Issue
Block a user