Skip to content

Commit 9ca7e34

Browse files
author
6174
committed
home page support drag to create workflow
1 parent d00056d commit 9ca7e34

3 files changed

Lines changed: 46 additions & 3 deletions

File tree

apps/electron-frontend/src/components/my-workflows/import.tsx

Lines changed: 13 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,10 +4,11 @@ import { readWorkflowFromFile, readWorkflowFromPng } from '@comflowy/common/comf
44
import { documentDatabaseInstance } from '@comflowy/common/storage/document-database';
55
import { useAppStore } from '@comflowy/common/store';
66
import { message } from 'antd';
7-
import React, { useState, useRef } from 'react';
7+
import React, { useState, useRef, useEffect } from 'react';
88
import { ImageIcon } from 'ui/icons';
99
import {KEYS, t} from "@comflowy/common/i18n";
1010
import { PersistedWorkflowDocument } from '@comflowy/common/types';
11+
import { GlobalEvents, SlotGlobalEvent } from '@comflowy/common/utils/slot-event';
1112

1213
export const ImportWorkflow = () => {
1314
const [selectedFile, setSelectedFile] = useState<File | null>(null);
@@ -65,6 +66,17 @@ export const ImportWorkflow = () => {
6566
}
6667
};
6768

69+
useEffect(() => {
70+
const disposable = SlotGlobalEvent.on((ev) => {
71+
if (ev.type === GlobalEvents.import_workflow) {
72+
onFileSelected(ev.data)
73+
}
74+
})
75+
return () => {
76+
disposable.dispose();
77+
}
78+
}, [])
79+
6880
return (
6981
<div className='create-button' onClick={handleButtonClick}>
7082
<div style={{ display: 'none' }}>

apps/electron-frontend/src/components/my-workflows/my-workflows.tsx

Lines changed: 31 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -18,8 +18,38 @@ import {KEYS, t} from "@comflowy/common/i18n";
1818
import { NotificationModalEntry } from './notification-modal';
1919

2020
function MyWorkflowsPage() {
21+
const [draggingOver, setDraggingOver] = React.useState(false);
22+
const handleDragEnter = (ev) => {
23+
ev.preventDefault();
24+
setDraggingOver(true);
25+
}
26+
27+
const handleDragLeave = (ev) => {
28+
ev.preventDefault();
29+
if (ev.currentTarget.contains(ev.relatedTarget)) {
30+
return;
31+
}
32+
console.log("drag leave")
33+
setDraggingOver(false);
34+
}
35+
36+
const handleDrop = async (ev) => {
37+
ev.preventDefault();
38+
setDraggingOver(false);
39+
console.log(ev.dataTransfer.files)
40+
const files = ev.dataTransfer.files;
41+
if (files.length > 0) {
42+
SlotGlobalEvent.emit({
43+
type: GlobalEvents.import_workflow,
44+
data: files[0]
45+
});
46+
}
47+
}
48+
2149
return (
22-
<div className={styles.myWorkflows}>
50+
<div className={styles.myWorkflows} style={{
51+
border: draggingOver ? "2px solid var(--primaryColor)" : "2px dashed transparent"
52+
}} onDragEnter={handleDragEnter} onDragLeave={handleDragLeave} onDragOver={(ev) => ev.preventDefault()} onDrop={handleDrop}>
2353
<WorkflowCreateBox/>
2454
<h2>{t(KEYS.myWorkflows)}</h2>
2555
<WorkflowList/>

packages/common/utils/slot-event.ts

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -142,7 +142,8 @@ export enum GlobalEvents {
142142
toggle_panel_container = 'toggle_panel_container',
143143
show_notification_modal = 'show_notification_modal',
144144
start_comfyui_execute = 'start_comfyui_execute',
145-
show_execution_error = 'show_execution_error'
145+
show_execution_error = 'show_execution_error',
146+
import_workflow = 'import_workflow'
146147
}
147148

148149
export type GlobalEventKeys = keyof typeof GlobalEvents;

0 commit comments

Comments
 (0)