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

fix: add fold-code button when code is expand #5554

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

Conversation

code-october
Copy link
Contributor

@code-october code-october commented Sep 27, 2024

💻 变更类型 | Change Type

  • feat
  • fix
  • refactor
  • perf
  • style
  • test
  • docs
  • ci
  • chore
  • build

🔀 变更说明 | Description of Change

Add a collapse code button when expanding the code to support toggling the code's collapsed state at any time.

📝 补充信息 | Additional Information

Relevant issue:#5284

image

image

Summary by CodeRabbit

  • New Features

    • Simplified toggle button for content visibility, now showing "More" or "Less" based on state.
    • Added localization support for the toggle button in English, Simplified Chinese, and Traditional Chinese.
  • Style

    • Enhanced layout behavior for expanded content with updated alignment properties.

Copy link

vercel bot commented Sep 27, 2024

@code-october is attempting to deploy a commit to the NextChat Team on Vercel.

A member of the Team first needs to authorize it.

Copy link
Contributor

coderabbitai bot commented Sep 27, 2024

Walkthrough

The changes involve updates to the rendering logic of the CustomCode component in the app/components/markdown.tsx file, specifically regarding a toggle button for content visibility. The button's display condition has been simplified, and new localization entries have been added for different languages. Additionally, CSS modifications enhance the layout of the .expanded class, improving content alignment.

Changes

Files Change Summary
app/components/markdown.tsx Updated CustomCode function to simplify toggle button rendering logic and dynamically update text.
app/locales/cn.ts Added Less: "折叠代码" for localization support in Chinese.
app/locales/en.ts Added Less: "Fold Code" for localization support in English.
app/locales/tw.ts Added Less: "收合程式" for localization support in Traditional Chinese.
app/styles/globals.scss Modified .expanded class to set justify-content: flex-end for improved layout behavior.

Possibly related PRs

Suggested reviewers

  • lloydzhou

🐰 In the meadow, the code does play,
With toggles that dance, come what may.
"More" and "Less" in harmony sing,
Localization brings a joyful spring.
Aligning content, a neat little feat,
Hop along, changes make it sweet! 🌼


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

🧹 Outside diff range and nitpick comments (3)
app/components/markdown.tsx (1)

199-205: LGTM! Consider adding aria-label for accessibility.

The changes successfully implement the fold-code button functionality as described in the PR objectives. The button now appears whenever showToggle is true, allowing users to collapse expanded code.

Consider adding an aria-label to the button for better accessibility:

 <button onClick={toggleCollapsed}
+        aria-label={collapsed ? "Show more code" : "Show less code"}
 >
   {collapsed ? Locale.NewChat.More : Locale.NewChat.Less}
 </button>
app/locales/tw.ts (1)

510-510: Approve with a minor suggestion for improvement

The addition of the "Less" translation is correct and aligns with the PR objectives. However, I suggest a small improvement to make it more precise:

-    Less: "收合程式",
+    Less: "收合代碼",

This change from "收合程式" (collapse program) to "收合代碼" (collapse code) more accurately reflects the functionality of collapsing code snippets rather than an entire program.

app/locales/en.ts (1)

691-691: LGTM! Consider a more descriptive key name.

The addition of the "Fold Code" text for the collapse button is correct and aligns with the PR objectives. However, the key name "Less" might be a bit ambiguous without context.

Consider using a more descriptive key name, such as "FoldCode" or "CollapseCode", to improve clarity and maintainability. For example:

-    Less: "Fold Code",
+    FoldCode: "Fold Code",
📜 Review details

Configuration used: CodeRabbit UI
Review profile: CHILL

📥 Commits

Files that changed from the base of the PR and between 870ad91 and 8522759.

📒 Files selected for processing (5)
  • app/components/markdown.tsx (1 hunks)
  • app/locales/cn.ts (1 hunks)
  • app/locales/en.ts (1 hunks)
  • app/locales/tw.ts (1 hunks)
  • app/styles/globals.scss (1 hunks)
🔇 Additional comments (4)
app/styles/globals.scss (1)

334-334: LGTM: Improved layout for expanded code blocks

The addition of justify-content: flex-end; to the .expanded class is appropriate and aligns with the PR objective of adding a fold-code button when code is expanded. This change ensures that the content within expanded code blocks is aligned to the end of the container, which likely improves the positioning of the fold-code button.

app/locales/cn.ts (1)

683-683: LGTM! The new translation entry is consistent and accurate.

The addition of Less: "折叠代码" (which translates to "Collapse code" in English) is consistent with the existing structure of the NewChat object and accurately represents the functionality described in the PR objectives. This new entry will enable users to collapse expanded code snippets, improving the user experience as intended.

app/locales/en.ts (2)

Line range hint 1-694: Summary: Minimal change with no negative impact.

The change introduces a new locale string for the "Fold Code" functionality, which aligns with the PR objectives. The addition is minimal and doesn't affect the overall structure or integrity of the locale file. The implementation is correct, although there are minor suggestions for improvement in terms of key naming and placement.


691-691: Verify the placement and usage of the new string.

The new "Fold Code" string is added to the NewChat section. However, based on the PR objectives, this button appears when code is expanded, which might occur in various parts of the application, not just in new chats.

Could you please confirm if this string is only used in the context of new chats, or if it's a general-purpose string used throughout the application? If it's the latter, consider moving it to a more general section of the locale object for better organization and easier maintenance.

To help verify this, you can run the following script to search for usages of this new locale string:

This will help us understand where and how the new string is being used across the application.

✅ Verification successful

The placement of the "Fold Code" string is verified and appropriate.
Currently, "Fold Code" is only defined in the NewChat section of the locale object and is not used elsewhere in the application. This placement aligns with its intended use for the button that appears when code is expanded within new chats.

🏁 Scripts executed

The following scripts were executed for the analysis:

Script:

#!/bin/bash
# Description: Search for usages of the new "Less" locale string

# Test: Search for "Less" usage in TypeScript and JavaScript files
rg --type-add 'web:*.{ts,tsx,js,jsx}' --type web -i 'Less.*["|'\'']Fold Code' ./app

Length of output: 128

Copy link
Contributor

Your build has completed!

Preview deployment

@lloydzhou
Copy link
Contributor

查看全部在顶部,居中。
所以,折叠收起,应该在底部居中,应该同样有一个遮罩层,只是颜色渐变是相反的。

@Issues-translate-bot
Copy link

Bot detected the issue body's language is not English, translate it automatically.


See all at the top, centered.
So, folded, it should be centered at the bottom, and it should also have a mask layer, just with the color gradient reversed.

@code-october
Copy link
Contributor Author

code-october commented Sep 27, 2024

@lloydzhou 我移动到右上角,主要是担心提示文字居中会遮挡代码,影响阅读代码观感,这再加上遮罩,感觉观感更差了 ?

@Issues-translate-bot
Copy link

Bot detected the issue body's language is not English, translate it automatically.


I moved it to the upper right corner, mainly because I was worried that the centering of the prompt text would block the code and affect the look and feel of reading the code. Coupled with the mask, the look and feel would be worse?

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