From ae7f33c48542cfdc3a79d47c9feb647de4a207ae Mon Sep 17 00:00:00 2001 From: Vishnu Date: Thu, 22 May 2025 15:58:09 +0530 Subject: [PATCH] refactor: rearrange early return for better readability in CommentInstance --- .../instances/commentInstance/commentInstance.tsx | 9 +++++---- 1 file changed, 5 insertions(+), 4 deletions(-) diff --git a/app/src/modules/collaboration/comments/instances/commentInstance/commentInstance.tsx b/app/src/modules/collaboration/comments/instances/commentInstance/commentInstance.tsx index 42655bb..5b5c145 100644 --- a/app/src/modules/collaboration/comments/instances/commentInstance/commentInstance.tsx +++ b/app/src/modules/collaboration/comments/instances/commentInstance/commentInstance.tsx @@ -10,8 +10,7 @@ function CommentInstance({ comment }: { comment: CommentSchema }) { const [selectedComment, setSelectedComment] = useState(null); const [transformMode, setTransformMode] = useState<"translate" | "rotate" | null>(null); - if (comment.state === 'inactive' || isPlaying) return null; - + useEffect(() => { const handleKeyDown = (e: KeyboardEvent) => { const keyCombination = detectModifierKeys(e); @@ -23,11 +22,13 @@ function CommentInstance({ comment }: { comment: CommentSchema }) { setTransformMode((prev) => (prev === "rotate" ? null : "rotate")); } }; - + window.addEventListener("keydown", handleKeyDown); return () => window.removeEventListener("keydown", handleKeyDown); }, [selectedComment]); - + + if (comment.state === 'inactive' || isPlaying) return null; + return ( <>