added types folder
This commit is contained in:
parent
898bba87b1
commit
e14debfcc0
4 changed files with 28 additions and 23 deletions
|
|
@ -1,24 +1,8 @@
|
||||||
import { createContext, useEffect, useState, useRef } from "react";
|
import { createContext, useEffect, useState, useRef } from "react";
|
||||||
import { example } from "../data_assets/example";
|
import {flow} from "../types/flow"
|
||||||
|
import { TabsContextType } from "../types/tabs";
|
||||||
|
|
||||||
type flow = {
|
|
||||||
name: string;
|
|
||||||
id: string;
|
|
||||||
data: any;
|
|
||||||
chat: Array<{ message: string; isSend: boolean }>;
|
|
||||||
};
|
|
||||||
|
|
||||||
type TabsContextType = {
|
|
||||||
tabIndex: number;
|
|
||||||
setTabIndex: (index: number) => void;
|
|
||||||
flows: Array<flow>;
|
|
||||||
removeFlow: (id: string) => void;
|
|
||||||
addFlow: (flowData?: any) => void;
|
|
||||||
updateFlow: (newFlow: flow) => void;
|
|
||||||
incrementNodeId: () => number;
|
|
||||||
downloadFlow: () => void;
|
|
||||||
uploadFlow: () => void;
|
|
||||||
};
|
|
||||||
|
|
||||||
const TabsContextInitialValue = {
|
const TabsContextInitialValue = {
|
||||||
tabIndex: 0,
|
tabIndex: 0,
|
||||||
|
|
@ -76,7 +60,7 @@ export function TabsProvider({ children }) {
|
||||||
link.download = `${flows[tabIndex].name}.json`;
|
link.download = `${flows[tabIndex].name}.json`;
|
||||||
link.click();
|
link.click();
|
||||||
}
|
}
|
||||||
|
|
||||||
function uploadFlow() {
|
function uploadFlow() {
|
||||||
const input = document.createElement("input");
|
const input = document.createElement("input");
|
||||||
input.type = "file";
|
input.type = "file";
|
||||||
|
|
@ -84,14 +68,17 @@ export function TabsProvider({ children }) {
|
||||||
if ((e.target as HTMLInputElement).files[0].type === "application/json") {
|
if ((e.target as HTMLInputElement).files[0].type === "application/json") {
|
||||||
const file = (e.target as HTMLInputElement).files[0];
|
const file = (e.target as HTMLInputElement).files[0];
|
||||||
file.text().then((text) => {
|
file.text().then((text) => {
|
||||||
console.log(JSON.parse(text),"json from upload")
|
|
||||||
addFlow(JSON.parse(text));
|
addFlow(JSON.parse(text));
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
input.click();
|
input.click();
|
||||||
}
|
}
|
||||||
|
/**
|
||||||
|
* Removes a flow from an array of flows based on its id.
|
||||||
|
* Updates the state of flows and tabIndex using setFlows and setTabIndex hooks.
|
||||||
|
* @param {string} id - The id of the flow to remove.
|
||||||
|
*/
|
||||||
function removeFlow(id: string) {
|
function removeFlow(id: string) {
|
||||||
setFlows((prevState) => {
|
setFlows((prevState) => {
|
||||||
const newFlows = [...prevState];
|
const newFlows = [...prevState];
|
||||||
|
|
|
||||||
|
|
@ -1,11 +1,10 @@
|
||||||
import { useCallback, useContext, useEffect, useRef, useState } from "react";
|
import { useCallback, useContext, useEffect, useRef } from "react";
|
||||||
import ReactFlow, {
|
import ReactFlow, {
|
||||||
Background,
|
Background,
|
||||||
Controls,
|
Controls,
|
||||||
addEdge,
|
addEdge,
|
||||||
useEdgesState,
|
useEdgesState,
|
||||||
useNodesState,
|
useNodesState,
|
||||||
ReactFlowProvider,
|
|
||||||
useReactFlow,
|
useReactFlow,
|
||||||
ControlButton,
|
ControlButton,
|
||||||
} from "reactflow";
|
} from "reactflow";
|
||||||
|
|
|
||||||
6
space_flow/src/types/flow/index.ts
Normal file
6
space_flow/src/types/flow/index.ts
Normal file
|
|
@ -0,0 +1,6 @@
|
||||||
|
export type flow = {
|
||||||
|
name: string;
|
||||||
|
id: string;
|
||||||
|
data: any;
|
||||||
|
chat: Array<{ message: string; isSend: boolean }>;
|
||||||
|
};
|
||||||
13
space_flow/src/types/tabs/index.ts
Normal file
13
space_flow/src/types/tabs/index.ts
Normal file
|
|
@ -0,0 +1,13 @@
|
||||||
|
import { flow } from "../flow";
|
||||||
|
|
||||||
|
export type TabsContextType = {
|
||||||
|
tabIndex: number;
|
||||||
|
setTabIndex: (index: number) => void;
|
||||||
|
flows: Array<flow>;
|
||||||
|
removeFlow: (id: string) => void;
|
||||||
|
addFlow: (flowData?: any) => void;
|
||||||
|
updateFlow: (newFlow: flow) => void;
|
||||||
|
incrementNodeId: () => number;
|
||||||
|
downloadFlow: () => void;
|
||||||
|
uploadFlow: () => void;
|
||||||
|
};
|
||||||
Loading…
Add table
Add a link
Reference in a new issue