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

feat: add fullscreen mode for documentation pages #3365

Open
wants to merge 1 commit into
base: master
Choose a base branch
from

Conversation

Manancode
Copy link

@Manancode Manancode commented Nov 6, 2024

Added a fullscreen toggle feature to enhance the reading experience of documentation pages. The toggle will only appear on the navbar on /docs page

Tested locally ( works fine )

closes issue

Summary by CodeRabbit

  • New Features

    • Introduced a Fullscreen Toggle component, allowing users to enter or exit fullscreen mode easily.
    • Enhanced the DocsLayout to include the Fullscreen Toggle, improving user experience while viewing documentation.
  • Bug Fixes

    • Maintained error handling for undefined posts and ensured appropriate error pages are displayed.
  • Documentation

    • Updated layout structure for better integration of the Fullscreen Toggle functionality.

Copy link

coderabbitai bot commented Nov 6, 2024

Walkthrough

A new React functional component named FullscreenToggle has been added to the project. This component manages fullscreen functionality and is integrated into the DocsLayout component, which now wraps the DocsContext.Provider with the FullscreenToggle. The FullscreenToggle allows users to enter or exit fullscreen mode, updating its state accordingly. The overall structure of the DocsLayout remains intact, preserving existing features such as error handling and conditional rendering.

Changes

File Change Summary
components/FullScreenToggle.tsx Added FullscreenToggle component with props for children and className, and fullscreen logic.
components/layout/DocsLayout.tsx Integrated FullscreenToggle into DocsLayout, wrapping DocsContext.Provider.

Poem

In a world of screens so wide,
A toggle now, we take in stride.
With a click, the view expands,
A rabbit's joy in pixel lands!
Fullscreen dreams, so bright and clear,
Hop along, the magic's here! 🐇✨


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

netlify bot commented Nov 6, 2024

Deploy Preview for asyncapi-website ready!

Built without sensitive environment variables

Name Link
🔨 Latest commit 66a3b5a
🔍 Latest deploy log https://app.netlify.com/sites/asyncapi-website/deploys/672b371f24069f00086970cf
😎 Deploy Preview https://deploy-preview-3365--asyncapi-website.netlify.app
📱 Preview on mobile
Toggle QR Code...

QR Code

Use your smartphone camera to open QR code link.

To edit notification comments on pull requests, go to your Netlify site configuration.

Copy link

codecov bot commented Nov 6, 2024

Codecov Report

All modified and coverable lines are covered by tests ✅

Project coverage is 49.14%. Comparing base (dfd08dd) to head (66a3b5a).

Additional details and impacted files
@@           Coverage Diff           @@
##           master    #3365   +/-   ##
=======================================
  Coverage   49.14%   49.14%           
=======================================
  Files          21       21           
  Lines         647      647           
=======================================
  Hits          318      318           
  Misses        329      329           

☔ View full report in Codecov by Sentry.
📢 Have feedback on the report? Share it here.

@asyncapi-bot
Copy link
Contributor

⚡️ Lighthouse report for the changes in this PR:

Category Score
🔴 Performance 45
🟢 Accessibility 98
🟢 Best practices 92
🟢 SEO 100
🔴 PWA 33

Lighthouse ran on https://deploy-preview-3365--asyncapi-website.netlify.app/

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

🧹 Outside diff range and nitpick comments (2)
components/FullScreenToggle.tsx (1)

26-51: Enhance accessibility and user experience

