Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

sync armies fix #2585

Merged
merged 1 commit into from
Dec 22, 2024
Merged

sync armies fix #2585

merged 1 commit into from
Dec 22, 2024

Conversation

aymericdelab
Copy link
Collaborator

@aymericdelab aymericdelab commented Dec 22, 2024

Summary by CodeRabbit

  • New Features

    • Enhanced loading state management with the introduction of a new loading state for "Donkeys and Armies".
    • Updated entity fetching logic to include new models related to "Donkeys and Armies".
  • Bug Fixes

    • Corrected references in loading states to ensure accurate tracking and display.
  • Refactor

    • Renamed subscription functions and loading state keys for clarity and consistency across the application.

Copy link

vercel bot commented Dec 22, 2024

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 Dec 22, 2024 9:44pm
eternum-docs ✅ Ready (Inspect) Visit Preview 💬 Add feedback Dec 22, 2024 9:44pm
1 Skipped Deployment
Name Status Preview Comments Updated (UTC)
eternum-landing ⬜️ Ignored (Inspect) Visit Preview Dec 22, 2024 9:44pm

Copy link
Contributor

coderabbitai bot commented Dec 22, 2024

Walkthrough

This pull request focuses on renaming and updating various functions and loading states related to resource and entity management across multiple files in the client source code. The changes primarily involve replacing "Arrivals" with "DonkeysAndArmies" in function names, loading state keys, and related references. The modifications span several TypeScript files, including debouncedQueries.ts, queries.ts, useWorldLoading.tsx, WorldLoading.tsx, and World.tsx, ensuring consistent naming and updating the subscription and loading state mechanisms.

Changes

File Change Summary
client/src/dojo/debouncedQueries.ts Renamed debounceAddResourceArrivals to debounceAddDonkeysAndArmiesSubscription
client/src/dojo/queries.ts Renamed addArrivalsSubscription to addDonkeysAndArmiesSubscription, updated entity query logic
client/src/hooks/store/useWorldLoading.tsx Replaced LoadingStateKey.Arrivals with LoadingStateKey.DonkeysAndArmies
client/src/ui/components/WorldLoading.tsx Updated loading state condition from Arrivals to DonkeysAndArmies
client/src/ui/layouts/World.tsx Renamed function call and loading state key from Arrivals to DonkeysAndArmies

Possibly related PRs

Suggested reviewers

  • ponderingdemocritus

Poem

🐰 Hop, hop, through the code we leap,
Renaming functions, no time to sleep!
From Arrivals to Donkeys we dance,
A rabbit's refactor, a coding romance! 🌟
Subscriptions renamed with glee and might,
Our changes bring clarity, oh so bright! 🚀

Tip

CodeRabbit's docstrings feature is now available as part of our Early Access Program! Simply use the command @coderabbitai generate docstrings to have CodeRabbit automatically generate docstrings for your pull request. We would love to hear your feedback on Discord.


Thank you for using CodeRabbit. We offer it for free to the OSS community and would appreciate your support in helping us grow. If you find it useful, would you consider giving us a shout-out on your favorite social media?

❤️ Share
🪧 Tips

Chat

There are 3 ways to chat with CodeRabbit:

  • Review comments: Directly reply to a review comment made by CodeRabbit. Example:
    • I pushed a fix in commit <commit_id>, please review it.
    • Generate unit testing code for this file.
    • Open a follow-up GitHub issue for this discussion.
  • Files and specific lines of code (under the "Files changed" tab): Tag @coderabbitai in a new review comment at the desired location with your query. Examples:
    • @coderabbitai generate unit testing code for this file.
    • @coderabbitai modularize this function.
  • PR comments: Tag @coderabbitai in a new PR comment to ask questions about the PR branch. For the best results, please provide a very specific query, as very limited context is provided in this mode. Examples:
    • @coderabbitai gather interesting stats about this repository and render them as a table. Additionally, render a pie chart showing the language distribution in the codebase.
    • @coderabbitai read src/utils.ts and generate unit testing code.
    • @coderabbitai read the files in the src/scheduler package and generate a class diagram using mermaid and a README in the markdown format.
    • @coderabbitai help me debug CodeRabbit configuration file.

Note: Be mindful of the bot's finite context window. It's strongly recommended to break down tasks such as reading entire modules into smaller chunks. For a focused discussion, use review comments to chat about specific files and their changes, instead of using the PR comments.

