feat(webui): add "max rank all warframes" & "max rank all weapons" #783

Merged
nrbdev merged 3 commits from rank-30-everything into main 2025-01-15 07:29:02 -08:00
nrbdev commented 2025-01-15 06:57:43 -08:00 (Migrated from github.com)

Adds 2 new buttons in the bulk actions container

  1. to make every owned warframe max rank
  2. to make every owned weapon max rank

also made the lists have a max width so the page doesnt need to be scrolled down all the way to see the buttons

Adds 2 new buttons in the bulk actions container 1. to make every owned warframe max rank 2. to make every owned weapon max rank also made the lists have a max width so the page doesnt need to be scrolled down all the way to see the buttons
coderabbitai[bot] commented 2025-01-15 06:57:52 -08:00 (Migrated from github.com)

Walkthrough

The pull request introduces enhancements to the web user interface for managing warframes and weapons in a game-like inventory system. The changes span two primary files: index.html and script.js.

In the HTML file, visual and layout modifications were made to improve the user interface, including setting explicit heights for card elements, enabling scrollable content, and implementing a more responsive design for the "Bulk Actions" section. Two new buttons were added for bulk actions: "Max Rank All Warframes" and "Max Rank All Weapons."

The corresponding JavaScript file (script.js) implements the functionality for these new bulk action buttons. Two new functions, maxRankAllWarframes and maxRankAllWeapons, were created to automatically rank up all warframes and weapons by retrieving inventory data and sending batch experience updates. A helper function sendBatchGearExp was also introduced to streamline the batch update process.

  • spaceninjaserver/SpaceNinjaServer#776: This issue requests the implementation of a feature to max rank all warframes/weapons, which aligns directly with the new functionality introduced in this pull request.

📜 Recent review details

Configuration used: .coderabbit.yaml
Review profile: CHILL
Plan: Pro

📥 Commits

Reviewing files that changed from the base of the PR and between b62a44cc9f and 7068d01ae4.

📒 Files selected for processing (1)
  • static/webui/index.html (3 hunks)
