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 option to toggle Scroll Sync On/Off #394

Merged
merged 2 commits into from
Nov 1, 2024
Merged

Conversation

devleejb
Copy link
Member

@devleejb devleejb commented Oct 31, 2024

What this PR does / why we need it:
image

This PR introduces an option to toggle the Scroll Sync feature on or off. Previously, the Scroll Sync functionality was always enabled, which caused issues with improper scrolling for users, especially in cases where the application is used by a large number of users.

With this change, users now have the ability to disable Scroll Sync, allowing for a more controlled scrolling experience.

Which issue(s) this PR fixes:

Fixes #

Special notes for your reviewer:

Does this PR introduce a user-facing change?:

NONE

Additional documentation:


Checklist:

  • Added relevant tests or not required
  • Didn't break anything

Summary by CodeRabbit

  • New Features

    • Introduced a popover menu in the Document Header for enhanced user interaction.
    • Added a new component for managing theme and scroll synchronization settings.
    • Enabled configuration-dependent scroll synchronization control.
  • Bug Fixes

    • Improved strictness in theme comparisons for better reliability.
  • Chores

    • Updated configuration state management to include scroll synchronization settings.

Copy link
Contributor

coderabbitai bot commented Oct 31, 2024

Walkthrough

This pull request introduces several changes across multiple components in the frontend of the application. The DocumentView component now conditionally manages scroll synchronization based on a new configuration state. The DocumentHeader component has been enhanced with a popover menu for additional user interactions. A new DocumentPopover component has been created to manage theme and scroll synchronization settings. Additionally, the Redux store's configuration slice has been updated to include a property for disabling scroll synchronization, along with a corresponding reducer.

Changes

File Change Summary
frontend/src/components/editor/DocumentView.tsx - Added import for selectConfig.
- Introduced configStore using useSelector.
- Updated ScrollSync component to conditionally set the enabled prop based on disableScrollSync.
frontend/src/components/headers/DocumentHeader.tsx - Added imports for useState, DocumentPopover, and MoreVertIcon.
- Introduced state variable moreButtonanchorEl.
- Added handleMoreButtonClick and handleDocumentMenuClose methods.
- Updated JSX structure.
frontend/src/components/popovers/DocumentPopover.tsx - New component created for popover functionality, managing theme and scroll synchronization settings.
- Added handlers for toggling theme and scroll sync, with a menu structure for user interaction.
frontend/src/store/configSlice.ts - Added disableScrollSync boolean property to ConfigState interface.
- Initialized disableScrollSync in initialState.
- Added setDisableScrollSync reducer method.
- Updated export statement for actions.
frontend/src/components/editor/Editor.tsx - Changed equality check from == to === for themeMode comparison.
frontend/src/components/popovers/ProfilePopover.tsx - Changed equality check from == to === for themeMode comparison in handleChangeTheme.

Possibly related PRs

🐇 In the meadow where changes bloom,
A popover dances, dispelling gloom.
Scrolls now sync or take a break,
With themes that shift like a gentle lake.
User joy is what we seek,
In every click, a new technique! 🌼

Suggested labels

enhancement 🌟


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

🧹 Outside diff range and nitpick comments (2)
frontend/src/store/configSlice.ts (1)

20-20: LGTM! Consider the property naming.

The boolean property is appropriately typed for a toggle feature. While the negative state naming (disableScrollSync vs enableScrollSync) is acceptable, it might require careful attention when implementing the toggle logic to avoid double negatives.

frontend/src/components/headers/DocumentHeader.tsx (1)

46-46: Consider adding type safety enhancement.

The state and handlers are well-implemented following React and Material-UI patterns.

Consider using a more specific type for the anchor element state:

- const [moreButtonanchorEl, setMoreButtonAnchorEl] = useState<HTMLButtonElement | null>(null);
+ const [moreButtonanchorEl, setMoreButtonAnchorEl] = useState<HTMLElement | null>(null);

This makes it more flexible if you decide to change the anchor element type in the future.

Also applies to: 88-94

📜 Review details

Configuration used: CodeRabbit UI
Review profile: CHILL

📥 Commits

Reviewing files that changed from the base of the PR and between 265c0ea and b6d639e.

📒 Files selected for processing (4)
  • frontend/src/components/editor/DocumentView.tsx (2 hunks)
  • frontend/src/components/headers/DocumentHeader.tsx (5 hunks)
  • frontend/src/components/popovers/DocumentPopover.tsx (1 hunks)
  • frontend/src/store/configSlice.ts (2 hunks)
🔇 Additional comments (10)
frontend/src/store/configSlice.ts (4)

27-27: LGTM! Default value maintains backward compatibility.

Setting disableScrollSync to false by default ensures that existing users maintain their current scroll sync behavior, which is a good practice for introducing toggleable features.


