Closed cwastche closed 3 months 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 15, 2024 2:03pm |
⏱️ Estimated effort to review [1-5] | 3 |
🧪 Relevant tests | No |
🔒 Security concerns | No |
⚡ Key issues to review |
Possible Bug: The refactoring in `useResources.tsx` changes the function `useGetOwnedEntityOnPosition` to `useOwnedEntitiesOnPosition`, which now returns a function rather than directly executing the logic. This change could potentially break existing functionality if not all usages have been updated accordingly. |
Code Clarity: The new functions `getOwnedEntitiesOnPosition` and `getOwnedEntityOnPosition` could benefit from more detailed comments explaining their purpose and the logic, especially given the complex query conditions and mapping. |
Category | Suggestion | Score |
Possible bug |
Add a guard clause to check for null or undefined
___
**Consider checking for the existence of | 9 |
Add a check to handle empty or undefined
___
**To ensure that the function | 8 | |
Maintainability |
Extract repeated logic into a separate function for better maintainability___ **Refactor the repeated logic for gettingposition and checking its existence into a separate function to improve code reusability and maintainability.** [client/src/hooks/helpers/useResources.tsx [247-249]](https://github.com/BibliothecaDAO/eternum/pull/946/files#diff-da868a5a06b096d28f8b0e970a0260a8d26d34f5acfafa3dcbd0156da8f15749R247-R249) ```diff -const position = getComponentValue(Position, entityId); -if (!position) return; -return position?.entity_id; +function getPositionEntityId(entityId: bigint): bigint | undefined { + const position = getComponentValue(Position, entityId); + if (!position) return undefined; + return position.entity_id; +} +return getPositionEntityId(entityId); ``` Suggestion importance[1-10]: 7Why: This refactoring improves code maintainability and reusability by encapsulating repeated logic into a separate function, making the code cleaner and easier to manage. | 7 |
Enhancement |
Utilize optional chaining to simplify the return statement___ **Use TypeScript's optional chaining to simplify the return statement in the mappingfunction, enhancing readability.** [client/src/hooks/helpers/useResources.tsx [249]](https://github.com/BibliothecaDAO/eternum/pull/946/files#diff-da868a5a06b096d28f8b0e970a0260a8d26d34f5acfafa3dcbd0156da8f15749R249-R249) ```diff +return position?.entity_id; - ``` Suggestion importance[1-10]: 6Why: Using optional chaining improves code readability and conciseness, although it is a minor enhancement compared to the other suggestions. | 6 |
User description
Closes #903
PR Type
Bug fix, Enhancement
Description
useGetOwnedEntityOnPosition
touseOwnedEntitiesOnPosition
inuseResources.tsx
.getOwnedEntitiesOnPosition
andgetOwnedEntityOnPosition
for better modularity.Entity.tsx
to use the new helper functions for determining entity state and deposit entity ID.Idle
andWaitingToOffload
based on the presence of resources and deposit entity ID.DepositResources
component is conditionally rendered based on the entity state inEntity.tsx
.DepositResources.tsx
.Changes walkthrough 📝
useResources.tsx
Refactor and enhance entity ownership retrieval functions.
client/src/hooks/helpers/useResources.tsx
useGetOwnedEntityOnPosition
touseOwnedEntitiesOnPosition
.getOwnedEntitiesOnPosition
andgetOwnedEntityOnPosition
.Entity.tsx
Update entity state display and resource deposit logic.
client/src/ui/components/entities/Entity.tsx
getOwnedEntityOnPosition
to determine deposit entity ID.Idle
andWaitingToOffload
.DepositResources
component based on entitystate.
DepositResources.tsx
Use new entity ownership retrieval in resource deposit.
client/src/ui/components/resources/DepositResources.tsx
useGetOwnedEntityOnPosition
withuseOwnedEntitiesOnPosition
.getOwnedEntityOnPosition
to fetch deposit entity ID.