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

Add discord invite button #1985

Merged
merged 1 commit into from
Nov 4, 2024
Merged

Add discord invite button #1985

merged 1 commit into from
Nov 4, 2024

Conversation

bob0005
Copy link
Collaborator

@bob0005 bob0005 commented Nov 4, 2024

Closes #1957

Summary by CodeRabbit

Release Notes

  • New Features

    • Added a Discord button in the secondary menu for quick access.
    • Introduced a new Discord image thumbnail in the UI configuration.
    • Included a Settings window in the top navigation for enhanced user settings management.
  • Bug Fixes

    • Improved error handling for battery checks on laptops to enhance device detection reliability.
  • Refactor

    • Streamlined the SecondaryMenuItems component by removing unused state management related to quests.
  • Style

    • Updated the label of the settings button to "Support" for clearer functionality.

Copy link

vercel bot commented Nov 4, 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 Nov 4, 2024 6:33pm
1 Skipped Deployment
Name Status Preview Comments Updated (UTC)
eternum-landing ⬜️ Ignored (Inspect) Visit Preview Nov 4, 2024 6:33pm

Copy link
Contributor

mentatbot bot commented Nov 4, 2024

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

Copy link
Contributor

coderabbitai bot commented Nov 4, 2024

Walkthrough

The changes in this pull request introduce a new Discord image path in the BuildingThumbs object and enhance error handling in the checkIfGameIsRunningOnLaptop function. The SecondaryMenuItems component is streamlined by removing unused quest-related state management and adding a Discord button. The TopNavigation component now includes the SettingsWindow, and the Settings component has reorganized imports and adjusted graphics settings handling. Overall, these modifications improve UI navigation and device detection functionalities.

Changes

File Path Change Summary
client/src/ui/config.tsx Added discord: "/images/buildings/thumb/discord.png" to BuildingThumbs. Modified checkIfGameIsRunningOnLaptop for error handling and local storage updates.
client/src/ui/modules/navigation/SecondaryMenuItems.tsx Removed useQuestClaimStatus and useQuestStore. Added Discord CircleButton and changed settings button label from "Settings" to "Support". Removed SettingsWindow from return statement.
client/src/ui/modules/navigation/TopNavigation.tsx Imported and added SettingsWindow to TopMiddleNavigation.
client/src/ui/modules/settings/Settings.tsx Reorganized imports and adjusted graphics settings handling based on IS_LOW_GRAPHICS_ENABLED.

Assessment against linked issues