43-45: LGTM! Clean and type-safe implementation.

The reducer follows Redux best practices with proper typing and a straightforward implementation appropriate for a toggle feature.


49-50: LGTM! Export statement properly includes the new action.

The new action is correctly exported alongside existing actions, maintaining consistency with the file's structure.


Line range hint 20-50: Verify the configuration usage in components.

The Redux configuration changes look good, but let's verify that components are properly consuming this configuration.

✅ Verification successful

Configuration is properly integrated and consumed by components

The verification shows proper implementation and usage of the disableScrollSync configuration:

  • DocumentPopover.tsx correctly toggles the setting via Redux dispatch
  • DocumentView.tsx properly consumes the configuration to enable/disable scroll sync functionality
  • The implementation follows Redux patterns and maintains consistency
🏁 Scripts executed

The following scripts were executed for the analysis:

Script:

#!/bin/bash
# Description: Verify proper usage of the scroll sync configuration in components

# Search for usages of the configuration selector
echo "Checking for configuration selector usage:"
rg -l "selectConfig|useSelector.*config" frontend/src/

# Search for direct references to disableScrollSync
echo -e "\nChecking for disableScrollSync references:"
rg -l "disableScrollSync" frontend/src/

Length of output: 766


Script:

#!/bin/bash
# Let's examine how disableScrollSync is being used in the components

echo "Checking DocumentPopover.tsx implementation:"
rg "disableScrollSync" frontend/src/components/popovers/DocumentPopover.tsx -B 2 -A 2

echo -e "\nChecking DocumentView.tsx implementation:"
rg "disableScrollSync" frontend/src/components/editor/DocumentView.tsx -B 2 -A 2

# Let's also verify the selector pattern being used
echo -e "\nChecking selector usage pattern:"
rg "useSelector.*config" frontend/src/ -B 1 -A 1

Length of output: 962

frontend/src/components/popovers/DocumentPopover.tsx (2)

17-21: LGTM! Clean and proper hooks setup.

The component is well-structured with proper typing and hook usage.


1-64: Verify Redux store integration.

The component implements the scroll sync toggle UI as intended. Let's verify the Redux store integration:

✅ Verification successful

Redux store integration is properly implemented

The verification confirms:

  • The Redux store correctly implements disableScrollSync state in configSlice.ts with proper initialization and reducer
  • The state is correctly consumed in DocumentView.tsx to control the ScrollSync component
  • The toggle in DocumentPopover.tsx properly dispatches state changes through the Redux store

The implementation aligns with the PR objectives and maintains proper state management integration.

🏁 Scripts executed

The following scripts were executed for the analysis:

Script:

#!/bin/bash
# Check if configSlice properly implements the scroll sync state
rg -l "disableScrollSync" --type ts

Length of output: 170


Script:

#!/bin/bash
# Check configSlice implementation
rg "disableScrollSync" frontend/src/store/configSlice.ts -A 5 -B 5

# Check how DocumentView uses the scroll sync state
rg "disableScrollSync" frontend/src/components/editor/DocumentView.tsx -A 5 -B 5

Length of output: 1154

frontend/src/components/editor/DocumentView.tsx (2)

9-14: LGTM: Clean store integration

The new configuration store integration follows Redux best practices and maintains consistency with existing patterns.


28-28: Implementation looks good, verify edge cases

The ScrollSync toggle implementation correctly uses the configuration state. However, please verify:

  1. Scroll position behavior when toggling sync while content is scrolled
  2. Multi-user experience when different users have different sync settings

Let's check for any existing scroll position handling code:

✅ Verification successful

ScrollSync implementation is robust and safe

The implementation is well-structured and handles scroll syncing appropriately:

  • ScrollSync state is managed through Redux store with proper initialization (default: enabled)
  • Toggle functionality is properly implemented in DocumentPopover
  • ScrollSyncPane components are correctly wrapped around both editor and preview content
  • The library react-scroll-sync handles the scroll position management internally

The concerns raised in the review comment can be addressed:

  1. Scroll position during toggle: The ScrollSync component from react-scroll-sync handles this internally by design
  2. Multi-user experience: The sync setting is client-side only and doesn't affect other users' views
🏁 Scripts executed

The following scripts were executed for the analysis:

Script:

#!/bin/bash
# Search for scroll position management code
rg -l 'scroll(Top|Left|Position|Into)' --type tsx --type ts

Length of output: 89


Script:

#!/bin/bash
# Search for scroll-related code with proper extension patterns
rg -l 'scroll(Top|Left|Position|Into)' -g '*.tsx' -g '*.ts'

# Also search for ScrollSync component usage and implementation
rg -C 3 'ScrollSync' -g '*.tsx' -g '*.ts'

Length of output: 7858

frontend/src/components/headers/DocumentHeader.tsx (2)

