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 shortcut key #5396

Merged
merged 6 commits into from
Sep 12, 2024
Merged

Conversation

DDMeaqua
Copy link
Contributor

@DDMeaqua DDMeaqua commented Sep 9, 2024

💻 变更类型 | Change Type

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

🔀 变更说明 | Description of Change

#5135

📝 补充信息 | Additional Information

QQ_1725879673150

Summary by CodeRabbit

  • New Features

    • Introduced a ShortcutKeyModal for displaying keyboard shortcuts within the chat application.
    • Added keyboard shortcuts for actions such as starting a new chat and focusing the input field.
    • Enhanced localization by adding keyboard shortcut information in English, Chinese, and Taiwanese.
  • Style

    • Updated styles for shortcut keys to improve layout and visual presentation in the chat component.

Copy link

vercel bot commented Sep 9, 2024

@DDMeaqua 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 9, 2024

Walkthrough

This pull request introduces enhancements to the chat application, including a new ShortcutKeyModal component for displaying keyboard shortcuts, modifications to the chat component to handle keyboard events, and updates to localization files for shortcut translations in Chinese, English, and Traditional Chinese. Additionally, new CSS styles are added to improve the layout of shortcut keys within the chat interface.

Changes

Files Change Summary
app/components/chat.module.scss Added styles for shortcut key layout, including container, grid, and item classes.
app/components/chat.tsx Introduced ShortcutKeyModal component and modified _Chat to handle keyboard shortcuts.
app/locales/cn.ts Added ShortcutKey object for localized keyboard shortcuts in Chinese.
app/locales/en.ts Added ShortcutKey object for localized keyboard shortcuts in English.
app/locales/tw.ts Added ShortcutKey object for localized keyboard shortcuts in Traditional Chinese.

Poem

In the chat where bunnies hop,
New shortcuts help us never stop.
With a modal bright, keys in sight,
We chat and play, from day to night!
Hooray for keys, both big and small,
A joyful leap, we’ll use them all! 🐇✨

Tip

Announcements
  • The review status is no longer posted as a separate comment when there are no actionable or nitpick comments. In such cases, the review status is included in the walkthrough comment.
  • We have updated our review workflow to use the Anthropic's Claude family of models. Please share any feedback in the discussion post on our Discord.
  • Possibly related PRs: Walkthrough comment now includes a list of potentially related PRs to help you recall past context. Please share any feedback in the discussion post on our Discord.
  • Suggested labels: CodeRabbit can now suggest labels by learning from your past PRs in the walkthrough comment. You can also provide custom labeling instructions in the UI or configuration file.
  • Possibly related PRs, automatic label suggestions based on past PRs, learnings, and possibly related issues require data opt-in (enabled by default).

Recent review details

Configuration used: CodeRabbit UI
Review profile: CHILL

Commits

Files that changed from the base of the PR and between 18e2403 and 45306bb.

Files selected for processing (1)
  • app/components/chat.tsx (7 hunks)
Files skipped from review as they are similar to previous changes (1)
  • app/components/chat.tsx

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>.
    • 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 show all the console.log statements in this repository.
    • @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

Review details

Configuration used: CodeRabbit UI
Review profile: CHILL

Commits

Files that changed from the base of the PR and between 35f77f4 and f219515.

Files selected for processing (5)
  • app/components/chat.module.scss (1 hunks)
  • app/components/chat.tsx (3 hunks)
  • app/locales/cn.ts (2 hunks)
  • app/locales/en.ts (1 hunks)
  • app/locales/tw.ts (1 hunks)
Additional comments not posted (5)
app/locales/tw.ts (1)

84-91: Translations for keyboard shortcuts look good.

The addition of the ShortcutKey object with its respective translations enhances the user experience by providing localized keyboard shortcuts. Ensure that the translations are accurate and culturally appropriate.

Please verify the accuracy of the translations with a native speaker or through user feedback.

app/components/chat.module.scss (1)

650-697: New CSS styles for shortcut keys are well-designed.

The addition of .shortcut-key-container, .shortcut-key-grid, .shortcut-key-item, .shortcut-key-title, .shortcut-key-keys, and .shortcut-key classes enhance the layout and presentation of shortcut keys. Ensure that the styles are responsive and compatible across different browsers and devices.

Please conduct a cross-browser compatibility test to ensure consistent rendering.

app/locales/cn.ts (1)

85-92: Translations for keyboard shortcuts in Chinese look good.

The addition of the ShortcutKey object with its respective translations enhances the user experience by providing localized keyboard shortcuts for Chinese-speaking users. Ensure that the translations are accurate and culturally appropriate.

Please verify the accuracy of the translations with a native speaker or through user feedback.

app/locales/en.ts (1)

86-93: Approved: Shortcut keys localization added.

The addition of the ShortcutKey object with localized strings for the new shortcut keys is correctly implemented. Ensure that similar updates are made across other locale files to maintain consistency.

Verification successful

Localization Consistency Verified: ShortcutKey object is consistent across locales.

The ShortcutKey object is consistently defined across the en.ts, tw.ts, and cn.ts locale files with appropriate translations. This ensures that the shortcut keys are correctly localized for English, Traditional Chinese, and Simplified Chinese users. No further action is required.

Scripts executed

The following scripts were executed for the analysis:

Script:

#!/bin/bash
# Description: Verify that similar updates are made across other locale files.

# Test: Search for `ShortcutKey` in other locale files. Expect: Similar entries in other locale files.
rg --type ts 'ShortcutKey' --files-with-matches

Length of output: 125


Script:

#!/bin/bash
# Extract and display the `ShortcutKey` object from `tw.ts` and `cn.ts` for comparison.

# Extract `ShortcutKey` from `tw.ts`
echo "ShortcutKey in tw.ts:"
rg --type ts --context 5 'ShortcutKey' app/locales/tw.ts

# Extract `ShortcutKey` from `cn.ts`
echo -e "\nShortcutKey in cn.ts:"
rg --type ts --context 5 'ShortcutKey' app/locales/cn.ts

Length of output: 1123

app/components/chat.tsx (1)

832-881: Approved: New ShortcutKeyModal component implemented.

The implementation of the ShortcutKeyModal component is correct and uses localized strings effectively. Consider adding accessibility features such as keyboard navigability and ARIA attributes to enhance usability for all users.

Comment on lines 1430 to 1489
useEffect(() => {
const handleKeyDown = (event) => {
// 打开新聊天 command + shift + o
if (
(event.metaKey || event.ctrlKey) &&
event.shiftKey &&
event.key.toLowerCase() === "o"
) {
event.preventDefault();
setTimeout(() => {
chatStore.newSession();
navigate(Path.Chat);
}, 10);
}
// 聚焦聊天输入 shift + esc
else if (event.shiftKey && event.key.toLowerCase() === "escape") {
event.preventDefault();
inputRef.current?.focus();
}
// 复制最后一个代码块 command + shift + ;
else if (
(event.metaKey || event.ctrlKey) &&
event.shiftKey &&
event.code === "Semicolon"
) {
event.preventDefault();
const copyCodeButton = document.querySelectorAll(".copy-code-button");
if (copyCodeButton.length > 0) {
copyCodeButton[copyCodeButton.length - 1].click();
}
}
// 复制最后一个回复 command + shift + c
else if (
(event.metaKey || event.ctrlKey) &&
event.shiftKey &&
event.key.toLowerCase() === "c"
) {
event.preventDefault();
const lastNonUserMessage = messages
.filter((message) => message.role !== "user")
.pop();
if (lastNonUserMessage) {
const lastMessageContent = getMessageTextContent(lastNonUserMessage);
copyToClipboard(lastMessageContent);
}
}
// 展示快捷键 command + /
else if ((event.metaKey || event.ctrlKey) && event.key === "/") {
event.preventDefault();
setShowShortcutKeyModal(true);
}
};

window.addEventListener("keydown", handleKeyDown);

return () => {
window.removeEventListener("keydown", handleKeyDown);
};
}, [messages, chatStore, navigate]);

Copy link
Contributor

Choose a reason for hiding this comment

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

Suggest improvement: Refine shortcut handling in _Chat.

The handling of keyboard shortcuts in _Chat is functional but could be improved. Consider removing setTimeout for navigation and exploring more React-centric approaches like state transitions or context for managing UI changes. This could enhance performance and maintainability.

Copy link
Member

  1. 提交之前检查一下打包是否成功,有没有ts报错
  2. 这个快捷键,是不是只能在chat页面?如果进入其他页面了,快捷键还能使用吗?例如我在settings页面是否能直接开启新会话?

@Issues-translate-bot
Copy link

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


  1. Before submitting, check whether the packaging is successful and whether there are any ts errors.
  2. Is this shortcut key only available on the chat page? If I enter another page, can the shortcut keys still be used? For example, can I open a new session directly on the settings page?

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

Review details

Configuration used: CodeRabbit UI
Review profile: CHILL

Commits

Files that changed from the base of the PR and between f219515 and 7804182.

Files selected for processing (1)
  • app/components/chat.tsx (3 hunks)
Files skipped from review as they are similar to previous changes (1)
  • app/components/chat.tsx

Copy link
Contributor

github-actions bot commented Sep 9, 2024

Your build has completed!

Preview deployment

@DDMeaqua
Copy link
Contributor Author

DDMeaqua commented Sep 9, 2024

有ts报错现已修复,快捷键只在 chat 页生效

@Issues-translate-bot
Copy link

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


An error reported in ts has been fixed. The shortcut keys only take effect on the chat page.

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

Review details

Configuration used: CodeRabbit UI
Review profile: CHILL

Commits

Files that changed from the base of the PR and between 7804182 and e578c5f.

Files selected for processing (2)
  • app/components/chat.module.scss (1 hunks)
  • app/components/chat.tsx (3 hunks)
Files skipped from review due to trivial changes (1)
  • app/components/chat.module.scss
Files skipped from review as they are similar to previous changes (1)
  • app/components/chat.tsx

@Dogtiti Dogtiti merged commit 1234dea into ChatGPTNextWeb:main Sep 12, 2024
1 of 2 checks passed
@holzora
Copy link

holzora commented Sep 12, 2024

编译看了下,是否隐藏手机端的显示?
IMG_20240912_225309
Screenshot_2024-09-12-22-52-46-360_mark via

@Issues-translate-bot
Copy link

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


After compiling and reading, do you want to hide the display on the mobile phone?
IMG_20240912_225309
Screenshot_2024-09-12-22-52-46-360_mark via

@coderabbitai coderabbitai bot mentioned this pull request Nov 6, 2024
10 tasks
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.

5 participants