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

添加点击复制到 Clipboard 的能力 #897

Closed
wants to merge 2 commits into from
Closed

Conversation

Ghost-chu
Copy link
Collaborator

@Ghost-chu Ghost-chu commented Jan 13, 2025

新增组件 vue-clipboard3

Summary by CodeRabbit

  • 新功能

    • 在多个视图中添加了复制 InfoHash 到剪贴板的功能
    • 用户现在可以通过点击 InfoHash 直接复制到剪贴板
  • 依赖项

    • 新增 vue-clipboard3 库,用于实现剪贴板功能
  • 本地化

    • 为复制 InfoHash 添加了中英文本地化提示消息
    • 更新了部分现有的本地化文本以提高准确性
  • 用户体验

    • 增加了复制 InfoHash 时的成功提示
    • 提供了更方便的哈希值复制方式

@Ghost-chu Ghost-chu requested a review from a team as a code owner January 13, 2025 12:46
Copy link
Contributor

coderabbitai bot commented Jan 13, 2025

概述

演练

此拉取请求引入了一个新的剪贴板功能,允许用户在多个视图(禁止列表、数据视图的禁止日志和种子列表)中通过点击轻松复制信息哈希值。为实现此功能,添加了 vue-clipboard3 依赖,并在相关组件中集成了复制方法和本地化消息,提供了一个简单直观的用户交互方式。

变更

文件路径 变更摘要
webui/package.json 添加 vue-clipboard3 依赖
webui/src/views/*/components/*.vue 添加复制到剪贴板功能,包括 copyToClipboard 方法和点击事件处理
webui/src/views/*/locale/*.ts 添加剪贴板复制成功的本地化消息

建议的审阅者

  • paulzzh
  • Gaojianli

可能相关的 PR

  • v7.3.1 #895:涉及下载器暂停状态的复选框选项,与本 PR 在 WebUI 用户交互和状态管理方面有相似之处

📜 Recent review details

Configuration used: CodeRabbit UI
Review profile: CHILL
Plan: Pro

📥 Commits

Reviewing files that changed from the base of the PR and between d320bfe and b4ee73d.

📒 Files selected for processing (1)
  • webui/src/views/banlist/locale/en-US.ts (1 hunks)
🚧 Files skipped from review as they are similar to previous changes (1)
  • webui/src/views/banlist/locale/en-US.ts
⏰ Context from checks skipped due to timeout of 90000ms (2)
  • GitHub Check: Build_Installers / install4jc
  • GitHub Check: Cloudflare Pages

🪧 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 generate docstrings to generate docstrings for this PR. (Beta)
  • @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: 3

🔭 Outside diff range comments (1)
webui/src/views/data-view/banlog/components/banlogTable.vue (1)

Line range hint 128-144: 建议提取共享函数并改进错误处理!

  1. copyToClipboard 函数在多个组件中重复,建议提取到共享工具文件中
  2. 当复制失败时,应该向用户显示错误消息

建议创建 utils/clipboard.ts 文件:

import { Message } from '@arco-design/web-vue'
import useClipboard from 'vue-clipboard3'

export const copyToClipboard = async (text: string, successMessage: string) => {
  const { toClipboard } = useClipboard()
  try {
    await toClipboard(text)
    Message.success({
      content: successMessage,
      resetOnHover: true
    })
  } catch (e) {
    console.error(e)
    Message.error({
      content: '复制到剪贴板失败',
      resetOnHover: true
    })
  }
}
🧹 Nitpick comments (4)
webui/src/views/data-view/banlog/locale/en-US.ts (1)

15-15: 建议统一中英文消息格式

英文消息中的格式与中文版本不一致:

  • 中文版本:InfoHash: {hash} 已复制到剪贴板
  • 英文版本:InfoHash: {hash} has been copied to the clipboard

建议修改英文版本以保持一致的风格:

-  'page.banlog.hashCopiedToClipboard': 'InfoHash: {hash} has been copied to the clipboard'
+  'page.banlog.hashCopiedToClipboard': 'InfoHash:{hash} copied to clipboard'
webui/src/views/data-view/banlog/components/banlogTable.vue (1)

68-74: 代码实现正确,建议改进用户体验!

点击复制功能的实现正确。建议添加视觉反馈(如鼠标指针变化)来提示用户该文本是可点击的。

 <template #torrentName="{ record }">
   <a-tooltip :content="record.torrentInfoHash">
     <a-typography-text ellipsis @click="copyToClipboard(record.torrentInfoHash)"
+      style="cursor: pointer"
     >{{
       record.torrentName
     }}</a-typography-text>
webui/src/views/data-view/torrentList/components/torrentTable.vue (1)

37-42: 实现正确,建议保持一致性!

点击复制功能实现正确。code 属性提供了良好的视觉反馈,建议在其他使用复制功能的组件中也采用相同的样式。

webui/src/views/banlist/components/banListItem.vue (1)

140-144: 建议添加视觉反馈!

点击复制功能实现正确,但缺少视觉反馈来提示用户该文本是可点击的。

 <a-typography-text
   style="margin-bottom: 0"
   :ellipsis="{ showTooltip: true }"
+  style="cursor: pointer"
   @click="copyToClipboard(item.banMetadata.torrent.hash)"
 >
📜 Review details

Configuration used: CodeRabbit UI
Review profile: CHILL
Plan: Pro

📥 Commits

Reviewing files that changed from the base of the PR and between cfc5169 and d320bfe.

⛔ Files ignored due to path filters (1)
  • webui/pnpm-lock.yaml is excluded by !**/pnpm-lock.yaml
📒 Files selected for processing (10)
  • webui/package.json (1 hunks)
  • webui/src/views/banlist/components/banListItem.vue (3 hunks)
  • webui/src/views/banlist/locale/en-US.ts (1 hunks)
  • webui/src/views/banlist/locale/zh-CN.ts (1 hunks)
  • webui/src/views/data-view/banlog/components/banlogTable.vue (5 hunks)
  • webui/src/views/data-view/banlog/locale/en-US.ts (1 hunks)
  • webui/src/views/data-view/banlog/locale/zh-CN.ts (1 hunks)
  • webui/src/views/data-view/torrentList/components/torrentTable.vue (2 hunks)
  • webui/src/views/data-view/torrentList/locale/en-US.ts (1 hunks)
  • webui/src/views/data-view/torrentList/locale/zh-CN.ts (1 hunks)
✅ Files skipped from review due to trivial changes (1)
  • webui/src/views/data-view/torrentList/locale/en-US.ts
⏰ Context from checks skipped due to timeout of 90000ms (7)
  • GitHub Check: Analyze (java-kotlin)
  • GitHub Check: Build_Installers / install4jc
  • GitHub Check: Build_SPK / pkgcreate
  • GitHub Check: Build_PKG / pkg (14.1)
  • GitHub Check: Build_PKG / pkg (13.4)
  • GitHub Check: Build_Docker
  • GitHub Check: Cloudflare Pages
🔇 Additional comments (5)
webui/src/views/data-view/banlog/locale/zh-CN.ts (1)

14-15: 消息格式和翻译正确!

消息格式保持一致,使用了正确的中文标点符号,翻译准确清晰。

webui/src/views/banlist/locale/zh-CN.ts (1)

23-24: 翻译和格式保持一致!

与 banlog 模块的中文翻译保持一致,使用了统一的消息格式。

webui/src/views/data-view/torrentList/locale/zh-CN.ts (1)

26-27: 代码变更正确!

添加了剪贴板复制成功的本地化消息,并修复了缺失的逗号。

webui/package.json (2)

40-40: 验证 vue-clipboard3 的版本兼容性

当前使用的是 ^2.0.0 版本约束。请确保此版本与项目中的 Vue 3.5.13 完全兼容。

✅ Verification successful

vue-clipboard3 与 Vue 3.5.13 完全兼容

vue-clipboard3 是专门为 Vue 3 开发的库,且目前在项目中的使用方式完全符合其设计意图(Composition API)。经检查,当前版本 ^2.0.0 可以安全使用。

🏁 Scripts executed

The following scripts were executed for the analysis:

Script:

#!/bin/bash
# 检查 vue-clipboard3 的版本兼容性信息
npm info vue-clipboard3 peerDependencies

# 检查是否有已知的安全问题
npm audit [email protected]

Length of output: 427


Script:

#!/bin/bash
# Check Vue version in package.json
echo "Vue version in package.json:"
cat webui/package.json | grep '"vue":'

# Look for vue-clipboard3 usage in the codebase
echo -e "\nUsage patterns:"
rg "vue-clipboard3" -A 2 -B 2

# Check package documentation
echo -e "\nREADME content:"
curl -s https://raw.githubusercontent.com/JamieCurnow/vue-clipboard3/master/README.md | head -n 20

Length of output: 3412


40-40: 请检查剪贴板依赖项的重复性

项目中已经存在 copy-to-clipboard 包,现在又添加了 vue-clipboard3。建议评估是否可以统一使用其中一个依赖项,以减少包大小和维护成本。

让我们验证这两个包的大小和功能重叠:

webui/src/views/banlist/locale/en-US.ts Outdated Show resolved Hide resolved
Comment on lines +187 to +198
const copyToClipboard = async (toCopyText: string) => {
try {
await toClipboard(toCopyText)
console.log('Copied to clipboard: ' + toCopyText)
Message.success({
content: t('page.banlist.banlist.listItem.hashCopiedToClipboard', { hash: toCopyText }),
resetOnHover: true
})
} catch (e) {
console.error(e)
}
}
Copy link
Contributor

Choose a reason for hiding this comment

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

🛠️ Refactor suggestion

建议复用共享的复制函数!

这个复制功能的实现与其他组件重复。建议使用共享的 utils/clipboard.ts 中的函数。

-const copyToClipboard = async (toCopyText: string) => {
-  try {
-    await toClipboard(toCopyText)
-    console.log('Copied to clipboard: ' + toCopyText)
-    Message.success({
-      content: t('page.banlist.banlist.listItem.hashCopiedToClipboard', { hash: toCopyText }),
-      resetOnHover: true
-    })
-  } catch (e) {
-    console.error(e)
-  }
-}
+import { copyToClipboard } from '@/utils/clipboard'
+
+const handleCopy = (text: string) => {
+  copyToClipboard(
+    text,
+    t('page.banlist.banlist.listItem.hashCopiedToClipboard', { hash: text })
+  )
+}

Committable suggestion skipped: line range outside the PR's diff.

Co-authored-by: coderabbitai[bot] <136622811+coderabbitai[bot]@users.noreply.github.com>
Copy link

cloudflare-workers-and-pages bot commented Jan 13, 2025

Deploying pbh-fe with  Cloudflare Pages  Cloudflare Pages

Latest commit: b4ee73d
Status: ✅  Deploy successful!
Preview URL: https://7a9903f0.peerbanhelper.pages.dev
Branch Preview URL: https://clipboard.peerbanhelper.pages.dev

View logs

@Gaojianli
Copy link
Member

驳回,请使用 components/copier.vue

@Ghost-chu Ghost-chu closed this Jan 13, 2025
@Ghost-chu Ghost-chu deleted the clipboard branch January 13, 2025 13:16
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