diff --git a/apps/electron-frontend/src/components/my-workflows/import.tsx b/apps/electron-frontend/src/components/my-workflows/import.tsx index a15915f0..6f5fa00c 100644 --- a/apps/electron-frontend/src/components/my-workflows/import.tsx +++ b/apps/electron-frontend/src/components/my-workflows/import.tsx @@ -4,10 +4,11 @@ import { readWorkflowFromFile, readWorkflowFromPng } from '@comflowy/common/comf import { documentDatabaseInstance } from '@comflowy/common/storage/document-database'; import { useAppStore } from '@comflowy/common/store'; import { message } from 'antd'; -import React, { useState, useRef } from 'react'; +import React, { useState, useRef, useEffect } from 'react'; import { ImageIcon } from 'ui/icons'; import {KEYS, t} from "@comflowy/common/i18n"; import { PersistedWorkflowDocument } from '@comflowy/common/types'; +import { GlobalEvents, SlotGlobalEvent } from '@comflowy/common/utils/slot-event'; export const ImportWorkflow = () => { const [selectedFile, setSelectedFile] = useState(null); @@ -65,6 +66,17 @@ export const ImportWorkflow = () => { } }; + useEffect(() => { + const disposable = SlotGlobalEvent.on((ev) => { + if (ev.type === GlobalEvents.import_workflow) { + onFileSelected(ev.data) + } + }) + return () => { + disposable.dispose(); + } + }, []) + return (
diff --git a/apps/electron-frontend/src/components/my-workflows/my-workflows.tsx b/apps/electron-frontend/src/components/my-workflows/my-workflows.tsx index 16191932..ec3e2249 100644 --- a/apps/electron-frontend/src/components/my-workflows/my-workflows.tsx +++ b/apps/electron-frontend/src/components/my-workflows/my-workflows.tsx @@ -18,8 +18,38 @@ import {KEYS, t} from "@comflowy/common/i18n"; import { NotificationModalEntry } from './notification-modal'; function MyWorkflowsPage() { + const [draggingOver, setDraggingOver] = React.useState(false); + const handleDragEnter = (ev) => { + ev.preventDefault(); + setDraggingOver(true); + } + + const handleDragLeave = (ev) => { + ev.preventDefault(); + if (ev.currentTarget.contains(ev.relatedTarget)) { + return; + } + console.log("drag leave") + setDraggingOver(false); + } + + const handleDrop = async (ev) => { + ev.preventDefault(); + setDraggingOver(false); + console.log(ev.dataTransfer.files) + const files = ev.dataTransfer.files; + if (files.length > 0) { + SlotGlobalEvent.emit({ + type: GlobalEvents.import_workflow, + data: files[0] + }); + } + } + return ( -
+
ev.preventDefault()} onDrop={handleDrop}>

{t(KEYS.myWorkflows)}

diff --git a/packages/common/utils/slot-event.ts b/packages/common/utils/slot-event.ts index 0d4db3d8..20223a8f 100755 --- a/packages/common/utils/slot-event.ts +++ b/packages/common/utils/slot-event.ts @@ -142,7 +142,8 @@ export enum GlobalEvents { toggle_panel_container = 'toggle_panel_container', show_notification_modal = 'show_notification_modal', start_comfyui_execute = 'start_comfyui_execute', - show_execution_error = 'show_execution_error' + show_execution_error = 'show_execution_error', + import_workflow = 'import_workflow' } export type GlobalEventKeys = keyof typeof GlobalEvents;