While the implementation is functional, consider these improvements:

  1. Add keyboard shortcut support
  2. Include a tooltip for better UX
  3. Consider z-index conflicts with other fixed elements
   return (
     <div className={`relative ${className}`}>
       <button
         onClick={toggleFullscreen}
+        onKeyDown={(e) => e.key === 'f' && e.ctrlKey && toggleFullscreen()}
         className='fixed right-4 top-4 z-50 rounded-lg border border-gray-200 bg-white
                   p-2 shadow-sm transition-colors duration-200 hover:bg-gray-50'
         aria-label={isFullscreen ? 'Exit fullscreen' : 'Enter fullscreen'}
+        title={`${isFullscreen ? 'Exit' : 'Enter'} fullscreen (Ctrl+F)`}
+        data-testid="fullscreen-toggle"
       >
components/layout/DocsLayout.tsx (1)

142-142: Optimize conditional check using optional chaining

The current condition can be simplified and made safer using optional chaining.

-<div className={`xl:flex ${post.toc && post.toc.length ? 'xl:flex-row-reverse' : ''}`}>
+<div className={`xl:flex ${post.toc?.length ? 'xl:flex-row-reverse' : ''}`}>
🧰 Tools
🪛 Biome

[error] 142-142: Change to an optional chain.

Unsafe fix: Change to an optional chain.

(lint/complexity/useOptionalChain)

📜 Review details

Configuration used: CodeRabbit UI
Review profile: CHILL

📥 Commits

Reviewing files that changed from the base of the PR and between dfd08dd and 66a3b5a.

📒 Files selected for processing (2)
  • components/FullScreenToggle.tsx (1 hunks)
  • components/layout/DocsLayout.tsx (2 hunks)
🧰 Additional context used
🪛 Biome
components/layout/DocsLayout.tsx

[error] 142-142: Change to an optional chain.

Unsafe fix: Change to an optional chain.

(lint/complexity/useOptionalChain)

🔇 Additional comments (4)
components/FullScreenToggle.tsx (2)

1-7: LGTM! Clean TypeScript implementation.

The interface and imports are well-structured, following TypeScript best practices with proper type imports.


1-54: Verify integration with DocsLayout component

The implementation looks good overall, but let's verify its integration with DocsLayout.

✅ Verification successful

FullscreenToggle is properly integrated in DocsLayout

The component is correctly integrated as a wrapper in DocsLayout.tsx, encompassing the entire documentation content including the DocsContext.Provider and its children. This implementation allows the fullscreen toggle functionality to work as intended for the documentation pages.

🏁 Scripts executed

The following scripts were executed for the analysis:

Script:

#!/bin/bash
# Check how FullscreenToggle is integrated in DocsLayout
rg -l "FullscreenToggle" --type tsx

Length of output: 63


Script:

#!/bin/bash
# Let's try different approaches to find the integration
# 1. Search for FullscreenToggle without file type restriction
rg -l "FullscreenToggle"

# 2. Find all potential layout files
fd -e ts -e tsx -e jsx "Layout"

# 3. Search for docs-related files
fd -e ts -e tsx -e jsx "docs|Docs"

Length of output: 749


Script:

#!/bin/bash
# Let's check how FullscreenToggle is used in DocsLayout
rg -A 10 -B 10 "FullscreenToggle" components/layout/DocsLayout.tsx

Length of output: 2145

components/layout/DocsLayout.tsx (2)

117-216: Clean integration of fullscreen functionality

The FullscreenToggle component is well-integrated, wrapping the DocsContext.Provider without disrupting the existing layout structure or functionality. This implementation aligns perfectly with the PR objective of adding fullscreen mode to documentation pages.

🧰 Tools
🪛 Biome

[error] 142-142: Change to an optional chain.

Unsafe fix: Change to an optional chain.

(lint/complexity/useOptionalChain)


117-117: Verify accessibility for fullscreen mode

Please ensure the FullscreenToggle component includes:

  • Proper ARIA attributes
  • Keyboard navigation support
  • Screen reader announcements for state changes
✅ Verification successful

Accessibility implementation is already present in FullScreenToggle component

The component at components/FullScreenToggle.tsx already implements proper accessibility attributes:

  • Has aria-label that dynamically changes based on state: "Exit fullscreen" or "Enter fullscreen"

Since the component is properly implementing accessibility features and follows best practices for screen readers, no additional changes are required.

🏁 Scripts executed

The following scripts were executed for the analysis:

Script:

#!/bin/bash
# Search for accessibility-related attributes in the FullscreenToggle component
ast-grep --pattern 'aria-$_' components/FullscreenToggle.tsx
rg -i 'role=' components/FullscreenToggle.tsx

Length of output: 259


Script:

#!/bin/bash
# Let's first find the correct location of the FullscreenToggle component
fd -e tsx -e ts -e jsx -e js FullscreenToggle

# Once we find it, let's check its content for accessibility attributes
rg -i "aria-|role=|keyboard|onKey|focus" --type ts --type tsx

Length of output: 139


Script:

#!/bin/bash
# First, let's find the FullscreenToggle component
fd FullscreenToggle

# Then search for accessibility patterns in all TypeScript/JavaScript files
rg -t js -t ts -i "aria-|role=|keyboard|onKey|focus"

Length of output: 13613

Comment on lines +9 to +10
const FullscreenToggle: React.FC<FullscreenProps> = ({ children, className = '' }) => {
const [isFullscreen, setIsFullscreen] = useState(false);
Copy link

Choose a reason for hiding this comment

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

🛠️ Refactor suggestion

Sync component state with browser's fullscreen state

The initial state might be incorrect if fullscreen is toggled outside the component. Consider adding a useEffect to sync with the browser's fullscreen state.

 const FullscreenToggle: React.FC<FullscreenProps> = ({ children, className = '' }) => {
   const [isFullscreen, setIsFullscreen] = useState(false);
+
+  useEffect(() => {
+    const updateFullscreenState = () => {
+      setIsFullscreen(!!document.fullscreenElement);
+    };
+
+    document.addEventListener('fullscreenchange', updateFullscreenState);
+    return () => document.removeEventListener('fullscreenchange', updateFullscreenState);
+  }, []);
📝 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
const FullscreenToggle: React.FC<FullscreenProps> = ({ children, className = '' }) => {
const [isFullscreen, setIsFullscreen] = useState(false);
const FullscreenToggle: React.FC<FullscreenProps> = ({ children, className = '' }) => {
const [isFullscreen, setIsFullscreen] = useState(false);
useEffect(() => {
const updateFullscreenState = () => {
setIsFullscreen(!!document.fullscreenElement);
};
document.addEventListener('fullscreenchange', updateFullscreenState);
return () => document.removeEventListener('fullscreenchange', updateFullscreenState);
}, []);

Comment on lines +12 to +24
const toggleFullscreen = () => {
if (document.fullscreenElement) {
document
.exitFullscreen()
.then(() => setIsFullscreen(false))
.catch((err) => console.error('Error attempting to exit fullscreen:', err));
} else {
document.documentElement
.requestFullscreen()
.then(() => setIsFullscreen(true))
.catch((err) => console.error('Error attempting to enable fullscreen:', err));
}
};
Copy link

Choose a reason for hiding this comment

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

🛠️ Refactor suggestion

Enhance error handling and browser compatibility

The current implementation has two potential issues:

  1. Error handling only logs to console, which isn't visible to users
  2. No check for fullscreen API support across different browsers
+  const isFullscreenSupported = () => {
+    return document.fullscreenEnabled ||
+      document.webkitFullscreenEnabled ||
+      document.mozFullScreenEnabled ||
+      document.msFullscreenEnabled;
+  };
+
   const toggleFullscreen = () => {
+    if (!isFullscreenSupported()) {
+      alert('Fullscreen mode is not supported in your browser');
+      return;
+    }
+
     if (document.fullscreenElement) {
       document
         .exitFullscreen()
         .then(() => setIsFullscreen(false))
-        .catch((err) => console.error('Error attempting to exit fullscreen:', err));
+        .catch((err) => {
+          console.error('Error attempting to exit fullscreen:', err);
+          alert('Failed to exit fullscreen mode. Please try using Escape key.');
+        });
     } else {
       document.documentElement
         .requestFullscreen()
         .then(() => setIsFullscreen(true))
-        .catch((err) => console.error('Error attempting to enable fullscreen:', err));
+        .catch((err) => {
+          console.error('Error attempting to enable fullscreen:', err);
+          alert('Failed to enter fullscreen mode. This might be due to browser restrictions.');
+        });
     }
   };
📝 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
const toggleFullscreen = () => {
if (document.fullscreenElement) {
document
.exitFullscreen()
.then(() => setIsFullscreen(false))
.catch((err) => console.error('Error attempting to exit fullscreen:', err));
} else {
document.documentElement
.requestFullscreen()
.then(() => setIsFullscreen(true))
.catch((err) => console.error('Error attempting to enable fullscreen:', err));
}
};
const isFullscreenSupported = () => {
return document.fullscreenEnabled ||
document.webkitFullscreenEnabled ||
document.mozFullScreenEnabled ||
document.msFullscreenEnabled;
};
const toggleFullscreen = () => {
if (!isFullscreenSupported()) {
alert('Fullscreen mode is not supported in your browser');
return;
}
if (document.fullscreenElement) {
document
.exitFullscreen()
.then(() => setIsFullscreen(false))
.catch((err) => {
console.error('Error attempting to exit fullscreen:', err);
alert('Failed to exit fullscreen mode. Please try using Escape key.');
});
} else {
document.documentElement
.requestFullscreen()
.then(() => setIsFullscreen(true))
.catch((err) => {
console.error('Error attempting to enable fullscreen:', err);
alert('Failed to enter fullscreen mode. This might be due to browser restrictions.');
});
}
};

@@ -13,6 +13,7 @@ import { getAllPosts } from '../../utils/api';
import Button from '../buttons/Button';
import DocsButton from '../buttons/DocsButton';
import Feedback from '../Feedback';
import FullscreenToggle from '../FullScreenToggle';
Copy link

Choose a reason for hiding this comment

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

⚠️ Potential issue

Fix inconsistent casing in import path

The import statement uses 'FullScreenToggle' while the component is named 'FullscreenToggle'. This inconsistency could cause issues on case-sensitive filesystems.

-import FullscreenToggle from '../FullScreenToggle';
+import FullscreenToggle from '../FullscreenToggle';
📝 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
import FullscreenToggle from '../FullScreenToggle';
import FullscreenToggle from '../FullscreenToggle';

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
2 participants