From 8f2e0de4e00437865ef04948198acf58c1abe6d4 Mon Sep 17 00:00:00 2001 From: yuruo Date: Thu, 20 Jun 2024 13:59:40 +0800 Subject: [PATCH] =?UTF-8?q?=E2=9C=A8=20=E6=B7=BB=E5=8A=A0(CategoryItem):?= =?UTF-8?q?=20=E4=BD=BF=E7=94=A8=E6=96=B0=E7=9A=84useCategory=E9=92=A9?= =?UTF-8?q?=E5=AD=90=E6=9D=A5=E6=9B=BF=E6=8D=A2=E6=97=A7=E7=9A=84useContex?= =?UTF-8?q?tMenu=E4=BD=BF=E7=94=A8=20=F0=9F=93=9D=20=E6=96=87=E6=A1=A3(use?= =?UTF-8?q?Category):=20=E6=B7=BB=E5=8A=A0=E7=94=A8=E4=BA=8ECategoryItem?= =?UTF-8?q?=E7=BB=84=E4=BB=B6=E4=B8=8A=E4=B8=8B=E6=96=87=E8=8F=9C=E5=8D=95?= =?UTF-8?q?=E7=9A=84contextMenu=E5=8A=9F=E8=83=BD=20=F0=9F=9A=80=20?= =?UTF-8?q?=E9=83=A8=E7=BD=B2(ContentItem):=20=E6=B7=BB=E5=8A=A0=E6=8B=96?= =?UTF-8?q?=E6=8B=BD=E4=BA=8B=E4=BB=B6=E5=A4=84=E7=90=86=E7=A8=8B=E5=BA=8F?= =?UTF-8?q?=E5=88=B0ContentItem=E7=BB=84=E4=BB=B6=20=F0=9F=94=A7=20?= =?UTF-8?q?=E9=85=8D=E7=BD=AE=E6=96=87=E4=BB=B6(useCategory):=20=E6=96=B0?= =?UTF-8?q?=E5=A2=9E=E5=88=9B=E5=BB=BAuseCategory=E9=92=A9=E5=AD=90?= =?UTF-8?q?=EF=BC=8C=E7=94=A8=E4=BA=8E=E5=A4=84=E7=90=86Category=E7=9B=B8?= =?UTF-8?q?=E5=85=B3=E7=9A=84=E6=93=8D=E4=BD=9C?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../src/components/CategoryItem/index.tsx | 18 ++++----------- .../src/components/ContentItem/index.tsx | 3 +++ .../src/renderer/src/hooks/useCategory.tsx | 23 +++++++++++++++++++ 3 files changed, 30 insertions(+), 14 deletions(-) create mode 100644 ui/autoMate/src/renderer/src/hooks/useCategory.tsx diff --git a/ui/autoMate/src/renderer/src/components/CategoryItem/index.tsx b/ui/autoMate/src/renderer/src/components/CategoryItem/index.tsx index 3ba0d3b..2616d08 100644 --- a/ui/autoMate/src/renderer/src/components/CategoryItem/index.tsx +++ b/ui/autoMate/src/renderer/src/components/CategoryItem/index.tsx @@ -1,8 +1,8 @@ -import { Delete, FolderClose } from "@icon-park/react" +import { FolderClose } from "@icon-park/react" import { NavLink, useFetcher, useSubmit } from "react-router-dom" import styles from "./styles.module.scss" -import { useContextMenu } from "mantine-contextmenu" import { useStore } from "@renderer/store/useStore" +import useCategory from "@renderer/hooks/useCategory" interface Props { category: CategoryType } @@ -10,9 +10,9 @@ interface Props { export const CategoryItem = ({ category }: Props) => { // fetcher 不会刷新路由 const fetcher = useFetcher() - const { showContextMenu } = useContextMenu() const setEditCategoryId = useStore(state => state.setEditCategoryId) const editCategoryId = useStore(state => state.editCategoryId) + const { contextMenu } = useCategory() return ( <> {editCategoryId == category.id ? ( @@ -43,17 +43,7 @@ export const CategoryItem = ({ category }: Props) => { className={({ isActive }) => { return isActive ? styles.active : styles.link }} - onContextMenu={showContextMenu([ - { - key: 'remove', - icon: , - title: '删除动作', - onClick: () => { - submit({ id: category.id }, { method: 'DELETE' }) - }, - } - ], - { className: 'contextMenu' })} + onContextMenu={contextMenu(category)} >
diff --git a/ui/autoMate/src/renderer/src/components/ContentItem/index.tsx b/ui/autoMate/src/renderer/src/components/ContentItem/index.tsx index 3b16209..52cb320 100644 --- a/ui/autoMate/src/renderer/src/components/ContentItem/index.tsx +++ b/ui/autoMate/src/renderer/src/components/ContentItem/index.tsx @@ -16,6 +16,9 @@ const { showContextMenu } = useContextMenu(); className={({isActive})=>{ return [isActive ? styles.active : '', styles.link].join(' ') }} + onDragStart={(_e)=>{ + console.log("drag") + }} onContextMenu={showContextMenu([ { key: 'remove', diff --git a/ui/autoMate/src/renderer/src/hooks/useCategory.tsx b/ui/autoMate/src/renderer/src/hooks/useCategory.tsx new file mode 100644 index 0000000..717be80 --- /dev/null +++ b/ui/autoMate/src/renderer/src/hooks/useCategory.tsx @@ -0,0 +1,23 @@ +import { Delete } from "@icon-park/react" +import { useContextMenu } from "mantine-contextmenu" +import { useSubmit } from "react-router-dom" + +export default ()=>{ + const submit = useSubmit() + const { showContextMenu } = useContextMenu() + + const contextMenu = (category: CategoryType) => { + return showContextMenu([ + { + key: 'remove', + icon: , + title: '删除动作', + onClick: () => { + submit({ id: category.id }, { method: 'DELETE' }) + }, + } + ], + { className: 'contextMenu' }) + } + return {contextMenu} +} \ No newline at end of file