CodeRabbit Commands (Invoked using PR comments)

  • @coderabbitai pause to pause the reviews on a PR.
  • @coderabbitai resume to resume the paused reviews.
  • @coderabbitai review to trigger an incremental review. This is useful when automatic reviews are disabled for the repository.
  • @coderabbitai full review to do a full review from scratch and review all the files again.
  • @coderabbitai summary to regenerate the summary of the PR.
  • @coderabbitai generate docstrings to generate docstrings for this PR. (Beta)
  • @coderabbitai resolve resolve all the CodeRabbit review comments.
  • @coderabbitai configuration to show the current CodeRabbit configuration for the repository.
  • @coderabbitai help to get help.

Other keywords and placeholders

  • Add @coderabbitai ignore anywhere in the PR description to prevent this PR from being reviewed.
  • Add @coderabbitai summary to generate the high-level summary at a specific location in the PR description.
  • Add @coderabbitai anywhere in the PR title to generate the title automatically.

CodeRabbit Configuration File (.coderabbit.yaml)

  • You can programmatically configure CodeRabbit by adding a .coderabbit.yaml file to the root of your repository.
  • Please see the configuration documentation for more information.
  • If your editor has YAML language server enabled, you can add the path at the top of this file to enable auto-completion and validation: # yaml-language-server: $schema=https://coderabbit.ai/integrations/schema.v2.json

Documentation and Community

  • Visit our Documentation for detailed information on how to use CodeRabbit.
  • Join our Discord Community to get help, request features, and share feedback.
  • Follow us on X/Twitter for updates and announcements.

Copy link
Contributor

mentatbot bot commented Dec 22, 2024

You are out of MentatBot reviews. Your usage will refresh December 23 at 08:00 AM.

Copy link

Failed to generate code suggestions for PR

Copy link
Contributor

@coderabbitai coderabbitai bot left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Actionable comments posted: 1

🧹 Nitpick comments (2)
client/src/dojo/queries.ts (1)

Line range hint 194-234: LGTM! The refactored query structure and additional models enhance entity tracking.

The changes improve the subscription mechanism by:

  • Using precise Member queries for entity ownership
  • Adding models for health, protection, and quantity tracking
  • Including performance monitoring

Consider adding error handling for the case when the query times out after 1000ms. This could help prevent silent failures and improve debugging.

client/src/ui/layouts/World.tsx (1)

167-167: Consider improving loading state management to prevent race conditions.

While the loading state updates are functionally correct, there's a potential race condition where multiple async operations could interfere with each other's loading states.

Consider using a more robust loading state management approach:

-      setLoading(LoadingStateKey.DonkeysAndArmies, true);
+      const loadingId = Date.now();
+      setLoading(LoadingStateKey.DonkeysAndArmies, true, loadingId);

       await debounceAddDonkeysAndArmiesSubscription(
         dojo.network.toriiClient,
         dojo.network.contractComponents as any,
         [...structures.map((structure) => structure.entity_id)],
-        () => setLoading(LoadingStateKey.DonkeysAndArmies, false),
+        () => setLoading(LoadingStateKey.DonkeysAndArmies, false, loadingId),
       );

This ensures that only the most recent loading state update is applied.

Also applies to: 189-193

📜 Review details

Configuration used: CodeRabbit UI
Review profile: CHILL
Plan: Pro

📥 Commits

Reviewing files that changed from the base of the PR and between 14042d0 and 709d2ff.

📒 Files selected for processing (5)
  • client/src/dojo/debouncedQueries.ts (2 hunks)
  • client/src/dojo/queries.ts (2 hunks)
  • client/src/hooks/store/useWorldLoading.tsx (2 hunks)
  • client/src/ui/components/WorldLoading.tsx (1 hunks)
  • client/src/ui/layouts/World.tsx (3 hunks)
🔇 Additional comments (4)
client/src/hooks/store/useWorldLoading.tsx (1)

10-10: Verify all references to LoadingStateKey.Arrivals have been updated

The enum value change from Arrivals to DonkeysAndArmies looks good, but we should ensure all references are updated.

Also applies to: 35-35

✅ Verification successful

All references to LoadingStateKey have been properly updated

All occurrences of the enum value have been consistently updated to LoadingStateKey.DonkeysAndArmies across the codebase:

  • client/src/hooks/store/useWorldLoading.tsx: Updated in the initial loadingStates
  • client/src/ui/layouts/World.tsx: Updated in loading state management
  • client/src/ui/components/WorldLoading.tsx: Updated in the loading items display
🏁 Scripts executed

The following scripts were executed for the analysis:

Script:

#!/bin/bash
# Search for any remaining references to LoadingStateKey.Arrivals
rg -l "LoadingStateKey\.Arrivals" 

# Search for new references to LoadingStateKey.DonkeysAndArmies to confirm adoption
rg -l "LoadingStateKey\.DonkeysAndArmies"

