diff --git a/packages/renderer/src/assets/svg/EditIcon.tsx b/packages/renderer/src/assets/svg/EditIcon.tsx index 4916de4..3d32a3b 100644 --- a/packages/renderer/src/assets/svg/EditIcon.tsx +++ b/packages/renderer/src/assets/svg/EditIcon.tsx @@ -10,16 +10,9 @@ export function EditIcon(props: React.SVGProps) { xmlns="http://www.w3.org/2000/svg" {...props} > - - - - - - - - - - + + + ); } diff --git a/packages/renderer/src/components/ui/button.tsx b/packages/renderer/src/components/ui/button.tsx index 205fec8..375be87 100644 --- a/packages/renderer/src/components/ui/button.tsx +++ b/packages/renderer/src/components/ui/button.tsx @@ -22,7 +22,7 @@ const buttonVariants = cva( }, size: { default: "h-[30px] px-3 py-1", - sm: "h-[20px] rounded-md px-1", + sm: "h-[20px] rounded-md px-1.5 text-xs", lg: "h-11 rounded-md px-8", icon: "h-10 w-10", }, diff --git a/packages/renderer/src/pages/SourceExtract/components/BrowserViewPanel.tsx b/packages/renderer/src/pages/SourceExtract/components/BrowserViewPanel.tsx index 9fb86cc..bd047dd 100644 --- a/packages/renderer/src/pages/SourceExtract/components/BrowserViewPanel.tsx +++ b/packages/renderer/src/pages/SourceExtract/components/BrowserViewPanel.tsx @@ -1,24 +1,53 @@ -import { DeleteIcon } from "@/assets/svg"; -import { IconButton } from "@/components/IconButton"; import { Button } from "@/components/ui/button"; import useElectron from "@/hooks/useElectron"; import { browserStoreSelector, setBrowserSelector, + SourceData, useBrowserStore, } from "@/store/browser"; import React from "react"; import { useTranslation } from "react-i18next"; import { useShallow } from "zustand/react/shallow"; +import { Button as AntdButton, App } from "antd"; +import { DeleteOutlined, EditOutlined } from "@ant-design/icons"; +import { useMemoizedFn } from "ahooks"; export function BrowserViewPanel() { const store = useBrowserStore(useShallow(browserStoreSelector)); - const { deleteSource } = useBrowserStore(useShallow(setBrowserSelector)); + const { deleteSource, clearSources } = useBrowserStore( + useShallow(setBrowserSelector), + ); const { t } = useTranslation(); const { showDownloadDialog } = useElectron(); + const { downloadNow } = useElectron(); + const { message } = App.useApp(); + + const handleClear = useMemoizedFn(() => { + clearSources(); + }); + + const handleDownloadNow = useMemoizedFn(async (item: SourceData) => { + try { + const downloadItem: Omit = { + url: item.url, + name: item.name, + headers: item.headers, + type: item.type, + }; + await downloadNow(downloadItem); + } catch (e) { + message.error((e as any).message); + } + }); return (
+
+ + 清空 + +
{store.sources.map((item, index) => { return (
-
- } +
+ } + type="text" + size="small" onClick={() => deleteSource(item.url)} + title={t("delete")} + danger + /> + } + type="text" + size="small" + title={t("edit")} + onClick={() => showDownloadDialog([item])} />
-
diff --git a/packages/renderer/src/store/browser.ts b/packages/renderer/src/store/browser.ts index 92603dd..80d3955 100644 --- a/packages/renderer/src/store/browser.ts +++ b/packages/renderer/src/store/browser.ts @@ -4,6 +4,7 @@ import { convertPlainObject } from "@/utils"; import { create } from "zustand"; import { immer } from "zustand/middleware/immer"; +// eslint-disable-next-line react-hooks/rules-of-hooks const { setSharedState } = useElectron(); export enum PageMode { @@ -42,6 +43,7 @@ type Actions = { addSource: (source: SourceData) => void; deleteSource: (url: string) => void; setSources: (sources: SourceData[]) => void; + clearSources: () => void; }; export const useBrowserStore = create()( @@ -68,6 +70,10 @@ export const useBrowserStore = create()( set((state) => { state.sources = sources; }), + clearSources: () => + set((state) => { + state.sources = []; + }), })), ); @@ -89,5 +95,6 @@ export const setBrowserSelector = (state: BrowserStore & Actions) => { addSource: state.addSource, deleteSource: state.deleteSource, setSources: state.setSources, + clearSources: state.clearSources, }; };