Objective Addressed Explanation
Link to discord in client for - 'Support' (#1957)

Possibly related PRs

  • fix sound effect volume #1975: Involves enhancements to functionality related to error handling and state management, but focuses on different components than this PR.

Suggested reviewers

  • edisontim

Poem

🐰 In the realm of code, new paths we weave,
A button for Discord, oh what a reprieve!
With settings now clearer, and graphics in sight,
Our app shines brighter, a true delight!
So hop on this journey, let’s code and explore,
Together we build, forever and more! 🌟


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 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

github-actions bot commented Nov 4, 2024

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

🧹 Outside diff range and nitpick comments (5)
client/src/ui/modules/navigation/TopNavigation.tsx (1)

3-3: Consider documenting the UI reorganization rationale.

Moving the SettingsWindow from SecondaryMenuItems to TopNavigation represents a significant UI structure change. Please document:

  1. Why this reorganization was necessary
  2. How it improves the user experience
  3. Whether this impacts the visibility and accessibility of settings

This documentation will help maintain architectural consistency in future UI changes.

Also applies to: 14-14

client/src/ui/config.tsx (1)

Line range hint 5-21: Improve error handling in device detection.

The current implementation has several potential issues:

  1. Setting LOW_GRAPHICS_FLAG to "true" by default might unnecessarily degrade performance on capable devices
  2. Setting INITIAL_LAPTOP_CHECK prevents retrying on subsequent page loads
  3. Users aren't notified of detection failures

Consider this improved implementation:

 const checkIfGameIsRunningOnLaptop = async () => {
-  if (!localStorage.getItem("INITIAL_LAPTOP_CHECK")) {
-    try {
-      const battery = await (navigator as any).getBattery();
-      if (battery.charging && battery.chargingTime === 0) {
-        // It's likely a desktop
-        localStorage.setItem("LOW_GRAPHICS_FLAG", "false");
-      } else {
-        // It's likely a laptop or mobile device
-        localStorage.setItem("LOW_GRAPHICS_FLAG", "true");
-      }
-    } catch (error) {
-      console.error("Error calling getBattery():", error);
-      // Set default values if getBattery() is not supported
-      localStorage.setItem("LOW_GRAPHICS_FLAG", "true");
-    } finally {
-      localStorage.setItem("INITIAL_LAPTOP_CHECK", "true");
-    }
+  try {
+    // Check if battery API is supported
+    if (!('getBattery' in navigator)) {
+      throw new Error('Battery API not supported');
+    }
+    
+    const battery = await (navigator as any).getBattery();
+    const isDesktop = battery.charging && battery.chargingTime === 0;
+    
+    localStorage.setItem("LOW_GRAPHICS_FLAG", (!isDesktop).toString());
+    return !isDesktop;
+  } catch (error) {
+    console.warn("Device detection failed:", error);
+    // Keep existing setting if available
+    const existing = localStorage.getItem("LOW_GRAPHICS_FLAG");
+    if (existing === null) {
+      // Default to system memory as fallback
+      const lowMemory = (navigator as any).deviceMemory < 4;
+      localStorage.setItem("LOW_GRAPHICS_FLAG", lowMemory.toString());
+      return lowMemory;
+    }
+    return existing === "true";
   }
-  return localStorage.getItem("LOW_GRAPHICS_FLAG") === "true";
 };
client/src/ui/modules/navigation/SecondaryMenuItems.tsx (1)

90-96: Consider enhancing the Discord button implementation.

While the implementation meets the basic requirement, consider these improvements:

  1. Move the Discord URL to a configuration file for easier maintenance
  2. Add error handling for the window.open call
  3. Add aria-label for better accessibility
 <CircleButton
   tooltipLocation="bottom"
   image={BuildingThumbs.discord}
   label={"Discord"}
   size="lg"
-  onClick={() => window.open("https://discord.gg/realmsworld")}
+  aria-label="Join our Discord community for support"
+  onClick={() => {
+    try {
+      window.open(DISCORD_INVITE_URL, '_blank')?.focus();
+    } catch (error) {
+      console.error('Failed to open Discord link:', error);
+    }
+  }}
 />
client/src/ui/modules/settings/Settings.tsx (2)

Line range hint 91-116: Improve graphics settings toggle implementation.

The current implementation has several areas for improvement:

  1. Window reload creates a jarring user experience
  2. No loading state or user warning about the page reload
  3. Missing error handling for localStorage operations

Consider applying these improvements:

 <Button
   disabled={!!isLowGraphics}
   variant={isLowGraphics ? "success" : "outline"}
   onClick={() => {
     if (!isLowGraphics) {
+      if (!confirm('Changing graphics settings requires a page reload. Continue?')) {
+        return;
+      }
+      try {
         localStorage.setItem("LOW_GRAPHICS_FLAG", "true");
+      } catch (error) {
+        toast.error("Failed to save graphics settings");
+        return;
+      }
+      toast.info("Reloading with new graphics settings...");
       window.location.reload();
     }
   }}
 >
-  Low
+  {isLowGraphics ? "Low (Active)" : "Low"}
 </Button>

Similar changes should be applied to the High graphics button.


Line range hint 146-152: Add Discord support button as per PR objectives.

The PR's main objective is to add a Discord support button, but it's missing from the social links section. Consider adding it alongside the existing Realms.World and Dojo links.

Add the Discord button:

 <div className="flex py-3 space-x-3">
   <a target="_blank" href="https://realms.world">
     <RealmsWorld className="w-16" />
   </a>
   <a href="https://www.dojoengine.org/en/">
     <DojoMark className="w-16" />
   </a>
+  <a href="https://discord.gg/realmsworld" target="_blank" rel="noopener noreferrer">
+    <Button variant="outline" className="!py-1">
+      Support
+    </Button>
+  </a>
 </div>
📜 Review details

Configuration used: CodeRabbit UI
Review profile: CHILL

📥 Commits

Reviewing files that changed from the base of the PR and between a07189a and 3d88ba7.

⛔ Files ignored due to path filters (1)
  • client/public/images/buildings/thumb/discord.png is excluded by !**/*.png
📒 Files selected for processing (4)
  • client/src/ui/config.tsx (1 hunks)
  • client/src/ui/modules/navigation/SecondaryMenuItems.tsx (3 hunks)
  • client/src/ui/modules/navigation/TopNavigation.tsx (2 hunks)
  • client/src/ui/modules/settings/Settings.tsx (1 hunks)
🔇 Additional comments (6)
client/src/ui/modules/navigation/TopNavigation.tsx (1)

3-3: Verify the Discord button implementation.

While these changes reorganize the UI by moving the SettingsWindow component, I don't see the implementation of the Discord 'Support' button mentioned in the PR objectives. Please clarify how these changes relate to the Discord integration.

Also applies to: 14-14

client/src/ui/config.tsx (2)

72-72: LGTM: Discord image path added correctly.

The addition follows the established pattern in BuildingThumbs and supports the PR objective of adding a Discord support button.


72-72: Verify Discord image exists.

Let's ensure the Discord image is present in the repository.

✅ Verification successful

Discord image is correctly placed and accessible

The image file exists at the expected location: client/public/images/buildings/thumb/discord.png, which matches the configured path in the code.

🏁 Scripts executed

The following scripts were executed for the analysis:

Script:

#!/bin/bash
# Description: Verify Discord image exists
# Expected: File exists at the specified path

fd -t f "discord.png" public/images/buildings/thumb/

Length of output: 170


Script:

#!/bin/bash
# Let's first check if the image exists in any directory
fd -t f "discord.png"

# Also check the directory structure for images/buildings
fd -t d "buildings"

# And check for any thumb directories
fd -t d "thumb"

Length of output: 272

client/src/ui/modules/navigation/SecondaryMenuItems.tsx (1)

76-76: Verify the impact of removed quest dependencies.

The removal of quest-related dependencies might affect the component's reactivity to quest state changes.

✅ Verification successful

Based on the search results, I can now generate the final response. The codebase analysis shows that the removal of quest-related dependencies from SecondaryMenuItems.tsx is safe because:

  1. The component still maintains the necessary quest-related hooks (useQuests and useUnclaimedQuestsCount)
  2. The removed selectedQuest dependency was not being used in the component's logic
  3. The changes align with the PR's objective of adding a Discord invite button and simplifying the component

Dependency cleanup is safe and aligned with changes

The removal of quest-related dependencies from the useEffect's dependency array is correct as these dependencies are no longer used in the component's logic after the quest-related state management cleanup.

🏁 Scripts executed

The following scripts were executed for the analysis:

Script:

#!/bin/bash
# Search for any remaining quest-related state usage that might be affected
rg -A 3 "selectedQuest" --type tsx

Length of output: 62


Script:

#!/bin/bash
# Search for any remaining quest-related state usage with correct file extension
rg -A 3 "selectedQuest" --type ts --type tsx --type jsx --type js

# Also check for any quest-related hooks or state management
rg -A 3 "useQuest|questState" --type ts --type tsx --type jsx --type js

# Look for the component's implementation to understand the context better
rg -A 10 "SecondaryMenuItems" --type ts --type tsx --type jsx --type js

Length of output: 295


Script:

#!/bin/bash
# Search for any remaining quest-related state usage without file type restrictions
rg -A 3 "selectedQuest"

# Also check for any quest-related hooks or state management
rg -A 3 "useQuest|questState"

# Look for the component's implementation to understand the context
rg -A 10 "SecondaryMenuItems"

Length of output: 28149

client/src/ui/modules/settings/Settings.tsx (2)

14-14: LGTM: Import changes are well-organized.

The imports are logically grouped and the new IS_LOW_GRAPHICS_ENABLED constant is appropriately placed with other configuration imports.

Also applies to: 22-22


Line range hint 146-152: Verify Discord button implementation location.

The AI summary indicates that the Discord button was added to the SecondaryMenuItems component, but we're suggesting adding it to the Settings component. Please clarify the intended location for the Discord button to ensure consistent implementation.

Let's verify the current implementation:

<CircleButton
tooltipLocation="bottom"
active={isPopupOpen(settings)}
image={BuildingThumbs.settings}
label={"Settings"}
label={"Support"}
Copy link
Contributor

Choose a reason for hiding this comment

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

⚠️ Potential issue

Reconsider labeling the Settings button as "Support".

This change creates potential user confusion:

  1. The button still triggers settings functionality but is labeled "Support"
  2. Having both a Discord button and a "Support" button might confuse users about where to seek help
-          label={"Support"}
+          label={"Settings"}
📝 Committable suggestion

‼️ IMPORTANT
Carefully review the code before committing. Ensure that it accurately replaces the highlighted code, contains no missing lines, and has no issues with indentation. Thoroughly test & benchmark the code to ensure it meets the requirements.

Suggested change
label={"Support"}
label={"Settings"}

@aymericdelab aymericdelab self-requested a review November 4, 2024 19:28
@aymericdelab aymericdelab merged commit ecd190f into main Nov 4, 2024
8 checks passed
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.

Link to discord in client for - 'Support'
2 participants