From 720710dbbfebbf48913df85a7ef729784471602a Mon Sep 17 00:00:00 2001 From: yiling Date: Mon, 15 Jun 2026 15:39:10 +0800 Subject: [PATCH] fix(webui): move carousel hooks before early returns to satisfy React Hook rules --- .../projects/$projectId/files/$fileId.tsx | 119 +++++++++--------- 1 file changed, 59 insertions(+), 60 deletions(-) diff --git a/packages/webui/routes/projects/$projectId/files/$fileId.tsx b/packages/webui/routes/projects/$projectId/files/$fileId.tsx index 3278f4d4..480072b8 100644 --- a/packages/webui/routes/projects/$projectId/files/$fileId.tsx +++ b/packages/webui/routes/projects/$projectId/files/$fileId.tsx @@ -30,6 +30,12 @@ function FileViewPage() { const [annotations, setAnnotations] = useState([]) const [currentTime, setCurrentTime] = useState(0) const [selectedCommentId, setSelectedCommentId] = useState(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 { mutate: patchMetadata } = useMutation< InferResponseType, @@ -164,69 +170,11 @@ function FileViewPage() { navigate, ]) - if (isLoading && !fileData) { - return - } - - if (isError || !fileData || !projectInfo || !teamId) { - return
File not found.
- } - - const handleSaveField = (fieldId: string, value: unknown) => { - if (!teamId) return - patchMetadata( - { - param: { fileId: activeFileId }, - json: [{ key: fieldId, value }] as InferRequestType['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 = - fileData.ancestorFolders?.[fileData.ancestorFolders.length - 1]?.id ?? - projectInfo.rootFolder ?? + fileData?.ancestorFolders?.[fileData.ancestorFolders.length - 1]?.id ?? + projectInfo?.rootFolder ?? '' - const [carouselState, setCarouselState] = useState<{ - show: boolean - files: AssetInfo[] - nextCursor?: string - folderId?: string - }>({ show: false, files: [], nextCursor: undefined, folderId: undefined }) - useEffect(() => { if (!parentFolderId || !activeFileId) return if (carouselState.folderId === parentFolderId) { @@ -308,6 +256,57 @@ function FileViewPage() { } }, [parentFolderId, activeFileId, carouselState.folderId]) + if (isLoading && !fileData) { + return + } + + if (isError || !fileData || !projectInfo || !teamId) { + return
File not found.
+ } + + const handleSaveField = (fieldId: string, value: unknown) => { + if (!teamId) return + patchMetadata( + { + param: { fileId: activeFileId }, + json: [{ key: fieldId, value }] as InferRequestType['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 (