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

[WEB-2509] feat: fullscreen option for editor images #5665

Merged
merged 4 commits into from
Sep 23, 2024

Conversation

aaryan610
Copy link
Collaborator

@aaryan610 aaryan610 commented Sep 20, 2024

What's new?

Editor images can now be opened in a full-screen mode. A much requested feature.

Media:

Screen.Recording.2024-09-20.at.14.45.19.mov

GitHub issue: #4458

Plane issue: WEB-2509

Summary by CodeRabbit

Release Notes

  • New Features
    • Introduced ImageToolbarRoot for enhanced image interaction with a dedicated toolbar.
    • Added ImageFullScreenAction for a full-screen image viewing experience with zoom capabilities.
    • Improved export structure for streamlined access to toolbar components.

These updates enhance user experience by providing better image management and viewing options within the application.

Copy link
Contributor

coderabbitai bot commented Sep 20, 2024

Warning

Rate limit exceeded

@aaryan610 has exceeded the limit for the number of commits or files that can be reviewed per hour. Please wait 10 minutes and 20 seconds before requesting another review.

How to resolve this issue?

After the wait time has elapsed, a review can be triggered using the @coderabbitai review command as a PR comment. Alternatively, push new commits to this PR.

We recommend that you space out your commits to avoid hitting the rate limit.

How do rate limits work?

CodeRabbit enforces hourly rate limits for each developer per organization.

Our paid plans have higher rate limits than the trial, open-source and free plans. In all cases, we re-allow further reviews after a brief timeout.

Please see our FAQ for further information.

Commits

Files that changed from the base of the PR and between 7ef1134 and 35451bd.

Walkthrough

The changes introduce a new toolbar component, ImageToolbarRoot, to the CustomImageBlock, enhancing its functionality by providing user interaction options. Additionally, a new full-screen image viewing component, ImageFullScreenAction, is added, allowing users to view images in full-screen mode with zoom capabilities. The updates also include re-exporting mechanisms for better organization of the toolbar components and adjustments to existing files to accommodate these new features.

Changes

Files Change Summary
packages/editor/src/core/extensions/custom-image/components/image-block.tsx Added ImageToolbarRoot component to enhance CustomImageBlock with a toolbar for user interactions.
packages/editor/src/core/extensions/custom-image/components/index.ts Added export statement for the toolbar module, expanding the module's interface.
packages/editor/src/core/extensions/custom-image/components/toolbar/full-screen.tsx Introduced ImageFullScreenAction component for full-screen image viewing with zoom functionality.
packages/editor/src/core/extensions/custom-image/components/toolbar/index.ts Created an index file to re-export all entities from the toolbar module for streamlined imports.
packages/editor/src/core/extensions/custom-image/components/toolbar/root.tsx Added ImageToolbarRoot component to manage image display and full-screen functionality.

Possibly related PRs

🐇 In the garden of code, we play,
New tools and features brighten the day.
With images full-screen, we zoom and glide,
A toolbar to help us, right by our side.
Hopping through changes, we celebrate cheer,
In the world of development, joy is near! 🌼✨


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

Outside diff range and nitpick comments (1)
packages/editor/src/core/extensions/custom-image/components/toolbar/full-screen.tsx (1)

35-42: Consider using window.open() to open the image in a new tab.

Instead of creating a temporary link element, appending it to the document body, triggering a click event, and then removing the link element, you can use the window.open() method to open the image URL directly in a new tab. Here's an example:

const handleOpenInNewTab = () => {
  window.open(src, "_blank");
};

This approach is more straightforward and eliminates the need for manipulating the DOM.

Review details

Configuration used: CodeRabbit UI
Review profile: CHILL

Commits

Files that changed from the base of the PR and between 66cfc73 and 6a00192.

Files selected for processing (5)
  • packages/editor/src/core/extensions/custom-image/components/image-block.tsx (2 hunks)
  • packages/editor/src/core/extensions/custom-image/components/index.ts (1 hunks)
  • packages/editor/src/core/extensions/custom-image/components/toolbar/full-screen.tsx (1 hunks)
  • packages/editor/src/core/extensions/custom-image/components/toolbar/index.ts (1 hunks)
  • packages/editor/src/core/extensions/custom-image/components/toolbar/root.tsx (1 hunks)
Additional comments not posted (9)
packages/editor/src/core/extensions/custom-image/components/toolbar/index.ts (1)

1-1: More context needed to assess relevance to PR objectives.

The export * from "./root"; statement is a standard way to re-export all named exports from the ./root module, creating a single entry point for the directory.