🚧 Files skipped from review as they are similar to previous changes (1)
  • static/webui/index.html

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.

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.
<!-- This is an auto-generated comment: summarize by coderabbit.ai --> <!-- walkthrough_start --> ## Walkthrough The pull request introduces enhancements to the web user interface for managing warframes and weapons in a game-like inventory system. The changes span two primary files: `index.html` and `script.js`. In the HTML file, visual and layout modifications were made to improve the user interface, including setting explicit heights for card elements, enabling scrollable content, and implementing a more responsive design for the "Bulk Actions" section. Two new buttons were added for bulk actions: "Max Rank All Warframes" and "Max Rank All Weapons." The corresponding JavaScript file (`script.js`) implements the functionality for these new bulk action buttons. Two new functions, `maxRankAllWarframes` and `maxRankAllWeapons`, were created to automatically rank up all warframes and weapons by retrieving inventory data and sending batch experience updates. A helper function `sendBatchGearExp` was also introduced to streamline the batch update process. ## Possibly related issues - **spaceninjaserver/SpaceNinjaServer#776**: This issue requests the implementation of a feature to max rank all warframes/weapons, which aligns directly with the new functionality introduced in this pull request. <!-- walkthrough_end --> --- <details> <summary>📜 Recent review details</summary> **Configuration used: .coderabbit.yaml** **Review profile: CHILL** **Plan: Pro** <details> <summary>📥 Commits</summary> Reviewing files that changed from the base of the PR and between b62a44cc9fdd944e4c2425256ae05b65c40977ca and 7068d01ae4708cafffae600652ea43f16ba7796f. </details> <details> <summary>📒 Files selected for processing (1)</summary> * `static/webui/index.html` (3 hunks) </details> <details> <summary>🚧 Files skipped from review as they are similar to previous changes (1)</summary> * static/webui/index.html </details> </details> <!-- internal state start --> <!-- FAHghAtBAEAqAWBLAztF0CGA7TBXALgPYQDmAplmQE4b5kAm0AxoQLasX4Bc0ADldEIAjAFZkm+RADcyqIQE9mhetQxChifADoMiaFAB8wY+CjGAxOegAFAErQAyrnYYq84wjJ9cAGx/QqMgBHXFl8aEl8HwZoACIAMzJaAAoAdzIhXEQASh4MekYAclYMAA8A7ABrTD9oVNd4mg5kQugAMmhisoqsaoxa9IxeQiwW2LqMVGRcIVZNOkYFaFxkamgsKiEVKUwsRnREFSxJeMQYyfXnITWAdgAOAGYtOHgvOzRjqmVcJlkI1MI6zIqWgmXwRFGdU0SBw+FeoN8fQkiBGqBYx10lAEhHiEXh6SEy1WAkQx2o8Qwv2enlWCPBqOgxJkeK88UIfkIqVJJGg8VwWGRqK4xgAjM8AIJ0iERQElSpeMgyNyCVKURj1KiNDAcAJJJjwaAlco0XpaYAAJglUpGMsNGHl0EV1EUnLVdSSwxw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YhWp6mmS6EZSZ2iwFiGMC7SVsODTxkY4boCRpXTG8IaYK3ICrcm6AHMs05rzeEEWE1W6pkPS2q2+LV59vdIirJlNwiUBiBZ3cy69hJL2GnGZtAbOAj+S+t9R6P1fp/X8iUHlogXjQFMRNqp/3rEBCZyEYXGCobYZbQM+dC7hmLt6rwyW1Kpf1J+1w37f0Pq2rmA4nxvi/FtoCa+9AxoVmGClVsGkhDvuWL5ugIcDbkFcLTfVFAAmMgmkkQqpJb7wjY0Sz+7Lu3UsPmVw8xgLGqD8E1u5LU/hX2wM4u+vWi7eNAfCcOezwhLAjJyVsX9qhVZ5BpBD956xscltV4ka3BYba8EsDuPx9teAq9anT0t/BQcW4GCwZyfAtO6dk9peSukMiKT+vpZSBAVKGSMyQshlnQCPI+m0+Qp48D+b6m0gKqgeqpc0ZI2RIU9WS6la6GUMhZW+/srQhy/n1JZ2zjykWuc85wHz4FjHz7C9Fy69ZaUpeZG2bLg5LGles7e6rzn0Bucq5i6+99HWqBdeSCekXHw7eG8l1snZgs5cK+OaVep8VEqqWixpXFFy9GMACoZYKjJnANUUBFZQUUNAxUcmH5y+k5j4AAPqHGQAXwIktgQMAL+svLSlQAqVBGm80GAWYszfAATniAUNvLeyCt/NCzc0ABWIfaaMBkHZoPoQabB9MBZuzNvNwbjZjikYXPNx2ZpruPQdmIox8s3X3cbMcyKRkAzRv4fSQWYPHiCKNNs3F9t7TbiWvueAqaCL6nUviozjpHoAXtSK+QAA=== --> <!-- internal state end --> <!-- tips_start --> --- 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? <details> <summary>❤️ Share</summary> - [X](https://twitter.com/intent/tweet?text=I%20just%20used%20%40coderabbitai%20for%20my%20code%20review%2C%20and%20it%27s%20fantastic%21%20It%27s%20free%20for%20OSS%20and%20offers%20a%20free%20trial%20for%20the%20proprietary%20code.%20Check%20it%20out%3A&url=https%3A//coderabbit.ai) - [Mastodon](https://mastodon.social/share?text=I%20just%20used%20%40coderabbitai%20for%20my%20code%20review%2C%20and%20it%27s%20fantastic%21%20It%27s%20free%20for%20OSS%20and%20offers%20a%20free%20trial%20for%20the%20proprietary%20code.%20Check%20it%20out%3A%20https%3A%2F%2Fcoderabbit.ai) - [Reddit](https://www.reddit.com/submit?title=Great%20tool%20for%20code%20review%20-%20CodeRabbit&text=I%20just%20used%20CodeRabbit%20for%20my%20code%20review%2C%20and%20it%27s%20fantastic%21%20It%27s%20free%20for%20OSS%20and%20offers%20a%20free%20trial%20for%20proprietary%20code.%20Check%20it%20out%3A%20https%3A//coderabbit.ai) - [LinkedIn](https://www.linkedin.com/sharing/share-offsite/?url=https%3A%2F%2Fcoderabbit.ai&mini=true&title=Great%20tool%20for%20code%20review%20-%20CodeRabbit&summary=I%20just%20used%20CodeRabbit%20for%20my%20code%20review%2C%20and%20it%27s%20fantastic%21%20It%27s%20free%20for%20OSS%20and%20offers%20a%20free%20trial%20for%20proprietary%20code) </details> <details> <summary>🪧 Tips</summary> ### Chat There are 3 ways to chat with [CodeRabbit](https://coderabbit.ai): - 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](https://docs.coderabbit.ai/finishing-touches/docstrings) for this PR. ([Beta](https://docs.coderabbit.ai/early-access#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. ### Documentation and Community - Visit our [Documentation](https://docs.coderabbit.ai) for detailed information on how to use CodeRabbit. - Join our [Discord Community](http://discord.gg/coderabbit) to get help, request features, and share feedback. - Follow us on [X/Twitter](https://twitter.com/coderabbitai) for updates and announcements. </details> <!-- tips_end -->
coderabbitai[bot] (Migrated from github.com) reviewed 2025-01-15 06:59:58 -08:00
coderabbitai[bot] (Migrated from github.com) left a comment

