From e14debfcc0b23cd9658cc483fbb61c04f25d1e05 Mon Sep 17 00:00:00 2001 From: anovazzi1 Date: Tue, 28 Feb 2023 21:29:42 -0300 Subject: [PATCH] added types folder --- space_flow/src/contexts/tabsContext.tsx | 29 +++++++------------------ space_flow/src/pages/FlowPage/index.tsx | 3 +-- space_flow/src/types/flow/index.ts | 6 +++++ space_flow/src/types/tabs/index.ts | 13 +++++++++++ 4 files changed, 28 insertions(+), 23 deletions(-) create mode 100644 space_flow/src/types/flow/index.ts create mode 100644 space_flow/src/types/tabs/index.ts diff --git a/space_flow/src/contexts/tabsContext.tsx b/space_flow/src/contexts/tabsContext.tsx index 88ee249f8..d67fba95e 100644 --- a/space_flow/src/contexts/tabsContext.tsx +++ b/space_flow/src/contexts/tabsContext.tsx @@ -1,24 +1,8 @@ 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; - removeFlow: (id: string) => void; - addFlow: (flowData?: any) => void; - updateFlow: (newFlow: flow) => void; - incrementNodeId: () => number; - downloadFlow: () => void; - uploadFlow: () => void; -}; const TabsContextInitialValue = { tabIndex: 0, @@ -76,7 +60,7 @@ export function TabsProvider({ children }) { link.download = `${flows[tabIndex].name}.json`; link.click(); } - + function uploadFlow() { const input = document.createElement("input"); input.type = "file"; @@ -84,14 +68,17 @@ export function TabsProvider({ children }) { if ((e.target as HTMLInputElement).files[0].type === "application/json") { const file = (e.target as HTMLInputElement).files[0]; file.text().then((text) => { - console.log(JSON.parse(text),"json from upload") addFlow(JSON.parse(text)); }); } }; 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) { setFlows((prevState) => { const newFlows = [...prevState]; diff --git a/space_flow/src/pages/FlowPage/index.tsx b/space_flow/src/pages/FlowPage/index.tsx index d0e4538d4..6aafdebe2 100644 --- a/space_flow/src/pages/FlowPage/index.tsx +++ b/space_flow/src/pages/FlowPage/index.tsx @@ -1,11 +1,10 @@ -import { useCallback, useContext, useEffect, useRef, useState } from "react"; +import { useCallback, useContext, useEffect, useRef } from "react"; import ReactFlow, { Background, Controls, addEdge, useEdgesState, useNodesState, - ReactFlowProvider, useReactFlow, ControlButton, } from "reactflow"; diff --git a/space_flow/src/types/flow/index.ts b/space_flow/src/types/flow/index.ts new file mode 100644 index 000000000..b8042ea3e --- /dev/null +++ b/space_flow/src/types/flow/index.ts @@ -0,0 +1,6 @@ +export type flow = { + name: string; + id: string; + data: any; + chat: Array<{ message: string; isSend: boolean }>; +}; diff --git a/space_flow/src/types/tabs/index.ts b/space_flow/src/types/tabs/index.ts new file mode 100644 index 000000000..d1e286b2e --- /dev/null +++ b/space_flow/src/types/tabs/index.ts @@ -0,0 +1,13 @@ +import { flow } from "../flow"; + +export type TabsContextType = { + tabIndex: number; + setTabIndex: (index: number) => void; + flows: Array; + removeFlow: (id: string) => void; + addFlow: (flowData?: any) => void; + updateFlow: (newFlow: flow) => void; + incrementNodeId: () => number; + downloadFlow: () => void; + uploadFlow: () => void; +}; \ No newline at end of file