From a4535d06ef45d64cedfea36f3136df6975ceae2b Mon Sep 17 00:00:00 2001 From: ayangweb <75017711+ayangweb@users.noreply.github.com> Date: Fri, 20 Dec 2024 11:13:17 +0800 Subject: [PATCH] =?UTF-8?q?feat:=20=E6=96=B0=E5=A2=9E=20`=E5=89=AA?= =?UTF-8?q?=E8=B4=B4=E6=9D=BF=20>=20=E5=86=85=E5=AE=B9=E8=AE=BE=E7=BD=AE?= =?UTF-8?q?=20>=20=E5=88=A0=E9=99=A4=E7=A1=AE=E8=AE=A4`=20=E9=85=8D?= =?UTF-8?q?=E7=BD=AE=E9=A1=B9=20(#911)?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- src/locales/en-US.json | 9 +++++--- src/locales/ja-JP.json | 9 +++++--- src/locales/zh-CN.json | 9 +++++--- src/locales/zh-TW.json | 9 +++++--- .../components/List/components/Item/index.tsx | 21 +++++++++++++++++-- .../Clipboard/Panel/components/List/index.tsx | 8 +++++-- src/pages/Clipboard/Settings/index.tsx | 13 ++++++++++++ src/stores/clipboard.ts | 1 + src/types/store.d.ts | 1 + 9 files changed, 64 insertions(+), 16 deletions(-) diff --git a/src/locales/en-US.json b/src/locales/en-US.json index 9c5ac5f74e..de4c465991 100644 --- a/src/locales/en-US.json +++ b/src/locales/en-US.json @@ -67,7 +67,8 @@ "favorite": "Favorite", "delete": "Delete" }, - "auto_favorite": "Auto Favorite" + "auto_favorite": "Auto Favorite", + "delete_confirm": "Delete Confirmation" }, "hints": { "auto_paste": "Quickly paste content to the input field when using the left mouse button", @@ -75,7 +76,8 @@ "copy_as_plain": "Rich text and HTML formats retain only plain text content when copied", "paste_as_plain": "Rich text and HTML formatting retains only plain text content when pasting", "operation_button": "Customize icon buttons to operate on clipboard content", - "auto_favorite": "Auto-favorite after adding or editing a note" + "auto_favorite": "Auto-favorite after adding or editing a note", + "delete_confirm": "Pop-up confirmation dialog when deleting clipboard contents" } } }, @@ -283,7 +285,8 @@ "n_chars": "{{0}} Character(s)" }, "hints": { - "search_placeholder": "Search..." + "search_placeholder": "Search...", + "delete_modal_content": "Are you sure you want to delete this?" } }, "component": { diff --git a/src/locales/ja-JP.json b/src/locales/ja-JP.json index 85704857f1..07d69052a6 100644 --- a/src/locales/ja-JP.json +++ b/src/locales/ja-JP.json @@ -67,7 +67,8 @@ "favorite": "お気に入り", "delete": "削除" }, - "auto_favorite": "自動コレクション" + "auto_favorite": "自動コレクション", + "delete_confirm": "削除確認" }, "hints": { "auto_paste": "左クリック時に、内容を素早く入力フィールドに貼り付けます", @@ -75,7 +76,8 @@ "copy_as_plain": "リッチテキストとHTML形式は、コピーしてもプレーンテキストの内容しか保持しない", "paste_as_plain": "リッチテキストとHTMLの書式設定は、貼り付け時にプレーンテキストの内容だけを保持する", "operation_button": "クリップボード内容を操作するためのアイコンボタンをカスタマイズします", - "auto_favorite": "メモの追加・編集後に自動お気に入り登録" + "auto_favorite": "メモの追加・編集後に自動お気に入り登録", + "delete_confirm": "クリップボードの内容を削除する際のポップアップ確認ダイアログ" } } }, @@ -283,7 +285,8 @@ "n_chars": "{{0}} 文字" }, "hints": { - "search_placeholder": "検索" + "search_placeholder": "検索", + "delete_modal_content": "本当に削除しますか?" } }, "component": { diff --git a/src/locales/zh-CN.json b/src/locales/zh-CN.json index d179cea7cd..13974e8909 100644 --- a/src/locales/zh-CN.json +++ b/src/locales/zh-CN.json @@ -67,7 +67,8 @@ "favorite": "收藏", "delete": "删除" }, - "auto_favorite": "自动收藏" + "auto_favorite": "自动收藏", + "delete_confirm": "删除确认" }, "hints": { "auto_paste": "鼠标左键操作时,快速粘贴内容至输入位置", @@ -75,7 +76,8 @@ "copy_as_plain": "富文本和HTML格式在复制时仅保留纯文本内容", "paste_as_plain": "富文本和HTML格式在粘贴时仅保留纯文本内容", "operation_button": "自定义操作剪贴板内容的图标按钮", - "auto_favorite": "新增或编辑备注后自动收藏" + "auto_favorite": "新增或编辑备注后自动收藏", + "delete_confirm": "删除剪贴板内容时弹出确认对话框" } } }, @@ -283,7 +285,8 @@ "n_chars": "{{0}}个字符" }, "hints": { - "search_placeholder": "搜索" + "search_placeholder": "搜索", + "delete_modal_content": "确定要删除此项吗?" } }, "component": { diff --git a/src/locales/zh-TW.json b/src/locales/zh-TW.json index c73ac93156..c96b81355d 100644 --- a/src/locales/zh-TW.json +++ b/src/locales/zh-TW.json @@ -67,7 +67,8 @@ "favorite": "收藏", "delete": "刪除" }, - "auto_favorite": "自動收藏" + "auto_favorite": "自動收藏", + "delete_confirm": "删除確認" }, "hints": { "auto_paste": "當使用滑鼠左鍵時,快速將內容貼上到輸入位置", @@ -75,7 +76,8 @@ "copy_as_plain": "富文字和HTML格式在複製時僅保留純文字內容", "paste_as_plain": "富文字和HTML格式在粘貼時僅保留純文字內容", "operation_button": "自定義操作剪貼簿內容的圖示按鈕", - "auto_favorite": "新增或編輯備註後自動收藏" + "auto_favorite": "新增或編輯備註後自動收藏", + "delete_confirm": "删除剪貼板內容時彈出確認對話方塊" } } }, @@ -283,7 +285,8 @@ "n_chars": "{{0}}個字元" }, "hints": { - "search_placeholder": "搜尋" + "search_placeholder": "搜尋", + "delete_modal_content": "確定要删除此項嗎?" } }, "component": { diff --git a/src/pages/Clipboard/Panel/components/List/components/Item/index.tsx b/src/pages/Clipboard/Panel/components/List/components/Item/index.tsx index b5472a7858..2e07c81e6d 100644 --- a/src/pages/Clipboard/Panel/components/List/components/Item/index.tsx +++ b/src/pages/Clipboard/Panel/components/List/components/Item/index.tsx @@ -7,6 +7,7 @@ import { downloadDir, resolveResource } from "@tauri-apps/api/path"; import { copyFile, writeTextFile } from "@tauri-apps/plugin-fs"; import { open } from "@tauri-apps/plugin-shell"; import { Flex, type FlexProps, message } from "antd"; +import type { HookAPI } from "antd/es/modal/useModal"; import clsx from "clsx"; import { find, isNil, remove } from "lodash-es"; import type { DragEvent, FC, MouseEvent } from "react"; @@ -22,6 +23,7 @@ import Text from "./components/Text"; interface ItemProps extends Partial { index: number; data: HistoryTablePayload; + deleteModal: HookAPI; openNoteModel: () => void; } @@ -30,7 +32,7 @@ interface ContextMenuItem extends MenuItemOptions { } const Item: FC = (props) => { - const { index, data, className, openNoteModel, ...rest } = props; + const { index, data, className, deleteModal, openNoteModel, ...rest } = props; const { id, type, value, search, group, favorite, note, subtype } = data; const { state } = useContext(ClipboardPanelContext); const { t } = useTranslation(); @@ -130,7 +132,22 @@ const Item: FC = (props) => { }; // 删除条目 - const deleteItem = () => { + const deleteItem = async () => { + let confirmed = true; + + if (clipboardStore.content.deleteConfirm) { + confirmed = await deleteModal.confirm({ + centered: true, + content: t("clipboard.hints.delete_modal_content"), + afterClose() { + // 关闭确认框后焦点还在,需要手动取消焦点 + (document.activeElement as HTMLElement)?.blur(); + }, + }); + } + + if (!confirmed) return; + if (state.activeId === id) { const nextIndex = selectNextOrPrev(); diff --git a/src/pages/Clipboard/Panel/components/List/index.tsx b/src/pages/Clipboard/Panel/components/List/index.tsx index 3d1b43db59..9bb35a1b0b 100644 --- a/src/pages/Clipboard/Panel/components/List/index.tsx +++ b/src/pages/Clipboard/Panel/components/List/index.tsx @@ -1,7 +1,7 @@ import Scrollbar from "@/components/Scrollbar"; import { ClipboardPanelContext } from "@/pages/Clipboard/Panel"; import { useVirtualizer } from "@tanstack/react-virtual"; -import { FloatButton } from "antd"; +import { FloatButton, Modal } from "antd"; import { findIndex } from "lodash-es"; import Item from "./components/Item"; import NoteModal, { type NoteModalRef } from "./components/NoteModal"; @@ -10,6 +10,7 @@ const List = () => { const { state, getList } = useContext(ClipboardPanelContext); const outerRef = useRef(null); const noteModelRef = useRef(null); + const [deleteModal, contextHolder] = Modal.useModal(); const rowVirtualizer = useVirtualizer({ count: state.list.length, @@ -123,8 +124,9 @@ const List = () => { key={key} index={index} data={{ ...data, value }} - style={{ height: size, transform: `translateY(${start}px)` }} + deleteModal={deleteModal} openNoteModel={() => noteModelRef.current?.open()} + style={{ height: size, transform: `translateY(${start}px)` }} /> ); })} @@ -138,6 +140,8 @@ const List = () => { /> + + {contextHolder} ); }; diff --git a/src/pages/Clipboard/Settings/index.tsx b/src/pages/Clipboard/Settings/index.tsx index b1e4d12135..95ab3ab942 100644 --- a/src/pages/Clipboard/Settings/index.tsx +++ b/src/pages/Clipboard/Settings/index.tsx @@ -137,6 +137,19 @@ const ClipboardSettings = () => { clipboardStore.content.autoFavorite = value; }} /> + + { + clipboardStore.content.deleteConfirm = value; + }} + /> ); diff --git a/src/stores/clipboard.ts b/src/stores/clipboard.ts index 85c0e0bda1..fbe12380c1 100644 --- a/src/stores/clipboard.ts +++ b/src/stores/clipboard.ts @@ -26,6 +26,7 @@ export const clipboardStore = proxy({ pastePlain: false, operationButtons: ["copy", "star", "delete"], autoFavorite: false, + deleteConfirm: true, }, history: { diff --git a/src/types/store.d.ts b/src/types/store.d.ts index ff76c931b6..6088e50bc7 100644 --- a/src/types/store.d.ts +++ b/src/types/store.d.ts @@ -88,6 +88,7 @@ export interface ClipboardStore { pastePlain: boolean; operationButtons: OperationButton[]; autoFavorite: boolean; + deleteConfirm: boolean; }; // 历史记录