bug found migrate template code to types context

This commit is contained in:
anovazzi1 2023-04-24 18:31:03 -03:00
commit 9e76c50f09
6 changed files with 20 additions and 36 deletions

View file

@ -5,24 +5,21 @@ import { LocationProvider } from "./locationContext";
import PopUpProvider from "./popUpContext";
import { TabsProvider } from "./tabsContext";
import { TypesProvider } from "./typesContext";
import { TemplatesProvider } from "./templatesContext";
export default function ContextWrapper({ children }: { children: ReactNode }) {
//element to wrap all context
return (
<>
<DarkProvider>
<LocationProvider>
<AlertProvider>
<TemplatesProvider>
<TypesProvider>
<LocationProvider>
<AlertProvider>
<TabsProvider>
<PopUpProvider>
<TypesProvider>{children}</TypesProvider>
</PopUpProvider>
<PopUpProvider>{children}</PopUpProvider>
</TabsProvider>
</TemplatesProvider>
</AlertProvider>
</LocationProvider>
</AlertProvider>
</LocationProvider>
</TypesProvider>
</DarkProvider>
</>
);

View file

@ -3,7 +3,7 @@ import { FlowType } from "../types/flow";
import { LangFlowState, TabsContextType } from "../types/tabs";
import { normalCaseToSnakeCase } from "../utils";
import { alertContext } from "./alertContext";
import { TemplatesContext } from "./templatesContext";
import { typesContext } from "./typesContext";
const TabsContextInitialValue: TabsContextType = {
save:()=>{},
@ -31,7 +31,7 @@ export function TabsProvider({ children }: { children: ReactNode }) {
const [flows, setFlows] = useState<Array<FlowType>>([]);
const [id, setId] = useState(0);
const [lockChat, setLockChat] = useState(false);
const {templates} = useContext(TemplatesContext)
const {templates} = useContext(typesContext )
const newNodeId = useRef(0);
function incrementNodeId() {
@ -56,7 +56,7 @@ export function TabsProvider({ children }: { children: ReactNode }) {
useEffect(() => {
//get tabs locally saved
let cookie = window.localStorage.getItem("tabsData");
if (cookie && Object.keys(templates).length>0) {
if (cookie) {
console.log(templates)
console.log(Object.keys(templates).length)
let cookieObject:LangFlowState = JSON.parse(cookie);

View file

@ -1,20 +0,0 @@
import { createContext, ReactNode, useState } from "react";
import { TemplateContextType } from "../types/templatesContext";
//context to share types adn functions from nodes to flow
const initialValue: TemplateContextType = {
templates: {},
setTemplates: () => {},
};
export const TemplatesContext =
createContext<TemplateContextType>(initialValue);
export function TemplatesProvider({ children }: { children: ReactNode }) {
const [templates, setTemplates] = useState({});
return (
<TemplatesContext.Provider value={{ templates, setTemplates }}>
{children}
</TemplatesContext.Provider>
);
}

View file

@ -10,6 +10,8 @@ const initialValue:typesContextType = {
deleteNode: () => {},
types: {},
setTypes: () => {},
templates: {},
setTemplates: () => {},
};
export const typesContext = createContext<typesContextType>(initialValue);
@ -17,6 +19,7 @@ export const typesContext = createContext<typesContextType>(initialValue);
export function TypesProvider({ children }:{children:ReactNode}) {
const [types, setTypes] = useState({});
const [reactFlowInstance, setReactFlowInstance] = useState(null);
const [templates, setTemplates] = useState({});
function deleteNode(idx:string) {
reactFlowInstance.setNodes(
reactFlowInstance.getNodes().filter((n:Node) => n.id !== idx)
@ -31,6 +34,8 @@ export function TypesProvider({ children }:{children:ReactNode}) {
reactFlowInstance,
setReactFlowInstance,
deleteNode,
setTemplates,
templates
}}
>
{children}

View file

@ -9,12 +9,11 @@ import {
APIKindType,
APIObjectType,
} from "../../../../types/api";
import { TemplatesContext } from "../../../../contexts/templatesContext";
export default function ExtraSidebar() {
const [data, setData] = useState({});
const { setTypes } = useContext(typesContext);
const { setTemplates } = useContext(TemplatesContext);
const { setTemplates } = useContext(typesContext);
useEffect(() => {
async function getTypes(): Promise<void> {

View file

@ -1,6 +1,7 @@
import { ReactFlowInstance } from "reactflow";
const types:{[char: string]: string}={}
const types:{[char: string]: string}={};
const template:{[char: string]: string}={}
export type typesContextType = {
reactFlowInstance: ReactFlowInstance|null;
@ -8,4 +9,6 @@ export type typesContextType = {
deleteNode: (idx: string) => void;
types: typeof types;
setTypes: (newState: {}) => void;
templates: typeof template;
setTemplates: (newState: {}) => void;
};