Length of output: 196


Script:

#!/bin/bash
# Let's check the actual content of these files to see how the enum is used
rg "LoadingStateKey\.(Arrivals|DonkeysAndArmies)" -A 2 -B 2

Length of output: 1853

client/src/ui/components/WorldLoading.tsx (1)

15-15: LGTM! Loading message is now more descriptive

The loading state check has been updated to use LoadingStateKey.DonkeysAndArmies and the display text "Donkeys and Armies" provides better clarity about what's being loaded.

client/src/dojo/debouncedQueries.ts (1)

5-5: Verify the subscription function renaming

The renaming from addArrivalsSubscription to addDonkeysAndArmiesSubscription looks good, but we should ensure all usages are updated.

Also applies to: 106-114

✅ Verification successful

Function renaming has been properly implemented

All references to the old function names (addArrivalsSubscription and debounceAddResourceArrivals) have been completely replaced with the new names (addDonkeysAndArmiesSubscription and debounceAddDonkeysAndArmiesSubscription). The changes are consistent across all relevant files:

  • client/src/dojo/debouncedQueries.ts: Exports and implements both functions
  • client/src/dojo/queries.ts: Implements the base subscription function
  • client/src/ui/layouts/World.tsx: Uses the debounced version correctly
🏁 Scripts executed

The following scripts were executed for the analysis:

Script:

#!/bin/bash
# Search for any remaining references to the old function names
rg -l "addArrivalsSubscription|debounceAddResourceArrivals"

# Search for new function names to confirm adoption
rg -l "addDonkeysAndArmiesSubscription|debounceAddDonkeysAndArmiesSubscription"

Length of output: 238


Script:

#!/bin/bash
# Let's check the actual content of these files to verify the usage
rg "addArrivalsSubscription|debounceAddResourceArrivals|addDonkeysAndArmiesSubscription|debounceAddDonkeysAndArmiesSubscription" -A 2 -B 2

Length of output: 2012

client/src/ui/layouts/World.tsx (1)

7-7: LGTM! Import statement correctly updated.

The import statement has been properly updated to reflect the renamed function.

Comment on lines +106 to 114
export const debounceAddDonkeysAndArmiesSubscription = debounce(
async <S extends Schema>(
client: ToriiClient,
components: Component<S, Metadata, undefined>[],
entityID: number[],
onComplete?: () => void,
) => {
await subscriptionQueue.add(() => addArrivalsSubscription(client, components, entityID), onComplete);
await subscriptionQueue.add(() => addDonkeysAndArmiesSubscription(client, components, entityID), onComplete);
},
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

💡 Codebase verification

Type inconsistency confirmed between debounced function and its implementation

The type inconsistency is actually a bug. From the code analysis:

  • debounceAddDonkeysAndArmiesSubscription accepts entityID: number[]

  • But its implementation addDonkeysAndArmiesSubscription expects entityIds: number[] (note the plural form)

  • All other subscription functions consistently use entityID: string[]

  • client/src/dojo/debouncedQueries.ts: Parameter name mismatch between entityID and entityIds

  • client/src/dojo/queries.ts: Consider aligning the type with other subscription functions (string[] instead of number[])

🔗 Analysis chain

Consider type consistency across subscription functions

The entityID parameter is typed as number[] while other similar functions (debouncedAddToSubscription, debouncedAddToSubscriptionOneKey, etc.) use string[]. Please verify if this type difference is intentional.


These commands will help us:

  1. Find all subscription-related functions
  2. See the full context of debouncedQueries.ts
  3. Find function declarations with entityID parameter using AST matching
🏁 Scripts executed

The following scripts were executed for the analysis:

Script:

#!/bin/bash
# Search for entityID parameter types in subscription functions
ast-grep --pattern 'function $name($params) { $$$}' | rg 'entityID.*\['

Length of output: 73


Script:

#!/bin/bash
# Let's search for all subscription-related functions and their entityID parameter types
rg -A 3 "export (const|function) \w*[Ss]ubscription" 

Length of output: 3839


Script:

#!/bin/bash
# Search specifically in the debouncedQueries.ts file
cat client/src/dojo/debouncedQueries.ts

Length of output: 4739


Script:

#!/bin/bash
# Search for function declarations with entityID parameter
ast-grep --pattern 'export const $_ = $$$entityID: $_$$$'

Length of output: 59

@aymericdelab aymericdelab merged commit e0c23e4 into next Dec 22, 2024
7 of 9 checks passed
@aymericdelab aymericdelab deleted the fix-armies branch December 22, 2024 21:58
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

1 participant