tab refresh working, but not ideally
This commit is contained in:
parent
67e6bcddf7
commit
94577a383c
4 changed files with 90 additions and 77 deletions
|
|
@ -12,8 +12,10 @@ import { useContext } from "react";
|
|||
|
||||
export default function GenericNode({ data }) {
|
||||
const {types} = useContext(typesContext);
|
||||
console.log(types, data.type)
|
||||
const Icon = nodeIcons[types[data.type]];
|
||||
|
||||
|
||||
return (
|
||||
<div className="prompt-node relative bg-white w-96 rounded-lg solid border flex flex-col justify-center">
|
||||
<div className="w-full flex items-center justify-between p-4 gap-8 bg-gray-50 border-b ">
|
||||
|
|
|
|||
|
|
@ -1,4 +1,3 @@
|
|||
import { CookiesProvider } from "react-cookie";
|
||||
import { AlertProvider } from "./alertContext";
|
||||
import { LocationProvider } from "./locationContext";
|
||||
import PopUpProvider from "./popUpContext";
|
||||
|
|
@ -8,17 +7,15 @@ import { TypesProvider } from "./typesContext";
|
|||
export default function ContextWrapper({ children }) {
|
||||
return (
|
||||
<>
|
||||
<CookiesProvider>
|
||||
<LocationProvider>
|
||||
<PopUpProvider>
|
||||
<TypesProvider>
|
||||
<TabsProvider>
|
||||
<AlertProvider>{children}</AlertProvider>
|
||||
</TabsProvider>
|
||||
</TypesProvider>
|
||||
</PopUpProvider>
|
||||
</LocationProvider>
|
||||
</CookiesProvider>
|
||||
<LocationProvider>
|
||||
<PopUpProvider>
|
||||
<TypesProvider>
|
||||
<TabsProvider>
|
||||
<AlertProvider>{children}</AlertProvider>
|
||||
</TabsProvider>
|
||||
</TypesProvider>
|
||||
</PopUpProvider>
|
||||
</LocationProvider>
|
||||
</>
|
||||
);
|
||||
}
|
||||
|
|
|
|||
|
|
@ -12,34 +12,37 @@ import { typesContext } from "../../../../contexts/typesContext";
|
|||
|
||||
export default function ExtraSidebar() {
|
||||
const [data, setData] = useState({});
|
||||
const { setTypes } = useContext(typesContext);
|
||||
const { setTypes, types } = useContext(typesContext);
|
||||
|
||||
async function getTypes(){
|
||||
let d = await getAll();
|
||||
setData(d.data);
|
||||
setTypes(
|
||||
Object.keys(d.data).reduce(
|
||||
(acc, curr) => {
|
||||
Object.keys(d.data[curr]).forEach((c) => {
|
||||
acc[c] = curr;
|
||||
d.data[curr][c].base_classes?.forEach((b) => {
|
||||
acc[b] = curr;
|
||||
});
|
||||
});
|
||||
return acc;
|
||||
},
|
||||
{
|
||||
str: "advanced",
|
||||
bool: "advanced",
|
||||
chatOutput: "chat",
|
||||
chatInput: "chat",
|
||||
}
|
||||
)
|
||||
);
|
||||
}
|
||||
|
||||
useEffect(() => {
|
||||
getAll().then((d) => {
|
||||
setData(d.data);
|
||||
setTypes(
|
||||
Object.keys(d.data).reduce(
|
||||
(acc, curr) => {
|
||||
Object.keys(d.data[curr]).forEach((c) => {
|
||||
acc[c] = curr;
|
||||
d.data[curr][c].base_classes?.forEach((b) => {
|
||||
acc[b] = curr;
|
||||
});
|
||||
});
|
||||
// console.log(acc);
|
||||
return acc;
|
||||
},
|
||||
{
|
||||
str: "advanced",
|
||||
bool: "advanced",
|
||||
chatOutput: "chat",
|
||||
chatInput: "chat",
|
||||
}
|
||||
)
|
||||
);
|
||||
});
|
||||
getTypes();
|
||||
}, []);
|
||||
|
||||
|
||||
useEffect(() => {
|
||||
if(data){
|
||||
setTypes(
|
||||
|
|
@ -51,7 +54,6 @@ export default function ExtraSidebar() {
|
|||
acc[b] = curr;
|
||||
});
|
||||
});
|
||||
// console.log(acc);
|
||||
return acc;
|
||||
},
|
||||
{
|
||||
|
|
|
|||
|
|
@ -31,10 +31,9 @@ const nodeTypes = {
|
|||
|
||||
var _ = require("lodash");
|
||||
|
||||
export default function FlowPage({flow}) {
|
||||
|
||||
const {updateFlow} = useContext(TabsContext)
|
||||
const {reactFlowInstance, setReactFlowInstance} = useContext(typesContext);
|
||||
export default function FlowPage({ flow }) {
|
||||
const { updateFlow } = useContext(TabsContext);
|
||||
const { types, reactFlowInstance, setReactFlowInstance } = useContext(typesContext);
|
||||
const reactFlowWrapper = useRef(null);
|
||||
|
||||
const getId = () => `dndnode_${_.uniqueId()}`;
|
||||
|
|
@ -42,24 +41,29 @@ export default function FlowPage({flow}) {
|
|||
const { setExtraComponent, setExtraNavigation } = useContext(locationContext);
|
||||
const { setErrorData } = useContext(alertContext);
|
||||
|
||||
const [nodes, setNodes, onNodesChange] = useNodesState(flow.data?.nodes ?? []);
|
||||
const [edges, setEdges, onEdgesChange] = useEdgesState(flow.data?.edges ?? []);
|
||||
const [nodes, setNodes, onNodesChange] = useNodesState(
|
||||
flow.data?.nodes ?? []
|
||||
);
|
||||
const [edges, setEdges, onEdgesChange] = useEdgesState(
|
||||
flow.data?.edges ?? []
|
||||
);
|
||||
|
||||
useEffect(()=>{
|
||||
if(reactFlowInstance && flow){
|
||||
useEffect(() => {
|
||||
if (reactFlowInstance && flow) {
|
||||
flow.data = reactFlowInstance.toObject();
|
||||
updateFlow(flow);
|
||||
}
|
||||
},[nodes,edges])
|
||||
}, [nodes, edges]);
|
||||
|
||||
useEffect(()=>{
|
||||
console.log(flow);
|
||||
setNodes(flow?.data?.nodes ?? [])
|
||||
setEdges(flow?.data?.edges ?? [])
|
||||
if(reactFlowInstance){
|
||||
reactFlowInstance.setViewport(flow?.data?.viewport ?? {x: 1, y: 0, zoom: 1});
|
||||
useEffect(() => {
|
||||
setNodes(flow?.data?.nodes ?? []);
|
||||
setEdges(flow?.data?.edges ?? []);
|
||||
if (reactFlowInstance) {
|
||||
reactFlowInstance.setViewport(
|
||||
flow?.data?.viewport ?? { x: 1, y: 0, zoom: 1 }
|
||||
);
|
||||
}
|
||||
},[flow, reactFlowInstance, setEdges, setNodes])
|
||||
}, [flow, reactFlowInstance, setEdges, setNodes]);
|
||||
|
||||
useEffect(() => {
|
||||
setExtraComponent(<ExtraSidebar />);
|
||||
|
|
@ -111,19 +115,19 @@ export default function FlowPage({flow}) {
|
|||
y: event.clientY - reactflowBounds.top,
|
||||
});
|
||||
let newId = getId();
|
||||
|
||||
|
||||
const newNode = {
|
||||
id: newId,
|
||||
type:
|
||||
(data.type === "str"
|
||||
data.type === "str"
|
||||
? "inputNode"
|
||||
: (data.type === "chatInput"
|
||||
: data.type === "chatInput"
|
||||
? "chatInputNode"
|
||||
: (data.type === "chatOutput"
|
||||
: data.type === "chatOutput"
|
||||
? "chatOutputNode"
|
||||
: (data.type === "bool"
|
||||
: data.type === "bool"
|
||||
? "booleanNode"
|
||||
: "genericNode")))),
|
||||
: "genericNode",
|
||||
position,
|
||||
data: {
|
||||
...data,
|
||||
|
|
@ -149,24 +153,32 @@ export default function FlowPage({flow}) {
|
|||
|
||||
return (
|
||||
<div className="w-full h-full" ref={reactFlowWrapper}>
|
||||
<ReactFlow
|
||||
nodes={nodes}
|
||||
onMove={()=>updateFlow({...flow,data:reactFlowInstance.toObject()})}
|
||||
edges={edges}
|
||||
onNodesChange={onNodesChange}
|
||||
onEdgesChange={onEdgesChangeMod}
|
||||
onConnect={onConnect}
|
||||
onLoad={setReactFlowInstance}
|
||||
onInit={setReactFlowInstance}
|
||||
nodeTypes={nodeTypes}
|
||||
connectionLineComponent={connection}
|
||||
onDragOver={onDragOver}
|
||||
onDrop={onDrop}
|
||||
>
|
||||
<Background />
|
||||
<Controls ></Controls>
|
||||
</ReactFlow>
|
||||
<Chat reactFlowInstance={reactFlowInstance} />
|
||||
{Object.keys(types).length > 4 ? (
|
||||
<>
|
||||
<ReactFlow
|
||||
nodes={nodes}
|
||||
onMove={() =>
|
||||
updateFlow({ ...flow, data: reactFlowInstance.toObject() })
|
||||
}
|
||||
edges={edges}
|
||||
onNodesChange={onNodesChange}
|
||||
onEdgesChange={onEdgesChangeMod}
|
||||
onConnect={onConnect}
|
||||
onLoad={setReactFlowInstance}
|
||||
onInit={setReactFlowInstance}
|
||||
nodeTypes={nodeTypes}
|
||||
connectionLineComponent={connection}
|
||||
onDragOver={onDragOver}
|
||||
onDrop={onDrop}
|
||||
>
|
||||
<Background />
|
||||
<Controls></Controls>
|
||||
</ReactFlow>
|
||||
<Chat reactFlowInstance={reactFlowInstance} />
|
||||
</>
|
||||
) : (
|
||||
<></>
|
||||
)}
|
||||
</div>
|
||||
);
|
||||
}
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue