mirror of
https://github.com/shumaiOne/shumai.git
synced 2026-12-03 06:24:30 +00:00
fix(webui): move carousel hooks before early returns to satisfy React Hook rules
This commit is contained in:
@@ -30,6 +30,12 @@ function FileViewPage() {
|
|||||||
const [annotations, setAnnotations] = useState<Annotation[]>([])
|
const [annotations, setAnnotations] = useState<Annotation[]>([])
|
||||||
const [currentTime, setCurrentTime] = useState(0)
|
const [currentTime, setCurrentTime] = useState(0)
|
||||||
const [selectedCommentId, setSelectedCommentId] = useState<string | null>(null)
|
const [selectedCommentId, setSelectedCommentId] = useState<string | null>(null)
|
||||||
|
const [carouselState, setCarouselState] = useState<{
|
||||||
|
show: boolean
|
||||||
|
files: AssetInfo[]
|
||||||
|
nextCursor?: string
|
||||||
|
folderId?: string
|
||||||
|
}>({ show: false, files: [], nextCursor: undefined, folderId: undefined })
|
||||||
const $patchMetadata = client.api.files[':fileId'].metadata.$patch
|
const $patchMetadata = client.api.files[':fileId'].metadata.$patch
|
||||||
const { mutate: patchMetadata } = useMutation<
|
const { mutate: patchMetadata } = useMutation<
|
||||||
InferResponseType<typeof $patchMetadata>,
|
InferResponseType<typeof $patchMetadata>,
|
||||||
@@ -164,69 +170,11 @@ function FileViewPage() {
|
|||||||
navigate,
|
navigate,
|
||||||
])
|
])
|
||||||
|
|
||||||
if (isLoading && !fileData) {
|
|
||||||
return <FileDetailSkeleton />
|
|
||||||
}
|
|
||||||
|
|
||||||
if (isError || !fileData || !projectInfo || !teamId) {
|
|
||||||
return <div>File not found.</div>
|
|
||||||
}
|
|
||||||
|
|
||||||
const handleSaveField = (fieldId: string, value: unknown) => {
|
|
||||||
if (!teamId) return
|
|
||||||
patchMetadata(
|
|
||||||
{
|
|
||||||
param: { fileId: activeFileId },
|
|
||||||
json: [{ key: fieldId, value }] as InferRequestType<typeof $patchMetadata>['json'],
|
|
||||||
},
|
|
||||||
{
|
|
||||||
onSuccess: () => {
|
|
||||||
queryClient.invalidateQueries({
|
|
||||||
queryKey: ['files', activeFileId],
|
|
||||||
})
|
|
||||||
},
|
|
||||||
},
|
|
||||||
)
|
|
||||||
}
|
|
||||||
|
|
||||||
const handleCommentSelect = (comment: CommentInfo) => {
|
|
||||||
setSelectedCommentId(comment.id || null)
|
|
||||||
const newAnnotations = comment.annotations as Annotation[]
|
|
||||||
if (newAnnotations && newAnnotations.length > 0) {
|
|
||||||
setAnnotations(newAnnotations)
|
|
||||||
} else {
|
|
||||||
setAnnotations([])
|
|
||||||
}
|
|
||||||
|
|
||||||
if (comment.second !== null && comment.second !== undefined) {
|
|
||||||
if (videoRef.current) {
|
|
||||||
videoRef.current.currentTime(comment.second)
|
|
||||||
videoRef.current.pause()
|
|
||||||
}
|
|
||||||
} else if (newAnnotations && newAnnotations.length > 0) {
|
|
||||||
if (videoRef.current) {
|
|
||||||
videoRef.current.pause()
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
const handlePlay = () => {
|
|
||||||
setAnnotations([])
|
|
||||||
setSelectedCommentId(null)
|
|
||||||
}
|
|
||||||
|
|
||||||
const parentFolderId =
|
const parentFolderId =
|
||||||
fileData.ancestorFolders?.[fileData.ancestorFolders.length - 1]?.id ??
|
fileData?.ancestorFolders?.[fileData.ancestorFolders.length - 1]?.id ??
|
||||||
projectInfo.rootFolder ??
|
projectInfo?.rootFolder ??
|
||||||
''
|
''
|
||||||
|
|
||||||
const [carouselState, setCarouselState] = useState<{
|
|
||||||
show: boolean
|
|
||||||
files: AssetInfo[]
|
|
||||||
nextCursor?: string
|
|
||||||
folderId?: string
|
|
||||||
}>({ show: false, files: [], nextCursor: undefined, folderId: undefined })
|
|
||||||
|
|
||||||
useEffect(() => {
|
useEffect(() => {
|
||||||
if (!parentFolderId || !activeFileId) return
|
if (!parentFolderId || !activeFileId) return
|
||||||
if (carouselState.folderId === parentFolderId) {
|
if (carouselState.folderId === parentFolderId) {
|
||||||
@@ -308,6 +256,57 @@ function FileViewPage() {
|
|||||||
}
|
}
|
||||||
}, [parentFolderId, activeFileId, carouselState.folderId])
|
}, [parentFolderId, activeFileId, carouselState.folderId])
|
||||||
|
|
||||||
|
if (isLoading && !fileData) {
|
||||||
|
return <FileDetailSkeleton />
|
||||||
|
}
|
||||||
|
|
||||||
|
if (isError || !fileData || !projectInfo || !teamId) {
|
||||||
|
return <div>File not found.</div>
|
||||||
|
}
|
||||||
|
|
||||||
|
const handleSaveField = (fieldId: string, value: unknown) => {
|
||||||
|
if (!teamId) return
|
||||||
|
patchMetadata(
|
||||||
|
{
|
||||||
|
param: { fileId: activeFileId },
|
||||||
|
json: [{ key: fieldId, value }] as InferRequestType<typeof $patchMetadata>['json'],
|
||||||
|
},
|
||||||
|
{
|
||||||
|
onSuccess: () => {
|
||||||
|
queryClient.invalidateQueries({
|
||||||
|
queryKey: ['files', activeFileId],
|
||||||
|
})
|
||||||
|
},
|
||||||
|
},
|
||||||
|
)
|
||||||
|
}
|
||||||
|
|
||||||
|
const handleCommentSelect = (comment: CommentInfo) => {
|
||||||
|
setSelectedCommentId(comment.id || null)
|
||||||
|
const newAnnotations = comment.annotations as Annotation[]
|
||||||
|
if (newAnnotations && newAnnotations.length > 0) {
|
||||||
|
setAnnotations(newAnnotations)
|
||||||
|
} else {
|
||||||
|
setAnnotations([])
|
||||||
|
}
|
||||||
|
|
||||||
|
if (comment.second !== null && comment.second !== undefined) {
|
||||||
|
if (videoRef.current) {
|
||||||
|
videoRef.current.currentTime(comment.second)
|
||||||
|
videoRef.current.pause()
|
||||||
|
}
|
||||||
|
} else if (newAnnotations && newAnnotations.length > 0) {
|
||||||
|
if (videoRef.current) {
|
||||||
|
videoRef.current.pause()
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
const handlePlay = () => {
|
||||||
|
setAnnotations([])
|
||||||
|
setSelectedCommentId(null)
|
||||||
|
}
|
||||||
|
|
||||||
return (
|
return (
|
||||||
<div className="h-full flex flex-1 flex-col bg-background">
|
<div className="h-full flex flex-1 flex-col bg-background">
|
||||||
<div className="h-full flex flex-1 overflow-hidden">
|
<div className="h-full flex flex-1 overflow-hidden">
|
||||||
|
|||||||
Reference in New Issue
Block a user