diff --git a/space_flow/src/CustomNodes/GenericNode/index.tsx b/space_flow/src/CustomNodes/GenericNode/index.tsx index 0e1a71542..09a4315f8 100644 --- a/space_flow/src/CustomNodes/GenericNode/index.tsx +++ b/space_flow/src/CustomNodes/GenericNode/index.tsx @@ -7,9 +7,12 @@ import { snakeToNormalCase, } from "../../utils"; import ParameterComponent from "./components/parameterComponent"; +import { typesContext } from "../../contexts/typesContext"; +import { useContext } from "react"; export default function GenericNode({ data }) { const Icon = nodeIcons[data.type]; + const {types} = useContext(typesContext); return (
@@ -46,7 +49,7 @@ export default function GenericNode({ data }) { data={data} color={ - nodeColors[data.types[data.node.template[t].type]] ?? + nodeColors[types[data.node.template[t].type]] ?? "black" } title={ diff --git a/space_flow/src/contexts/index.tsx b/space_flow/src/contexts/index.tsx index 828ba1fa3..6eba87762 100644 --- a/space_flow/src/contexts/index.tsx +++ b/space_flow/src/contexts/index.tsx @@ -1,13 +1,16 @@ import { AlertProvider } from "./alertContext"; import { LocationProvider } from "./locationContext"; import PopUpProvider from "./popUpContext"; +import { TypesProvider } from "./typesContext"; export default function ContextWrapper({ children }) { return ( <> - {children} + + {children} + diff --git a/space_flow/src/contexts/typesContext.tsx b/space_flow/src/contexts/typesContext.tsx new file mode 100644 index 000000000..37f26a767 --- /dev/null +++ b/space_flow/src/contexts/typesContext.tsx @@ -0,0 +1,23 @@ +import { createContext, useState } from "react"; + +type typesContextType= +{ + types: {}; + setTypes:(newState:{})=>void; +} + +const initialValue= { + types: {}, + setTypes:()=>{}, +} + +export const typesContext = createContext(initialValue); + +export function TypesProvider({children}){ + const [types, setTypes] = useState({}); + return ( + + {children} + + ) +} diff --git a/space_flow/src/pages/FlowPage/components/extraSidebarComponent/index.tsx b/space_flow/src/pages/FlowPage/components/extraSidebarComponent/index.tsx index 90503f5b3..3d558d6e2 100644 --- a/space_flow/src/pages/FlowPage/components/extraSidebarComponent/index.tsx +++ b/space_flow/src/pages/FlowPage/components/extraSidebarComponent/index.tsx @@ -1,20 +1,18 @@ import { Bars2Icon, ComputerDesktopIcon } from "@heroicons/react/24/outline"; import DisclosureComponent from "../DisclosureComponent"; -import { nodeColors, nodeIcons, nodeNames, toFirstUpperCase } from "../../../../utils"; -import { useEffect, useState } from "react"; +import { + nodeColors, + nodeIcons, + nodeNames, + toFirstUpperCase, +} from "../../../../utils"; +import { useContext, useEffect, useState } from "react"; import { getAll } from "../../../../controllers/NodesServices"; +import { typesContext } from "../../../../contexts/typesContext"; export default function ExtraSidebar() { const [data, setData] = useState({}); - - const types = Object.keys(data).reduce((acc, curr) => { - Object.keys(data[curr]).forEach((c) => { - acc[c] = curr; - data[curr][c].base_classes?.forEach((b) => {acc[b] = curr;}) - }); - // console.log(acc); - return acc; - }, {str: 'advanced', bool: 'advanced', chatOutput: 'chat', chatInput: 'chat'}); + const { setTypes } = useContext(typesContext); useEffect(() => { getAll().then((d) => { @@ -23,6 +21,31 @@ export default function ExtraSidebar() { }); }, []); + useEffect(() => { + if(data){ + setTypes( + Object.keys(data).reduce( + (acc, curr) => { + Object.keys(data[curr]).forEach((c) => { + acc[c] = curr; + data[curr][c].base_classes?.forEach((b) => { + acc[b] = curr; + }); + }); + // console.log(acc); + return acc; + }, + { + str: "advanced", + bool: "advanced", + chatOutput: "chat", + chatInput: "chat", + } + ) + ); + } + }, [data, setTypes]) + function onDragStart(event: React.DragEvent, data) { event.dataTransfer.effectAllowed = "move"; event.dataTransfer.setData("json", JSON.stringify(data)); @@ -46,7 +69,6 @@ export default function ExtraSidebar() { onDragStart(event, { type: d, name: t, - types: types, node: data[d][t], }) } @@ -62,94 +84,89 @@ export default function ExtraSidebar() { ))} -
-
-
- onDragStart(event, { - type: 'chat', - name: 'chatInput', - types, - }) - } - > -
- Chat Input - -
+ button={{ title: nodeNames["chat"], Icon: nodeIcons["chat"] }} + > +
+
+
+ onDragStart(event, { + type: "chat", + name: "chatInput", + }) + } + > +
+ Chat Input +
-
-
- onDragStart(event, { - type: 'chat', - name: 'chatOutput', - types, - }) - } - > -
- Chat Output - -
+
+
+
+ onDragStart(event, { + type: "chat", + name: "chatOutput", + }) + } + > +
+ Chat Output +
-
- +
+
+ -
-
-
- onDragStart(event, { - type: 'advanced', - name: 'str', - types, - }) - } - > -
- String - -
+ button={{ title: nodeNames["advanced"], Icon: nodeIcons["advanced"] }} + > +
+
+
+ onDragStart(event, { + type: "advanced", + name: "str", + }) + } + > +
+ String +
-
-
- onDragStart(event, { - type: 'advanced', - name: 'bool', - types, - }) - } - > -
- Boolean - -
+
+
+
+ onDragStart(event, { + type: "advanced", + name: "bool", + }) + } + > +
+ Boolean +
-
- - +
+
+
); }