17-17: LGTM: Import statements are properly organized.

The new imports are correctly placed and all are utilized within the component.

Also applies to: 30-31


164-168: Verify scroll sync toggle implementation in DocumentPopover.

Let's ensure the DocumentPopover component properly implements the scroll sync toggle functionality as per PR objectives.

✅ Verification successful

DocumentPopover correctly implements scroll sync toggle functionality

The component properly implements the scroll sync toggle feature with:

  • A menu item for Panel Scroll Sync with toggle button UI
  • Correct state management using Redux (setDisableScrollSync)
  • Visual feedback with ToggleOn/ToggleOff icons based on current state
  • Proper handler (handleScrollSyncChange) to toggle the functionality
🏁 Scripts executed

The following scripts were executed for the analysis:

Script:

#!/bin/bash
# Check if DocumentPopover implements scroll sync toggle
ast-grep --pattern 'function DocumentPopover' -A 20

Length of output: 53


Script:

#!/bin/bash
# Let's try to find the DocumentPopover component definition with a more flexible pattern
ast-grep --pattern 'const DocumentPopover = ' -A 20

# Also search for the file containing DocumentPopover
fd "DocumentPopover" --type f

# Search for scroll sync related code in the component
rg -l "scroll.*sync" --type ts --type tsx

Length of output: 208


Script:

#!/bin/bash
# Let's examine the DocumentPopover component content
cat frontend/src/components/popovers/DocumentPopover.tsx

# Search for scroll sync related code with correct file type
rg -l "scroll.*sync" -t ts -t typescript

Length of output: 1869

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

🧹 Outside diff range and nitpick comments (2)
frontend/src/components/popovers/ProfilePopover.tsx (1)

35-35: Consider enhancing accessibility for theme toggle.

While the logic is correct, consider adding an aria-label to improve accessibility.

-		dispatch(setTheme(themeMode === ThemeType.LIGHT ? ThemeType.DARK : ThemeType.LIGHT));
+		const newTheme = themeMode === ThemeType.LIGHT ? ThemeType.DARK : ThemeType.LIGHT;
+		dispatch(setTheme(newTheme));
+		// Update aria-label on theme change
+		document.querySelector('button[aria-label*="theme"]')?.setAttribute('aria-label', `Switch to ${newTheme === ThemeType.LIGHT ? 'dark' : 'light'} theme`);
frontend/src/components/editor/Editor.tsx (1)

Line range hint 124-136: Implement scroll sync toggle functionality.

The PR aims to add scroll sync toggle functionality, but the ScrollSyncPane component is still unconditionally rendered. This component should respect the user's scroll sync preference from the Redux store.

Consider implementing the toggle like this:

+ const { isScrollSyncDisabled } = useSelector(selectConfig);
  return (
    <>
      <div style={{ height: `calc(100% - ${BOTTOM_BAR_HEIGHT}px)` }}>
-       <ScrollSyncPane>
+       {isScrollSyncDisabled ? (
          <div
            style={{
              height: "100%",
              overflow: "auto",
            }}
          >
            {/* ... content ... */}
          </div>
+       ) : (
+         <ScrollSyncPane>
+           <div
+             style={{
+               height: "100%",
+               overflow: "auto",
+             }}
+           >
+             {/* ... content ... */}
+           </div>
+         </ScrollSyncPane>
+       )}
-       </ScrollSyncPane>
      </div>
      <EditorBottomBar width={width} />
    </>
  );
📜 Review details

Configuration used: CodeRabbit UI
Review profile: CHILL

📥 Commits

Reviewing files that changed from the base of the PR and between b6d639e and 37ae1dc.

📒 Files selected for processing (3)
  • frontend/src/components/editor/Editor.tsx (1 hunks)
  • frontend/src/components/popovers/DocumentPopover.tsx (1 hunks)
  • frontend/src/components/popovers/ProfilePopover.tsx (1 hunks)
🚧 Files skipped from review as they are similar to previous changes (1)
  • frontend/src/components/popovers/DocumentPopover.tsx
🔇 Additional comments (2)
frontend/src/components/popovers/ProfilePopover.tsx (1)

35-35: LGTM! Improved type safety with strict equality.

The change from loose (==) to strict (===) equality is a good practice in TypeScript, ensuring both value and type checking.

frontend/src/components/editor/Editor.tsx (1)

80-80: LGTM! Good improvement in type safety.

The change from == to === for theme comparison is a positive improvement, enforcing strict equality checks which is a TypeScript best practice.

@devleejb devleejb merged commit 20a84cf into main Nov 1, 2024
2 checks passed
@devleejb devleejb deleted the scroll-sync-options branch November 1, 2024 02:31
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
Status: Done
Development

Successfully merging this pull request may close these issues.

1 participant