fixed routing, working perfectly

This commit is contained in:
Lucas Oliveira 2023-06-12 20:15:07 -03:00
commit 83e592d4d7
8 changed files with 87 additions and 73 deletions

Binary file not shown.

View file

@ -42,13 +42,6 @@ export default function App() {
const { flows, addFlow } = useContext(TabsContext); const { flows, addFlow } = useContext(TabsContext);
useEffect(() => {
//create the first flow
if (flows.length === 0) {
addFlow();
}
}, [addFlow, flows.length]);
// Initialize state variable for the list of alerts // Initialize state variable for the list of alerts
const [alertsList, setAlertsList] = useState< const [alertsList, setAlertsList] = useState<
Array<{ Array<{
@ -133,12 +126,8 @@ export default function App() {
}} }}
FallbackComponent={CrashErrorComponent} FallbackComponent={CrashErrorComponent}
> >
{flows.length !== 0 && (
<>
<Header /> <Header />
<Router /> <Router />
</>
)}
</ErrorBoundary> </ErrorBoundary>
<div></div> <div></div>
<div <div

View file

@ -36,6 +36,7 @@ export default function Header(){
}, [addFlow, flows.length, templates]); }, [addFlow, flows.length, templates]);
return ( return (
<div className="w-full h-16 flex justify-between items-center border-b"> <div className="w-full h-16 flex justify-between items-center border-b">
{flows.findIndex((f) => tabId === f.id) !== -1 &&
<MenuBar <MenuBar
activeTab={activeTab} activeTab={activeTab}
setRename={setRename} setRename={setRename}
@ -43,6 +44,7 @@ export default function Header(){
flows={flows} flows={flows}
tabId={tabId} tabId={tabId}
/> />
}
<div className="flex"> <div className="flex">
<Button>Explore</Button> <Button>Explore</Button>
<Button>My Flows</Button> <Button>My Flows</Button>

View file

@ -130,12 +130,6 @@ export function TabsProvider({ children }: { children: ReactNode }) {
}); });
}, [templates]); }, [templates]);
function getLocalStorageTabsData() {
let cookie = window.localStorage.getItem("tabsData");
let cookieObject: LangFlowState = JSON.parse(cookie);
return cookieObject;
}
function getTabsDataFromDB() { function getTabsDataFromDB() {
//get tabs from db //get tabs from db
return readFlowsFromDatabase(); return readFlowsFromDatabase();

View file

@ -1,6 +1,21 @@
import _ from "lodash"; import _ from "lodash";
import { useContext, useRef, useState, useEffect, useCallback } from "react"; import { useContext, useRef, useState, useEffect, useCallback } from "react";
import ReactFlow, { OnSelectionChangeParams, useNodesState, useEdgesState, useReactFlow, EdgeChange, Connection, addEdge, NodeDragHandler, SelectionDragHandler, OnEdgesDelete, Edge, updateEdge, Background, Controls } from "reactflow"; import ReactFlow, {
OnSelectionChangeParams,
useNodesState,
useEdgesState,
useReactFlow,
EdgeChange,
Connection,
addEdge,
NodeDragHandler,
SelectionDragHandler,
OnEdgesDelete,
Edge,
updateEdge,
Background,
Controls,
} from "reactflow";
import GenericNode from "../../../../CustomNodes/GenericNode"; import GenericNode from "../../../../CustomNodes/GenericNode";
import Chat from "../../../../components/chatComponent"; import Chat from "../../../../components/chatComponent";
import { alertContext } from "../../../../contexts/alertContext"; import { alertContext } from "../../../../contexts/alertContext";
@ -14,8 +29,6 @@ import useUndoRedo from "../../hooks/useUndoRedo";
import ConnectionLineComponent from "../ConnectionLineComponent"; import ConnectionLineComponent from "../ConnectionLineComponent";
import ExtraSidebar from "../extraSidebarComponent"; import ExtraSidebar from "../extraSidebarComponent";
const nodeTypes = { const nodeTypes = {
genericNode: GenericNode, genericNode: GenericNode,
}; };
@ -295,55 +308,68 @@ export default function Page({ flow }: { flow: FlowType }) {
const { setDisableCopyPaste } = useContext(TabsContext); const { setDisableCopyPaste } = useContext(TabsContext);
return ( return (
<div className="w-full h-full" ref={reactFlowWrapper}> <div className="flex grow shrink basis-auto min-h-0 flex-1 overflow-hidden">
{Object.keys(templates).length > 0 && Object.keys(types).length > 0 ? ( <ExtraSidebar />
<> {/* Main area */}
<ReactFlow <main className="min-w-0 flex-1 border-t border-gray-200 dark:border-gray-700 flex">
nodes={nodes} {/* Primary column */}
onMove={() => { <div className="w-full h-full">
updateFlow({ ...flow, data: reactFlowInstance.toObject() }); <div className="w-full h-full" ref={reactFlowWrapper}>
}} {Object.keys(templates).length > 0 &&
edges={edges} Object.keys(types).length > 0 ? (
onPaneClick={() => { <div className="w-full h-full">
setDisableCopyPaste(false); <ReactFlow
}} nodes={nodes}
onPaneMouseLeave={() => { onMove={() => {
setDisableCopyPaste(true); updateFlow({
}} ...flow,
onNodesChange={onNodesChange} data: reactFlowInstance.toObject(),
onEdgesChange={onEdgesChangeMod} });
onConnect={onConnect} }}
disableKeyboardA11y={true} edges={edges}
onLoad={setReactFlowInstance} onPaneClick={() => {
onInit={setReactFlowInstance} setDisableCopyPaste(false);
nodeTypes={nodeTypes} }}
onEdgeUpdate={onEdgeUpdate} onPaneMouseLeave={() => {
onEdgeUpdateStart={onEdgeUpdateStart} setDisableCopyPaste(true);
onEdgeUpdateEnd={onEdgeUpdateEnd} }}
onNodeDragStart={onNodeDragStart} onNodesChange={onNodesChange}
onSelectionDragStart={onSelectionDragStart} onEdgesChange={onEdgesChangeMod}
onSelectionEnd={onSelectionEnd} onConnect={onConnect}
onSelectionStart={onSelectionStart} disableKeyboardA11y={true}
onEdgesDelete={onEdgesDelete} onLoad={setReactFlowInstance}
connectionLineComponent={ConnectionLineComponent} onInit={setReactFlowInstance}
onDragOver={onDragOver} nodeTypes={nodeTypes}
onDrop={onDrop} onEdgeUpdate={onEdgeUpdate}
onNodesDelete={onDelete} onEdgeUpdateStart={onEdgeUpdateStart}
onSelectionChange={onSelectionChange} onEdgeUpdateEnd={onEdgeUpdateEnd}
nodesDraggable={!disableCopyPaste} onNodeDragStart={onNodeDragStart}
panOnDrag={!disableCopyPaste} onSelectionDragStart={onSelectionDragStart}
zoomOnDoubleClick={!disableCopyPaste} onSelectionEnd={onSelectionEnd}
selectNodesOnDrag={false} onSelectionStart={onSelectionStart}
className="theme-attribution" onEdgesDelete={onEdgesDelete}
> connectionLineComponent={ConnectionLineComponent}
<Background className="dark:bg-gray-900" /> onDragOver={onDragOver}
<Controls className="[&>button]:text-black [&>button]:dark:bg-gray-800 hover:[&>button]:dark:bg-gray-700 [&>button]:dark:text-gray-400 [&>button]:dark:fill-gray-400 [&>button]:dark:border-gray-600"></Controls> onDrop={onDrop}
</ReactFlow> onNodesDelete={onDelete}
<Chat flow={flow} reactFlowInstance={reactFlowInstance} /> onSelectionChange={onSelectionChange}
</> nodesDraggable={!disableCopyPaste}
) : ( panOnDrag={!disableCopyPaste}
<></> zoomOnDoubleClick={!disableCopyPaste}
)} selectNodesOnDrag={false}
className="theme-attribution"
>
<Background className="dark:bg-gray-900" />
<Controls className="[&>button]:text-black [&>button]:dark:bg-gray-800 hover:[&>button]:dark:bg-gray-700 [&>button]:dark:text-gray-400 [&>button]:dark:fill-gray-400 [&>button]:dark:border-gray-600"></Controls>
</ReactFlow>
<Chat flow={flow} reactFlowInstance={reactFlowInstance} />
</div>
) : (
<></>
)}
</div>
</div>
</main>
</div> </div>
); );
} }

View file

@ -49,7 +49,7 @@ export default function ExtraSidebar() {
} }
return ( return (
<div className="flex flex-col"> <div className="flex flex-col overflow-auto scrollbar-hide">
<div className="relative mt-2 flex items-center mb-2 mx-2"> <div className="relative mt-2 flex items-center mb-2 mx-2">
<input <input
type="text" type="text"

View file

@ -19,6 +19,7 @@ import ExportModal from "../../../../modals/exportModal";
import ApiModal from "../../../../modals/ApiModal"; import ApiModal from "../../../../modals/ApiModal";
import { alertContext } from "../../../../contexts/alertContext"; import { alertContext } from "../../../../contexts/alertContext";
import { updateFlowInDatabase } from "../../../../controllers/API"; import { updateFlowInDatabase } from "../../../../controllers/API";
import { Link } from "react-router-dom";
export const MenuBar = ({ activeTab, setRename, rename, flows, tabId }) => { export const MenuBar = ({ activeTab, setRename, rename, flows, tabId }) => {
const { updateFlow, setTabId, addFlow } = useContext(TabsContext); const { updateFlow, setTabId, addFlow } = useContext(TabsContext);
@ -129,6 +130,7 @@ export const MenuBar = ({ activeTab, setRename, rename, flows, tabId }) => {
<MenubarMenu> <MenubarMenu>
<MenubarTrigger>Flows</MenubarTrigger> <MenubarTrigger>Flows</MenubarTrigger>
<MenubarContent> <MenubarContent>
<MenubarRadioGroup <MenubarRadioGroup
value={tabId} value={tabId}
onValueChange={(value) => { onValueChange={(value) => {
@ -137,9 +139,12 @@ export const MenuBar = ({ activeTab, setRename, rename, flows, tabId }) => {
> >
{flows.map((flow, idx) => { {flows.map((flow, idx) => {
return ( return (
<MenubarRadioItem value={idx.toString()}> <Link to={"/flow/" + flow.id}>
<MenubarRadioItem value={flow.id}>
{emoji} {flow.name} {emoji} {flow.name}
</MenubarRadioItem> </MenubarRadioItem>
</Link>
); );
})} })}
</MenubarRadioGroup> </MenubarRadioGroup>

View file

@ -30,7 +30,6 @@ export default function HomePage() {
setTabId, setTabId,
} = useContext(TabsContext); } = useContext(TabsContext);
return ( return (
Object.keys(flows).length !== 0 && (
<div <div
className="w-full h-full flex flex-col bg-muted" className="w-full h-full flex flex-col bg-muted"
> >
@ -45,6 +44,5 @@ export default function HomePage() {
))} ))}
</div> </div>
</div> </div>
)
); );
} }