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

Fit text #1217

Merged
merged 2 commits into from
Sep 23, 2024
Merged

Fit text #1217

merged 2 commits into from
Sep 23, 2024

Conversation

cpvalente
Copy link
Owner

This PR resolves the issue with fullscreen messages going off-screen as described in #1067 .
The proposed library seemed abandoned and targetting react 16.5, so I have decided to copy the code into our code base and simplify it

It also changes the code in the studio-clock to use the same process

Screenshot 2024-09-18 at 22 22 39

Copy link
Contributor

coderabbitai bot commented Sep 18, 2024

Walkthrough

The changes introduce a new FitText component that dynamically adjusts the font size of text based on the available space within its container. This component is integrated into the StudioClock and Timer components, replacing the previous static text rendering. Additionally, styling adjustments are made to enhance layout and responsiveness across various components, including the .next-title and .message-overlay classes.

Changes

Files Change Summary
apps/client/src/common/components/fit-text/FitText.tsx Introduced FitText component for dynamic font sizing based on container space.
apps/client/src/common/components/fit-text/fitText.utils.ts Added bsearch utility function for efficient boundary searching within a specified range.
apps/client/src/features/viewers/studio/StudioClock.scss Modified .next-title class with specific height and width for improved layout.
apps/client/src/features/viewers/studio/StudioClock.tsx Removed useFitText hook; integrated FitText component directly for dynamic title rendering.
apps/client/src/features/viewers/timer/Timer.scss Updated .message-overlay and .message classes for improved styling and responsiveness.
apps/client/src/features/viewers/timer/Timer.tsx Wrapped message text in FitText component to dynamically adjust font size based on available space.
apps/client/src/theme/_viewerDefs.scss Removed variable $viewer-overlay-bg-color, indicating a simplification in theme styles for overlays.

Possibly related issues

  • Scale message to fit in Timer #1067: The changes directly address the issue of message overflow in the Timer view by implementing the FitText component to ensure text fits within the screen.

Possibly related PRs

  • refactor: remove size limits in title #1093: Directly relates to the removal of useFitText and the introduction of FitText in StudioClock.tsx, indicating a connection in the implementation of dynamic text fitting.
  • show time in block #1158: Shows the use of the FitText component in Timer.tsx, aligning with the main PR's introduction of the component for dynamic font sizing.
  • refactor: add options to hide schedule #1203: Involves conditional rendering in StudioClock.tsx, which may relate to the integration of the FitText component and enhance the user interface experience.

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 generate interesting stats about this repository and render them as a table.
    -- @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.

Tip

Early access features: enabled

We are currently testing the following features in early access:

  • OpenAI o1 for code reviews: OpenAI's new o1 model is being tested for code reviews. This model has advanced reasoning capabilities and can provide more nuanced feedback on your code.

Note:

  • You can enable or disable early access features from the CodeRabbit UI or by updating the CodeRabbit configuration file.

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 (1)
apps/client/src/common/components/fit-text/fitText.utils.ts (1)

1-5: Clarify function documentation for better understanding

The documentation comments for the bsearch function could be clearer. Specifically, the description of the low parameter might confuse readers. Consider rephrasing to explicitly state that the predicate must return true for the low value.

Apply the following changes to improve the comments:

/**
- * @param low inclusive, must be true on predicate function
+ * @param low Inclusive lower bound of the search range. The predicate must return `true` for this value.
- * @param high exclusive,
+ * @param high Exclusive upper bound of the search range.
- * @param predicate predicate function
+ * @param predicate A function that takes a number and returns a boolean. Determines the condition for the search.
 */
Review details

Configuration used: CodeRabbit UI
Review profile: CHILL

Commits

Files that changed from the base of the PR and between 5b47198 and 879838d.

Files selected for processing (8)
  • apps/client/src/common/components/fit-text/FitText.tsx (1 hunks)
  • apps/client/src/common/components/fit-text/fitText.utils.ts (1 hunks)
  • apps/client/src/common/hooks/useFitText.ts (0 hunks)
  • apps/client/src/features/viewers/studio/StudioClock.scss (1 hunks)
  • apps/client/src/features/viewers/studio/StudioClock.tsx (3 hunks)
  • apps/client/src/features/viewers/timer/Timer.scss (1 hunks)
  • apps/client/src/features/viewers/timer/Timer.tsx (2 hunks)
  • apps/client/src/theme/_viewerDefs.scss (0 hunks)
Files not reviewed due to no reviewable changes (2)
  • apps/client/src/common/hooks/useFitText.ts
  • apps/client/src/theme/_viewerDefs.scss
Additional comments not posted (9)
apps/client/src/common/components/fit-text/fitText.utils.ts (1)

6-18: Binary search implementation is correct and efficient

The bsearch function correctly implements a binary search algorithm to find the boundary where the predicate condition changes. The use of Math.floor and the check for mid === low effectively prevent infinite loops for adjacent values.

apps/client/src/common/components/fit-text/FitText.tsx (1)

16-63: FitText component effectively adjusts text to fit container

The FitText component correctly utilizes a binary search to adjust the font size of its children to fit within the container without overflow. The implementation using useCallback, useEffect, and ResizeObserver ensures responsiveness to size changes.

apps/client/src/features/viewers/studio/StudioClock.tsx (2)

35-45: Preventing FOUC by deferring rendering until stylesheets load

Introducing the shouldRender check effectively prevents the component from rendering before the necessary stylesheets are loaded, mitigating the Flash of Unstyled Content (FOUC) issue and improving user experience.


82-82: Simplified title rendering with FitText component

Replacing the previous title rendering logic with the FitText component simplifies the code and ensures the next event title dynamically resizes to fit the available space, enhancing readability.

apps/client/src/features/viewers/timer/Timer.scss (2)

174-178: Adjusted .message-overlay styles for proper layering and responsiveness

Updating the .message-overlay class by removing fixed width and height, adjusting padding, setting the background using a CSS variable, and increasing z-index to 2 ensures the overlay covers the full viewport and appears above other elements. The simplified transition on opacity enhances performance.


186-191: Centered message content using CSS Grid for better alignment

Changing the .message class to use display: grid and place-content: center efficiently centers the message content both vertically and horizontally. Setting height and width to 100% ensures the grid occupies the full overlay area.

apps/client/src/features/viewers/studio/StudioClock.scss (1)

123-125: Defined dimensions for .next-title to improve layout consistency

Adding explicit height: 12.5vh and width: 70% to the .next-title class provides better control over the element's size, ensuring consistent presentation across different screen sizes and preventing layout shifts.

apps/client/src/features/viewers/timer/Timer.tsx (2)

16-16: Imported FitText component for dynamic text fitting

Importing the FitText component allows for dynamic resizing of text elements, improving the adaptability of the timer's message overlay.


167-169: Enhanced message overlay with dynamic text sizing

Wrapping the message text within the FitText component ensures that the text automatically adjusts its font size to fit within the overlay, enhancing readability across different screen sizes and preventing text overflow.

@cpvalente cpvalente merged commit 92a16ea into master Sep 23, 2024
4 checks passed
@cpvalente cpvalente deleted the fit-text branch September 23, 2024 14:56
@coderabbitai coderabbitai bot mentioned this pull request Oct 6, 2024
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.

2 participants