Actionable comments posted: 3

📜 Review details

Configuration used: .coderabbit.yaml
Review profile: CHILL
Plan: Pro

📥 Commits

Reviewing files that changed from the base of the PR and between d73d14bc48 and b62a44cc9f.

📒 Files selected for processing (2)
  • static/webui/index.html (2 hunks)
  • static/webui/script.js (3 hunks)
🧰 Additional context used
🪛 eslint
static/webui/script.js

[error] 608-608: 'maxRankAllWarframes' is defined but never used.

(@typescript-eslint/no-unused-vars)


[error] 609-609: '$' is not defined.

(no-undef)


[error] 663-663: 'maxRankAllWeapons' is defined but never used.

(@typescript-eslint/no-unused-vars)


[error] 664-664: '$' is not defined.

(no-undef)


[error] 714-714: '$' is not defined.

(no-undef)

🔇 Additional comments (1)
static/webui/index.html (1)

99-101: UI improvements enhance usability and layout.

The changes improve the user interface by:

  1. Setting fixed heights for lists to prevent excessive page length
  2. Adding overflow scrolling for better content management
  3. Using flexbox for responsive button layout

Also applies to: 113-117, 122-124

**Actionable comments posted: 3** <details> <summary>📜 Review details</summary> **Configuration used: .coderabbit.yaml** **Review profile: CHILL** **Plan: Pro** <details> <summary>📥 Commits</summary> Reviewing files that changed from the base of the PR and between d73d14bc489be577438886b91dfb38cc46004296 and b62a44cc9fdd944e4c2425256ae05b65c40977ca. </details> <details> <summary>📒 Files selected for processing (2)</summary> * `static/webui/index.html` (2 hunks) * `static/webui/script.js` (3 hunks) </details> <details> <summary>🧰 Additional context used</summary> <details> <summary>🪛 eslint</summary> <details> <summary>static/webui/script.js</summary> [error] 608-608: 'maxRankAllWarframes' is defined but never used. (@typescript-eslint/no-unused-vars) --- [error] 609-609: '$' is not defined. (no-undef) --- [error] 663-663: 'maxRankAllWeapons' is defined but never used. (@typescript-eslint/no-unused-vars) --- [error] 664-664: '$' is not defined. (no-undef) --- [error] 714-714: '$' is not defined. (no-undef) </details> </details> </details> <details> <summary>🔇 Additional comments (1)</summary><blockquote> <details> <summary>static/webui/index.html (1)</summary> `99-101`: **UI improvements enhance usability and layout.** The changes improve the user interface by: 1. Setting fixed heights for lists to prevent excessive page length 2. Adding overflow scrolling for better content management 3. Using flexbox for responsive button layout Also applies to: 113-117, 122-124 </details> </blockquote></details> </details> <!-- This is an auto-generated comment by CodeRabbit for review status -->
@ -608,0 +643,4 @@
alert("No Warframes to rank up.");
});
});
}
coderabbitai[bot] (Migrated from github.com) commented 2025-01-15 06:59:58 -08:00

