Closed aymericdelab closed 2 weeks ago
The latest updates on your projects. Learn more about Vercel for Git โ๏ธ
Name | Status | Preview | Comments | Updated (UTC) |
---|---|---|---|---|
eternum | โ Ready (Inspect) | Visit Preview | ๐ฌ Add feedback | Jun 21, 2024 6:10pm |
โฑ๏ธ Estimated effort to review [1-5] | 3 |
๐งช Relevant tests | No |
๐ Security concerns | No |
โก Key issues to review |
Possible Bug: The useEffect hook in useArmyAnimation uses position.x and position.y in its dependency array, but it also accesses position directly inside the hook. This could lead to inconsistencies if position is updated in a way that does not change x or y . It would be safer to destructure position at the start of the hook and use only the destructured values throughout. |
Code Duplication: The ArmySelectionOverlay component seems to duplicate some logic related to entity selection and combat label visibility that might be better centralized or abstracted to reduce redundancy and improve maintainability. |
Category | Suggestion | Score |
Best practice |
Add a cleanup function in
___
**It's recommended to use a cleanup function in the | 9 |
Use a more specific event type in callbacks to enhance type safety___ **Consider using a more specific type thanany for the event parameter in the onPointerEnter and onPointerOut callbacks to improve type safety and take advantage of TypeScript's static type checking.** [client/src/ui/components/worldmap/armies/ArmyHitBox.tsx [40-53]](https://github.com/BibliothecaDAO/eternum/pull/981/files#diff-2dd1c84f2d9bb67d297d72c8c18345fa06b591e9f2ab0eae41c55f09407d7a35R40-R53) ```diff const onPointerEnter = useCallback( - (e: any) => { + (e: React.MouseEvent) => { e.stopPropagation(); if (!isAnimating) setHovered(true); }, [isAnimating], ); const onPointerOut = useCallback( - (e: any) => { + (e: React.MouseEvent) => { e.stopPropagation(); if (!isAnimating) setHovered(false); }, [isAnimating], ); ``` Suggestion importance[1-10]: 6Why: Using a more specific event type improves type safety and leverages TypeScript's static type checking. This is a minor improvement but contributes to better code quality. | 6 | |
Possible issue |
Add a check for
___
**Consider adding a check for | 8 |
Maintainability |
Refactor hover event handlers into a single function to improve code maintainability___ **Refactor theonPointerEnter and onPointerOut callbacks to a single function to toggle the hovered state based on the event type. This reduces redundancy and improves maintainability.** [client/src/ui/components/worldmap/armies/ArmyHitBox.tsx [40-53]](https://github.com/BibliothecaDAO/eternum/pull/981/files#diff-2dd1c84f2d9bb67d297d72c8c18345fa06b591e9f2ab0eae41c55f09407d7a35R40-R53) ```diff -const onPointerEnter = useCallback( - (e: any) => { +const toggleHover = useCallback( + (e: any, entering: boolean) => { e.stopPropagation(); - if (!isAnimating) setHovered(true); - }, - [isAnimating], -); -const onPointerOut = useCallback( - (e: any) => { - e.stopPropagation(); - if (!isAnimating) setHovered(false); + if (!isAnimating) setHovered(entering); }, [isAnimating], ); ``` Suggestion importance[1-10]: 7Why: The suggestion to refactor the hover event handlers into a single function reduces redundancy and improves maintainability. While not critical, it is a good practice for cleaner and more maintainable code. | 7 |
User description
-> avoid unnecessary rerenders of armies on world map -> prevent from selecting army if moving
PR Type
Bug fix, Enhancement
Description
isAnimating
prop toWarriorModel
andArmyHitBox
components to prevent interactions during animations.Army
component to useisAnimating
state and moved selection and combat label logic to a newArmySelectionOverlay
component.useArmyAnimation
hook to track animation state usingisAnimatingRef
.Changes walkthrough ๐
WarriorModel.tsx
Add `isAnimating` prop to WarriorModel component.
client/src/ui/components/models/armies/WarriorModel.tsx
isAnimating
prop toWarriorModel
component.isAnimating
prop toArmyHitBox
component.Army.tsx
Refactor Army component and add ArmySelectionOverlay.
client/src/ui/components/worldmap/armies/Army.tsx
Army
component to useisAnimating
state.ArmySelectionOverlay
component.
isAnimating
prop toWarriorModel
component.ArmyHitBox.tsx
Add `isAnimating` prop to ArmyHitBox component.
client/src/ui/components/worldmap/armies/ArmyHitBox.tsx
isAnimating
prop toArmyHitBox
component.isAnimating
state.useArmyAnimation.tsx
Track animation state with isAnimatingRef in useArmyAnimation.
client/src/ui/components/worldmap/armies/useArmyAnimation.tsx
isAnimatingRef
to track animation state.isAnimatingRef
appropriately.