Closed cwastche 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 11:46am |
โฑ๏ธ Estimated effort to review [1-5] | 4 |
๐งช Relevant tests | No |
๐ Security concerns | No |
โก Key issues to review |
Possible Bug: The removal of the useQuests hook and its replacement with useQuestStore might lead to issues if other parts of the application still depend on the old hook. It's crucial to ensure that all references to useQuests are updated. |
Refactoring Scope: The refactoring of the HintModal to include an initial active section prop could affect how modals are displayed across the application. Verify that this change does not disrupt the modal behavior in other components. | |
Performance Concern: The new Zustand store implementation in useQuestStore.tsx introduces more complex state management which could impact performance. Review the usage of Zustand and ensure it's optimized for frequent updates and re-renders. |
Category | Suggestion | Score |
Possible bug |
Ensure
___
**To avoid potential type coercion errors with the | 10 |
Improve the safety of accessing properties on potentially undefined objects___ **Consider checking ifselectedEntityId is defined before attempting to access its id property to avoid potential runtime errors. You can use optional chaining ( ?. ) for safer access.** [client/src/ui/modules/navigation/BottomNavigation.tsx [46]](https://github.com/BibliothecaDAO/eternum/pull/975/files#diff-e88ab2bf26cead1655ae59538674a03ae7a573c4c6ea347a8ad382f197b3cc4dR46-R46) ```diff -const army = getArmyByEntityId(selectedEntityId?.id || BigInt("0")); +const army = getArmyByEntityId(selectedEntityId?.id ?? BigInt("0")); ``` Suggestion importance[1-10]: 8Why: The suggestion improves the safety of accessing properties on potentially undefined objects, which can prevent runtime errors. | 8 | |
Performance |
Add a | 9 |
Improve the definition of
___
**To ensure that the | 9 | |
Move
___
**The function | 8 | |
Improve the stability and efficiency of useMemo by using a stable hash of the account object___ **Consider using a more robust key extraction method foruseMemo to avoid unnecessary recalculations. The current dependencies list includes account.address which might not be stable across re-renders. Using a stable hash of the account object or specific stable properties might be more efficient.** [client/src/hooks/store/useQuestStore.tsx [150]](https://github.com/BibliothecaDAO/eternum/pull/975/files#diff-a7c36ca377844946d158e339e652e7588b89111d70276c01cf716ce0dea0c9daR150-R150) ```diff -useMemo(() => {...}, [farms, resource, orders, entityArmies, HasClaimedStartingResources, entityId, account.address]); +useMemo(() => {...}, [farms, resource, orders, entityArmies, HasClaimedStartingResources, entityId, JSON.stringify(account)]); ``` Suggestion importance[1-10]: 7Why: This suggestion improves the stability and efficiency of the `useMemo` hook by using a stable hash of the account object, which can prevent unnecessary recalculations. However, the improvement is minor and does not address a critical issue. | 7 | |
Optimize performance by avoiding repeated BigInt instantiation___ **Avoid usingBigInt("0") as a fallback value directly inside the component render. Instead, define a constant outside of the component to prevent creating a new BigInt on every render.** [client/src/ui/modules/navigation/BottomNavigation.tsx [46]](https://github.com/BibliothecaDAO/eternum/pull/975/files#diff-e88ab2bf26cead1655ae59538674a03ae7a573c4c6ea347a8ad382f197b3cc4dR46-R46) ```diff -const army = getArmyByEntityId(selectedEntityId?.id || BigInt("0")); +const DEFAULT_ENTITY_ID = BigInt("0"); +const army = getArmyByEntityId(selectedEntityId?.id || DEFAULT_ENTITY_ID); ``` Suggestion importance[1-10]: 7Why: The suggestion optimizes performance by avoiding repeated BigInt instantiation, which is a good practice for improving efficiency. | 7 | |
Simplify the initialization of
___
**Initialize the | 6 | |
Best practice |
Add missing dependencies to useEffect to ensure it updates correctly___ **Refactor theuseEffect hook at line 152 to include quests in its dependencies array. This ensures that the effect correctly responds to changes in quests , aligning with React's best practices for effects that depend on props or state.** [client/src/hooks/store/useQuestStore.tsx [152-154]](https://github.com/BibliothecaDAO/eternum/pull/975/files#diff-a7c36ca377844946d158e339e652e7588b89111d70276c01cf716ce0dea0c9daR152-R154) ```diff useEffect(() => { setQuests(quests); -}, []); +}, [quests]); ``` Suggestion importance[1-10]: 9Why: Adding `quests` to the dependencies array of the `useEffect` hook ensures that the effect updates correctly when `quests` change, aligning with React's best practices. This is crucial for the correct functioning of the component. | 9 |
Ensure useMemo dependencies are correctly specified for accurate updates___ **TheuseMemo hook for isWorldView is missing its dependencies. Include location in the dependency array to ensure it updates correctly when location changes.**
[client/src/ui/modules/navigation/BottomNavigation.tsx [42]](https://github.com/BibliothecaDAO/eternum/pull/975/files#diff-e88ab2bf26cead1655ae59538674a03ae7a573c4c6ea347a8ad382f197b3cc4dR42-R42)
```diff
+const isWorldView = useMemo(() => location === "/map", [location]);
-
```
Suggestion importance[1-10]: 9Why: The suggestion correctly identifies a missing dependency in the `useMemo` hook, ensuring that the memoized value updates accurately when `location` changes. | 9 | |
Use type assertion instead of
___
**Avoid using | 8 | |
Replace array indexes with unique identifiers as keys in React list items___ **It is recommended to avoid using indexes as keys in React lists if the order of items maychange, as it could lead to performance issues and bugs. Use a unique identifier if available.** [client/src/ui/modules/navigation/RightNavigationModule.tsx [178-180]](https://github.com/BibliothecaDAO/eternum/pull/975/files#diff-8b98807e05dc7525757f9d43f5a3b1a081305f54aa3be0d5be4b2a130160bd0cR178-R180) ```diff -{navigation.map((a, index) => ( - {a.button}
+{navigation.map((navItem) => (
+ {navItem.button}
))}
```
Suggestion importance[1-10]: 8Why: Using unique identifiers instead of array indexes as keys in React list items is a best practice that helps prevent potential performance issues and bugs related to reordering of items. | 8 | |
Improve type safety by using a more specific type for the
___
**Consider using a more specific type for the | 7 | |
Maintainability |
Use more descriptive variable names to enhance code readability___ **Consider using a more descriptive variable name thana for the map function in the navigation array to improve code readability.**
[client/src/ui/modules/navigation/RightNavigationModule.tsx [178-180]](https://github.com/BibliothecaDAO/eternum/pull/975/files#diff-8b98807e05dc7525757f9d43f5a3b1a081305f54aa3be0d5be4b2a130160bd0cR178-R180)
```diff
-{navigation.map((a, index) => (
- {a.button}
+{navigation.map((navItem, index) => (
+ {navItem.button}
))}
```
Suggestion importance[1-10]: 7Why: Using a more descriptive variable name enhances code readability and maintainability, making it easier for other developers to understand the code. | 7 |
Enhancement |
Simplify class application by directly using conditional expressions instead of
___
**The | 6 |
User description
PR Type
Enhancement, Bug fix, Documentation
Description
useQuestStore
using Zustand for state management.useQuests
hook and replaced it with the new store-based approach.Changes walkthrough ๐
19 files
useQuestStore.tsx
Implement Zustand-based Quest Store and Hook
client/src/hooks/store/useQuestStore.tsx
useQuestStore
using Zustand for state management.useQuests
hook to manage quest logic and state.useQuests.tsx
Remove Deprecated useQuests Hook
client/src/hooks/helpers/useQuests.tsx - Removed the old `useQuests` hook.
useUIStore.tsx
Extend UI Store for Navigation Views
client/src/hooks/store/useUIStore.tsx
main.tsx
Enable TourProvider with Empty Steps
client/src/main.tsx - Enabled the `TourProvider` with empty steps.
HooksComponent.tsx
Integrate useQuests Hook in HooksComponent
client/src/ui/components/HooksComponent.tsx - Added `useQuests` hook to the component.
SelectPreviewBuilding.tsx
Add Quest Visual Cues and Hint Button
client/src/ui/components/construction/SelectPreviewBuilding.tsx
HintBox.tsx
Update HintBox to Use Quest Store and Display Steps
client/src/ui/components/hints/HintBox.tsx
useQuestStore
.HintModal.tsx
Refactor HintModal and Extract Resources Component
client/src/ui/components/hints/HintModal.tsx
Resources.tsx
Create Resources Component
client/src/ui/components/hints/Resources.tsx - Created a new Resources component.
EntityList.tsx
Add Questing Visual Cue to Entity List
client/src/ui/components/list/EntityList.tsx - Added questing visual cue to entity list items.
ArmyList.tsx
Add Quest Visual Cues to Army List
client/src/ui/components/military/ArmyList.tsx - Added quest-related visual cues to army creation and enlistment.
MarketModal.tsx
Add Hint Button to Market Modal
client/src/ui/components/trading/MarketModal.tsx - Added hint button to open the hint modal.
LeaderboardPanel.tsx
Add Hint Button to Leaderboard Panel
client/src/ui/components/worldmap/leaderboard/LeaderboardPanel.tsx - Added hint button to open the hint modal.
Military.tsx
Add Hint Button to Military Module
client/src/ui/modules/military/Military.tsx - Added hint button to open the hint modal.
BottomNavigation.tsx
Add Quest Visual Cues and Update Notifications
client/src/ui/modules/navigation/BottomNavigation.tsx
LeftNavigationModule.tsx
Add Quest Visual Cues and Update Navigation Visibility
client/src/ui/modules/navigation/LeftNavigationModule.tsx
RightNavigationModule.tsx
Add Quest Visual Cues and Update Navigation Visibility
client/src/ui/modules/navigation/RightNavigationModule.tsx
TopMiddleNavigation.tsx
Disable Navigation Button When Quests Are Claimable
client/src/ui/modules/navigation/TopMiddleNavigation.tsx - Disabled navigation button when quests are claimable.
Steps.tsx
Remove Deprecated Quest Logic from Onboarding Steps
client/src/ui/modules/onboarding/Steps.tsx - Removed old quest-related logic.