🛠️ Refactor suggestion

Add error handling and improve user feedback.

The function needs the following improvements:

  1. Error handling for API calls
  2. Loading state feedback for long operations
  3. Constants for XP thresholds

Consider this implementation:

+const WARFRAME_MAX_XP = 1_600_000;
+const WEAPON_MAX_XP = 800_000;

 function maxRankAllWarframes() {
+    const button = document.querySelector('button[onclick="maxRankAllWarframes()"]');
+    button.disabled = true;
+    button.textContent = 'Processing...';
+
     const req = $.get("/api/inventory.php?" + window.authz + "&xpBasedLevelCapDisabled=1");
-    req.done(data => {
+    req.done(data => {
         window.itemListPromise.then(itemMap => {
             const batchData = { Suits: [], SpecialItems: [] };
 
             data.Suits.forEach(item => {
-                if (item.XP < 1_600_000) {
+                if (item.XP < WARFRAME_MAX_XP) {
                     batchData.Suits.push({
                         ItemId: { $oid: item.ItemId.$oid },
-                        XP: 1_600_000 - item.XP
+                        XP: WARFRAME_MAX_XP - item.XP
                     });
                 }
 
                 if ("exalted" in itemMap[item.ItemType]) {
                     for (const exaltedType of itemMap[item.ItemType].exalted) {
                         const exaltedItem = data.SpecialItems.find(x => x.ItemType == exaltedType);
                         if (exaltedItem) {
-                            const exaltedCap = itemMap[exaltedType]?.type == "weapons" ? 800_000 : 1_600_000;
+                            const exaltedCap = itemMap[exaltedType]?.type == "weapons" ? WEAPON_MAX_XP : WARFRAME_MAX_XP;
                             if (exaltedItem.XP < exaltedCap) {
                                 batchData.SpecialItems.push({
                                     ItemId: { $oid: exaltedItem.ItemId.$oid },
                                     XP: exaltedCap - exaltedItem.XP
                                 });
                             }
                         }
                     }
                 }
             });
 
             if (batchData.Suits.length > 0 || batchData.SpecialItems.length > 0) {
-                return sendBatchGearExp(batchData);
+                return sendBatchGearExp(batchData).finally(() => {
+                    button.disabled = false;
+                    button.textContent = 'Max Rank All Warframes';
+                });
             }
 
             alert("No Warframes to rank up.");
+            button.disabled = false;
+            button.textContent = 'Max Rank All Warframes';
         });
+    }).fail(error => {
+        console.error('Failed to fetch inventory:', error);
+        alert('Failed to fetch inventory. Please try again.');
+        button.disabled = false;
+        button.textContent = 'Max Rank All Warframes';
     });
 }
📝 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.

const WARFRAME_MAX_XP = 1_600_000;
const WEAPON_MAX_XP = 800_000;

function maxRankAllWarframes() {
    const button = document.querySelector('button[onclick="maxRankAllWarframes()"]');
    button.disabled = true;
    button.textContent = 'Processing...';

    const req = $.get("/api/inventory.php?" + window.authz + "&xpBasedLevelCapDisabled=1");
    req.done(data => {
        window.itemListPromise.then(itemMap => {
            const batchData = { Suits: [], SpecialItems: [] };

            data.Suits.forEach(item => {
                if (item.XP < WARFRAME_MAX_XP) {
                    batchData.Suits.push({
                        ItemId: { $oid: item.ItemId.$oid },
                        XP: WARFRAME_MAX_XP - item.XP
                    });
                }

                if ("exalted" in itemMap[item.ItemType]) {
                    for (const exaltedType of itemMap[item.ItemType].exalted) {
                        const exaltedItem = data.SpecialItems.find(x => x.ItemType == exaltedType);
                        if (exaltedItem) {
                            const exaltedCap = itemMap[exaltedType]?.type == "weapons" ? WEAPON_MAX_XP : WARFRAME_MAX_XP;
                            if (exaltedItem.XP < exaltedCap) {
                                batchData.SpecialItems.push({
                                    ItemId: { $oid: exaltedItem.ItemId.$oid },
                                    XP: exaltedCap - exaltedItem.XP
                                });
                            }
                        }
                    }
                }
            });

            if (batchData.Suits.length > 0 || batchData.SpecialItems.length > 0) {
                return sendBatchGearExp(batchData).finally(() => {
                    button.disabled = false;
                    button.textContent = 'Max Rank All Warframes';
                });
            }

            alert("No Warframes to rank up.");
            button.disabled = false;
            button.textContent = 'Max Rank All Warframes';
        });
    }).fail(error => {
        console.error('Failed to fetch inventory:', error);
        alert('Failed to fetch inventory. Please try again.');
        button.disabled = false;
        button.textContent = 'Max Rank All Warframes';
    });
}
🧰 Tools
🪛 eslint

[error] 608-608: 'maxRankAllWarframes' is defined but never used.

(@typescript-eslint/no-unused-vars)


[error] 609-609: '$' is not defined.

(no-undef)

_:hammer_and_wrench: Refactor suggestion_ **Add error handling and improve user feedback.** The function needs the following improvements: 1. Error handling for API calls 2. Loading state feedback for long operations 3. Constants for XP thresholds Consider this implementation: ```diff +const WARFRAME_MAX_XP = 1_600_000; +const WEAPON_MAX_XP = 800_000; function maxRankAllWarframes() { + const button = document.querySelector('button[onclick="maxRankAllWarframes()"]'); + button.disabled = true; + button.textContent = 'Processing...'; + const req = $.get("/api/inventory.php?" + window.authz + "&xpBasedLevelCapDisabled=1"); - req.done(data => { + req.done(data => { window.itemListPromise.then(itemMap => { const batchData = { Suits: [], SpecialItems: [] }; data.Suits.forEach(item => { - if (item.XP < 1_600_000) { + if (item.XP < WARFRAME_MAX_XP) { batchData.Suits.push({ ItemId: { $oid: item.ItemId.$oid }, - XP: 1_600_000 - item.XP + XP: WARFRAME_MAX_XP - item.XP }); } if ("exalted" in itemMap[item.ItemType]) { for (const exaltedType of itemMap[item.ItemType].exalted) { const exaltedItem = data.SpecialItems.find(x => x.ItemType == exaltedType); if (exaltedItem) { - const exaltedCap = itemMap[exaltedType]?.type == "weapons" ? 800_000 : 1_600_000; + const exaltedCap = itemMap[exaltedType]?.type == "weapons" ? WEAPON_MAX_XP : WARFRAME_MAX_XP; if (exaltedItem.XP < exaltedCap) { batchData.SpecialItems.push({ ItemId: { $oid: exaltedItem.ItemId.$oid }, XP: exaltedCap - exaltedItem.XP }); } } } } }); if (batchData.Suits.length > 0 || batchData.SpecialItems.length > 0) { - return sendBatchGearExp(batchData); + return sendBatchGearExp(batchData).finally(() => { + button.disabled = false; + button.textContent = 'Max Rank All Warframes'; + }); } alert("No Warframes to rank up."); + button.disabled = false; + button.textContent = 'Max Rank All Warframes'; }); + }).fail(error => { + console.error('Failed to fetch inventory:', error); + alert('Failed to fetch inventory. Please try again.'); + button.disabled = false; + button.textContent = 'Max Rank All Warframes'; }); } ``` <!-- suggestion_start --> <details> <summary>📝 Committable suggestion</summary> > ‼️ **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. `````suggestion const WARFRAME_MAX_XP = 1_600_000; const WEAPON_MAX_XP = 800_000; function maxRankAllWarframes() { const button = document.querySelector('button[onclick="maxRankAllWarframes()"]'); button.disabled = true; button.textContent = 'Processing...'; const req = $.get("/api/inventory.php?" + window.authz + "&xpBasedLevelCapDisabled=1"); req.done(data => { window.itemListPromise.then(itemMap => { const batchData = { Suits: [], SpecialItems: [] }; data.Suits.forEach(item => { if (item.XP < WARFRAME_MAX_XP) { batchData.Suits.push({ ItemId: { $oid: item.ItemId.$oid }, XP: WARFRAME_MAX_XP - item.XP }); } if ("exalted" in itemMap[item.ItemType]) { for (const exaltedType of itemMap[item.ItemType].exalted) { const exaltedItem = data.SpecialItems.find(x => x.ItemType == exaltedType); if (exaltedItem) { const exaltedCap = itemMap[exaltedType]?.type == "weapons" ? WEAPON_MAX_XP : WARFRAME_MAX_XP; if (exaltedItem.XP < exaltedCap) { batchData.SpecialItems.push({ ItemId: { $oid: exaltedItem.ItemId.$oid }, XP: exaltedCap - exaltedItem.XP }); } } } } }); if (batchData.Suits.length > 0 || batchData.SpecialItems.length > 0) { return sendBatchGearExp(batchData).finally(() => { button.disabled = false; button.textContent = 'Max Rank All Warframes'; }); } alert("No Warframes to rank up."); button.disabled = false; button.textContent = 'Max Rank All Warframes'; }); }).fail(error => { console.error('Failed to fetch inventory:', error); alert('Failed to fetch inventory. Please try again.'); button.disabled = false; button.textContent = 'Max Rank All Warframes'; }); } ````` </details> <!-- suggestion_end --> <details> <summary>🧰 Tools</summary> <details> <summary>🪛 eslint</summary> [error] 608-608: 'maxRankAllWarframes' is defined but never used. (@typescript-eslint/no-unused-vars) --- [error] 609-609: '$' is not defined. (no-undef) </details> </details> <!-- This is an auto-generated comment by CodeRabbit -->
coderabbitai[bot] (Migrated from github.com) commented 2025-01-15 06:59:58 -08:00

🛠️ Refactor suggestion

Refactor to reduce duplication and add error handling.

The function needs similar improvements as maxRankAllWarframes, plus reduction of code duplication.

Consider this implementation:

+const WEAPON_CATEGORIES = ["LongGuns", "Pistols", "Melee"];

 function maxRankAllWeapons() {
+    const button = document.querySelector('button[onclick="maxRankAllWeapons()"]');
+    button.disabled = true;
+    button.textContent = 'Processing...';
+
     const req = $.get("/api/inventory.php?" + window.authz + "&xpBasedLevelCapDisabled=1");
-    req.done(data => {
+    req.done(data => {
         const batchData = {};
 
-        ["LongGuns", "Pistols", "Melee"].forEach(category => {
+        WEAPON_CATEGORIES.forEach(category => {
             data[category].forEach(item => {
-                if (item.XP < 800_000) {
+                if (item.XP < WEAPON_MAX_XP) {
                     if (!batchData[category]) {
                         batchData[category] = [];
                     }
                     batchData[category].push({
                         ItemId: { $oid: item.ItemId.$oid },
-                        XP: 800_000 - item.XP
+                        XP: WEAPON_MAX_XP - item.XP
                     });
                 }
             });
         });
 
         if (Object.keys(batchData).length > 0) {
-            return sendBatchGearExp(batchData);
+            return sendBatchGearExp(batchData).finally(() => {
+                button.disabled = false;
+                button.textContent = 'Max Rank All Weapons';
+            });
         }
 
         alert("No weapons to rank up.");
+        button.disabled = false;
+        button.textContent = 'Max Rank All Weapons';
+    }).fail(error => {
+        console.error('Failed to fetch inventory:', error);
+        alert('Failed to fetch inventory. Please try again.');
+        button.disabled = false;
+        button.textContent = 'Max Rank All Weapons';
     });
 }

Committable suggestion skipped: line range outside the PR's diff.

🧰 Tools
🪛 eslint

[error] 663-663: 'maxRankAllWeapons' is defined but never used.

(@typescript-eslint/no-unused-vars)


[error] 664-664: '$' is not defined.

(no-undef)

_:hammer_and_wrench: Refactor suggestion_ **Refactor to reduce duplication and add error handling.** The function needs similar improvements as maxRankAllWarframes, plus reduction of code duplication. Consider this implementation: ```diff +const WEAPON_CATEGORIES = ["LongGuns", "Pistols", "Melee"]; function maxRankAllWeapons() { + const button = document.querySelector('button[onclick="maxRankAllWeapons()"]'); + button.disabled = true; + button.textContent = 'Processing...'; + const req = $.get("/api/inventory.php?" + window.authz + "&xpBasedLevelCapDisabled=1"); - req.done(data => { + req.done(data => { const batchData = {}; - ["LongGuns", "Pistols", "Melee"].forEach(category => { + WEAPON_CATEGORIES.forEach(category => { data[category].forEach(item => { - if (item.XP < 800_000) { + if (item.XP < WEAPON_MAX_XP) { if (!batchData[category]) { batchData[category] = []; } batchData[category].push({ ItemId: { $oid: item.ItemId.$oid }, - XP: 800_000 - item.XP + XP: WEAPON_MAX_XP - item.XP }); } }); }); if (Object.keys(batchData).length > 0) { - return sendBatchGearExp(batchData); + return sendBatchGearExp(batchData).finally(() => { + button.disabled = false; + button.textContent = 'Max Rank All Weapons'; + }); } alert("No weapons to rank up."); + button.disabled = false; + button.textContent = 'Max Rank All Weapons'; + }).fail(error => { + console.error('Failed to fetch inventory:', error); + alert('Failed to fetch inventory. Please try again.'); + button.disabled = false; + button.textContent = 'Max Rank All Weapons'; }); } ``` > Committable suggestion skipped: line range outside the PR's diff. <details> <summary>🧰 Tools</summary> <details> <summary>🪛 eslint</summary> [error] 663-663: 'maxRankAllWeapons' is defined but never used. (@typescript-eslint/no-unused-vars) --- [error] 664-664: '$' is not defined. (no-undef) </details> </details> <!-- This is an auto-generated comment by CodeRabbit -->
coderabbitai[bot] (Migrated from github.com) commented 2025-01-15 06:59:57 -08:00

🛠️ Refactor suggestion

Improve error handling and promise chain.

The function should return the promise and handle errors properly.

Apply this improvement:

 function sendBatchGearExp(data) {
     revalidateAuthz(() => {
-        $.post({
+        return $.post({
             url: "/api/missionInventoryUpdate.php?" + window.authz,
             contentType: "text/plain",
             data: JSON.stringify(data)
-        }).done(() => {
+        }).done(response => {
             updateInventory();
+            return response;
+        }).fail(error => {
+            console.error('Failed to update inventory:', error);
+            throw error;
         });
     });
 }
📝 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.

function sendBatchGearExp(data) {
    revalidateAuthz(() => {
        return $.post({
            url: "/api/missionInventoryUpdate.php?" + window.authz,
            contentType: "text/plain",
            data: JSON.stringify(data)
        }).done(response => {
            updateInventory();
            return response;
        }).fail(error => {
            console.error('Failed to update inventory:', error);
            throw error;
        });
    });
}
🧰 Tools
🪛 eslint

[error] 714-714: '$' is not defined.

(no-undef)

_:hammer_and_wrench: Refactor suggestion_ **Improve error handling and promise chain.** The function should return the promise and handle errors properly. Apply this improvement: ```diff function sendBatchGearExp(data) { revalidateAuthz(() => { - $.post({ + return $.post({ url: "/api/missionInventoryUpdate.php?" + window.authz, contentType: "text/plain", data: JSON.stringify(data) - }).done(() => { + }).done(response => { updateInventory(); + return response; + }).fail(error => { + console.error('Failed to update inventory:', error); + throw error; }); }); } ``` <!-- suggestion_start --> <details> <summary>📝 Committable suggestion</summary> > ‼️ **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. `````suggestion function sendBatchGearExp(data) { revalidateAuthz(() => { return $.post({ url: "/api/missionInventoryUpdate.php?" + window.authz, contentType: "text/plain", data: JSON.stringify(data) }).done(response => { updateInventory(); return response; }).fail(error => { console.error('Failed to update inventory:', error); throw error; }); }); } ````` </details> <!-- suggestion_end --> <details> <summary>🧰 Tools</summary> <details> <summary>🪛 eslint</summary> [error] 714-714: '$' is not defined. (no-undef) </details> </details> <!-- This is an auto-generated comment by CodeRabbit -->
Sign in to join this conversation.
No description provided.