However, without more information about the contents of the ./root module and how it relates to the full-screen image feature mentioned in the PR objectives, it's difficult to determine the impact and relevance of this change.

Please provide additional context or clarify how this re-export contributes to the implementation of the full-screen image functionality.

packages/editor/src/core/extensions/custom-image/components/index.ts (1)

1-1: LGTM!

The new export statement is syntactically correct and aligns with the PR objective of introducing a full-screen option for editor images. The change allows other parts of the application to import the toolbar module from this index file, which likely contains the UI components for the new feature. The change does not appear to have any negative impact on the existing exports.

packages/editor/src/core/extensions/custom-image/components/toolbar/root.tsx (1)

1-36: LGTM!

The ImageToolbarRoot component follows React best practices and implements the full-screen functionality for images in a clean and readable manner. The usage of hooks, destructuring, and conditional styling enhances code clarity and maintainability.

The component effectively integrates with the ImageFullScreenAction component, passing the necessary props to handle the full-screen mode. The toggleFullScreenMode callback allows for seamless state updates.

Overall, the implementation aligns with the PR objectives and introduces the desired full-screen feature for editor images.

packages/editor/src/core/extensions/custom-image/components/toolbar/full-screen.tsx (5)

1-5: LGTM!

The imports are correctly specified and follow the proper syntax. The custom helper function cn is imported from a relative path, indicating it's a project-specific utility.


6-14: LGTM!

The Props type correctly defines the expected properties for the component, including the image object with appropriate property types, the isOpen boolean to indicate the full-screen mode state, and the toggleFullScreenMode function to toggle the full-screen mode.


16-16: LGTM!

The MAGNIFICATION_VALUES array contains a set of predefined magnification levels that provide a good range of options for zooming the image.


18-149: LGTM!

The ImageFullScreenAction component is well-structured and implements the full-screen functionality correctly. Here are the key points:

  • The component correctly handles the props and uses them appropriately.
  • The state management for the magnification level is implemented correctly.
  • The derived values for width, height, and aspect ratio are calculated accurately.
  • The event handlers are defined using useCallback for performance optimization.
  • The keydown event listener is properly registered and removed based on the full-screen mode state.
  • The full-screen overlay is rendered conditionally based on the isOpen prop.
  • The image is displayed with the correct magnification level and aspect ratio.
  • The magnification controls allow increasing and decreasing the magnification level within the defined range.
  • The close button and keydown event handling enable closing the full-screen mode.
  • The button to toggle the full-screen mode is rendered and triggers the toggleFullScreenMode function when clicked.

Overall, the component fulfills its purpose of providing a full-screen view of the image with magnification controls and proper event handling.


67-73: LGTM!

The useEffect hook is used correctly to register and remove the keydown event listener. The handleKeyDown function is added as the event listener when the component mounts, and the cleanup function ensures that the event listener is removed when the component unmounts, preventing any potential memory leaks. The handleKeyDown function is also included in the dependency array, ensuring that the event listener is updated if the function changes.

packages/editor/src/core/extensions/custom-image/components/image-block.tsx (1)

157-164: Excellent addition of the ImageToolbarRoot component!

The introduction of the ImageToolbarRoot component within the CustomImageBlock is a great enhancement. It provides a toolbar for user interactions related to the image block. The positioning and styling of the toolbar ensure a smooth user experience, as it appears on top of the image when hovered, without obstructing the view.

Passing the image prop to the ImageToolbarRoot component is also a smart move, as it allows the toolbar to have access to the necessary image attributes for potential modifications or actions.

Overall, this addition improves the functionality and user experience of the CustomImageBlock component.

Comment on lines 75 to 79
useEffect(() => {
if (!isFullScreenEnabled) {
document.removeEventListener("keydown", handleKeyDown);
}
}, [handleKeyDown]);
Copy link
Contributor

Choose a reason for hiding this comment

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

Remove the redundant useEffect hook.

The useEffect hook at lines 75-79 is redundant and can be removed. The previous useEffect hook (lines 67-73) already handles the registration and removal of the keydown event listener based on the component's lifecycle.

Removing the event listener again when isFullScreenEnabled is false is unnecessary since it is already handled by the cleanup function in the previous useEffect hook.

Additionally, including the handleKeyDown function in the dependency array of this useEffect hook is not needed since the event listener is being removed unconditionally.

@pushya22 pushya22 merged commit 83b8332 into preview Sep 23, 2024
14 of 15 checks passed
@pushya22 pushya22 deleted the feat/image-fullscreen branch September 23, 2024 10:30
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants