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

Refactor sidebar expanded on-hover functionality and fix sidebar expa… #2288

Merged
merged 2 commits into from
Oct 24, 2024

Conversation

Richard-Woessner
Copy link
Contributor

@Richard-Woessner Richard-Woessner commented Oct 23, 2024

…nd/collapse behavior

  • Preferences:

    • Added a new preference zen.view.sidebar-expanded.on-hover.paused-for-expand to manage the paused state of the sidebar hover functionality.
    • Updated zen.view.sidebar-expanded.on-hover preference handling to ensure proper behavior when toggling the sidebar.
  • ZenUIManager.mjs:

    • Updated _updateOnHoverVerticalTabs method to handle the expanded state and remove hover attributes when the sidebar is expanded.
    • Refactored _updateEvent method to check and handle the expanded state of the sidebar, and to open or close the sidebar accordingly.
    • Added openSidebar and closeSidebar methods to manage the sidebar's expanded state and related attributes.
    • Refactored toggleExpand method to handle the new paused-for-expand preference and ensure proper toggling of the sidebar's expanded state.
  • zen-settings.js:

    • Updated setCompactModeStyle method to handle the new paused-for-expand preference.
    • Ensured that the paused-for-expand preference is reset when the sidebar expand strategy is changed.
  • zen-browser.js:

    • Added the new preference zen.view.sidebar-expanded.on-hover.paused-for-expand with a default value of false.
  • Submodule Updates:

    • Updated l10n submodule to the latest commit dd93803b84f398834049a3f650536fbdbd14cbca.
    • Updated zen-components submodule to the latest commit d853fa8de4167dfd4d1289f4f15792a698c738c3-dirty.
  • Miscellaneous:

    • Fixed indentation issues in ZenUIManager.mjs.
    • Removed commented-out code in ZenUIManager.mjs.
    • Ensured proper formatting and alignment of code blocks.

ISSUE: #2156

Summary by CodeRabbit

  • New Features

    • Introduced a preference for sidebar expansion behavior in Zen Marketplace settings.
    • Enhanced theme management with improved visibility handling for dark theme styles.
    • Improved keyboard shortcut management with conflict checks and reset confirmation.
  • Bug Fixes

    • Corrected event listener handling for theme toggles to better reflect user preferences.
  • Refactor

    • Updated variable declarations for improved scoping in sidebar management.
    • Adjusted logic for sidebar expansion behavior to ensure correct default settings.

…nd/collapse behavior

- **Preferences**:
  - Added a new preference `zen.view.sidebar-expanded.on-hover.paused-for-expand` to manage the paused state of the sidebar hover functionality.
  - Updated `zen.view.sidebar-expanded.on-hover` preference handling to ensure proper behavior when toggling the sidebar.

- **ZenUIManager.mjs**:
  - Updated `_updateOnHoverVerticalTabs` method to handle the expanded state and remove hover attributes when the sidebar is expanded.
  - Refactored `_updateEvent` method to check and handle the expanded state of the sidebar, and to open or close the sidebar accordingly.
  - Added `openSidebar` and `closeSidebar` methods to manage the sidebar's expanded state and related attributes.
  - Refactored `toggleExpand` method to handle the new `paused-for-expand` preference and ensure proper toggling of the sidebar's expanded state.

- **zen-settings.js**:
  - Updated `setCompactModeStyle` method to handle the new `paused-for-expand` preference.
  - Ensured that the `paused-for-expand` preference is reset when the sidebar expand strategy is changed.

- **zen-browser.js**:
  - Added the new preference `zen.view.sidebar-expanded.on-hover.paused-for-expand` with a default value of `false`.

- **Submodule Updates**:
  - Updated `l10n` submodule to the latest commit `dd93803b84f398834049a3f650536fbdbd14cbca`.
  - Updated `zen-components` submodule to the latest commit `d853fa8de4167dfd4d1289f4f15792a698c738c3-dirty`.

- **Miscellaneous**:
  - Fixed indentation issues in `ZenUIManager.mjs`.
  - Removed commented-out code in `ZenUIManager.mjs`.
  - Ensured proper formatting and alignment of code blocks.

ISSUE: zen-browser#2156
Copy link

coderabbitai bot commented Oct 23, 2024

📝 Walkthrough
📝 Walkthrough

Walkthrough

The pull request introduces modifications to the ZenUIManager.mjs and zen-settings.js files, focusing on managing sidebar expansion and hover detection in the Zen Marketplace. Key updates include the addition of a new property to track hover state, changes in variable declarations from let to const, and refinements to event handling and theme management. These changes aim to improve the functionality and user experience related to sidebar behavior and theme preferences.

Changes

File Path Change Summary
src/browser/base/content/ZenUIManager.mjs - Added _hoverPausedForExpand property to gZenUIManager.
- Updated openAndChangeToTab, init, _updateOnHoverVerticalTabs, and toggleExpand methods to use const instead of let.
- Enhanced logic for managing sidebar expansion and hover detection.
src/browser/components/preferences/zen-settings.js - Updated _initializeTabbarExpandForm to set default sidebar state based on new hover preference.
- Improved event listeners and keyboard shortcut management.

Possibly related PRs

Suggested reviewers

  • mauro-balades

📜 Recent review details

Configuration used: CodeRabbit UI
Review profile: ASSERTIVE

📥 Commits

Files that changed from the base of the PR and between 2214ab3 and 94b32c3.

📒 Files selected for processing (1)
  • src/browser/components/preferences/zen-settings.js (1 hunks)
🧰 Additional context used
🔇 Additional comments (1)
src/browser/components/preferences/zen-settings.js (1)

624-624: Setting defaultExpandPref is correct, but pausedForExpandPref needs handling.

The logic to set defaultExpandPref to false when hover mode is enabled is correct. However, as noted in a previous review, the new pausedForExpandPref should also be reset when changing the expand strategy.


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

@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: 3

📜 Review details

Configuration used: CodeRabbit UI
Review profile: ASSERTIVE

📥 Commits

Files that changed from the base of the PR and between 8631ada and 2214ab3.

📒 Files selected for processing (2)
  • src/browser/base/content/ZenUIManager.mjs (8 hunks)
  • src/browser/components/preferences/zen-settings.js (2 hunks)
🧰 Additional context used
📓 Learnings (1)
src/browser/base/content/ZenUIManager.mjs (1)
Learnt from: Richard-Woessner
PR: zen-browser/desktop#2263
File: src/browser/base/content/ZenUIManager.mjs:115-117
Timestamp: 2024-10-21T15:48:17.759Z
Learning: In `src/browser/base/content/ZenUIManager.mjs`, prefer using `let` for variable declarations throughout the file to maintain uniformity, even if the variables are not reassigned.
🪛 Biome
src/browser/base/content/ZenUIManager.mjs

[error] 76-239: Use let or const instead of var.

A variable declared with var is accessible in the whole module. Thus, the variable can be accessed before its initialization and outside the block where it is declared.
See MDN web docs for more details.
Unsafe fix: Use 'const' instead.

(lint/style/noVar)

🔇 Additional comments (4)
src/browser/base/content/ZenUIManager.mjs (4)

3-3: Addition of _hoverPausedForExpand property looks good.

The new property _hoverPausedForExpand is properly added to gZenUIManager to manage the hover state during sidebar expansion.


147-148: Event handler correctly references toggleTabsOnRight.

The oncommand event handler in initRightSideOrderContextMenu properly calls the toggleTabsOnRight method, ensuring the context menu functions as intended.


115-136: Sidebar attribute management in _updateOnHoverVerticalTabs appears correct.

The method updates the sidebar's attributes based on the hover settings and expanded state, which should result in the expected UI behavior.


212-232: Toggle logic in toggleExpand method looks good.

The logic correctly handles different scenarios for expanding and collapsing the sidebar, including pausing and resuming hover detection.

@@ -8,11 +9,11 @@ var gZenUIManager = {

openAndChangeToTab(url, options) {
if (window.ownerGlobal.parent) {
let tab = window.ownerGlobal.parent.gBrowser.addTrustedTab(url, options);
const tab = window.ownerGlobal.parent.gBrowser.addTrustedTab(url, options);
Copy link

Choose a reason for hiding this comment

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

🧹 Nitpick (assertive)

Consider using let instead of const for variable declarations to maintain consistency.

Based on the team's coding style preference (as noted in prior learnings), we use let for variable declarations throughout the file for uniformity, even if the variables are not reassigned. This applies to the variable declarations at lines 12, 16, 89, 115-117, 188-191, and 212-214.

Apply these diffs to adjust the variable declarations:

-const tab = window.ownerGlobal.parent.gBrowser.addTrustedTab(url, options);
+let tab = window.ownerGlobal.parent.gBrowser.addTrustedTab(url, options);

-const tab = window.gBrowser.addTrustedTab(url, options);
+let tab = window.gBrowser.addTrustedTab(url, options);

-const tabs = document.getElementById('tabbrowser-tabs');
+let tabs = document.getElementById('tabbrowser-tabs');

-const onHover = Services.prefs.getBoolPref('zen.view.sidebar-expanded.on-hover');
-const expanded = Services.prefs.getBoolPref('zen.view.sidebar-expanded');
-const sidebar = this.navigatorToolbox;
+let onHover = Services.prefs.getBoolPref('zen.view.sidebar-expanded.on-hover');
+let expanded = Services.prefs.getBoolPref('zen.view.sidebar-expanded');
+let sidebar = this.navigatorToolbox;

-const isCompactMode = Services.prefs.getBoolPref('zen.view.compact');
-const expanded = this.expanded;
-const maxWidth = Services.prefs.getIntPref('zen.view.sidebar-expanded.max-width');
-const toolbox = document.getElementById('navigator-toolbox');
+let isCompactMode = Services.prefs.getBoolPref('zen.view.compact');
+let expanded = this.expanded;
+let maxWidth = Services.prefs.getIntPref('zen.view.sidebar-expanded.max-width');
+let toolbox = document.getElementById('navigator-toolbox');

-const pausedForExpand = this._hoverPausedForExpand;
-const onHover = Services.prefs.getBoolPref('zen.view.sidebar-expanded.on-hover');
-const expanded = Services.prefs.getBoolPref('zen.view.sidebar-expanded');
+let pausedForExpand = this._hoverPausedForExpand;
+let onHover = Services.prefs.getBoolPref('zen.view.sidebar-expanded.on-hover');
+let expanded = Services.prefs.getBoolPref('zen.view.sidebar-expanded');

Also applies to: 16-16, 89-89, 115-117, 188-191, 212-214

src/browser/components/preferences/zen-settings.js Outdated Show resolved Hide resolved
@Richard-Woessner
Copy link
Contributor Author

Screen.Recording.2024-10-21.at.11.10.32.AM.mov

@Anthonyy232
Copy link

Any chance of an animation when it is sliding back in? I remember a PR for that a while back but seems like it got closed..

@Richard-Woessner
Copy link
Contributor Author

Ya I messed up this pr so it closed so it hasn't been merged yet

@mr-cheff
Copy link
Member

Thanks a lot!

@mr-cheff mr-cheff merged commit 24d09cc into zen-browser:dev Oct 24, 2024
2 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.

3 participants