fix(App.tsx): remove unused useContext import and hardReset function call
refactor(App.tsx): remove hardReset function call and add comment indicating any reset function refactor(flowsContext.tsx): remove hardReset function and update comment for tabId property refactor(flowsContext.tsx): remove hardReset function from useEffect hook refactor(flowsContext.tsx): remove hardReset function and update comment for hardReset function refactor(flowManagerStore.ts): add nodeId property and incrementNodeId function refactor(tabs/index.ts): remove hardReset function from FlowsContextType
This commit is contained in:
parent
aa44a70a02
commit
c61c67cc7c
4 changed files with 10 additions and 23 deletions
|
|
@ -16,7 +16,6 @@ import {
|
|||
FETCH_ERROR_MESSAGE,
|
||||
} from "./constants/constants";
|
||||
import { alertContext } from "./contexts/alertContext";
|
||||
import { FlowsContext } from "./contexts/flowsContext";
|
||||
import { locationContext } from "./contexts/locationContext";
|
||||
import { typesContext } from "./contexts/typesContext";
|
||||
import Router from "./routes";
|
||||
|
|
@ -30,7 +29,6 @@ export default function App() {
|
|||
setShowSideBar(true);
|
||||
setIsStackedOpen(true);
|
||||
}, [location.pathname, setCurrent, setIsStackedOpen, setShowSideBar]);
|
||||
const { hardReset } = useContext(FlowsContext);
|
||||
|
||||
const {
|
||||
errorData,
|
||||
|
|
@ -136,10 +134,7 @@ export default function App() {
|
|||
<div className="flex h-full flex-col">
|
||||
<ErrorBoundary
|
||||
onReset={() => {
|
||||
window.localStorage.removeItem("tabsData");
|
||||
window.localStorage.clear();
|
||||
hardReset();
|
||||
window.location.href = window.location.href;
|
||||
// any reset function
|
||||
}}
|
||||
FallbackComponent={CrashErrorComponent}
|
||||
>
|
||||
|
|
|
|||
|
|
@ -64,6 +64,7 @@ import { typesContext } from "./typesContext";
|
|||
const uid = new ShortUniqueId({ length: 5 });
|
||||
|
||||
const FlowsContextInitialValue: FlowsContextType = {
|
||||
//Remove tab id and get current id from url
|
||||
tabId: "",
|
||||
setTabId: (index: string) => {},
|
||||
isLoading: true,
|
||||
|
|
@ -83,7 +84,6 @@ const FlowsContextInitialValue: FlowsContextType = {
|
|||
uploadFlow: async () => "",
|
||||
isBuilt: false,
|
||||
setIsBuilt: (state: boolean) => {},
|
||||
hardReset: () => {},
|
||||
saveFlow: async (flow?: FlowType, silent?: boolean) => {},
|
||||
lastCopiedSelection: null,
|
||||
setLastCopiedSelection: (selection: any) => {},
|
||||
|
|
@ -209,12 +209,6 @@ export function FlowsProvider({ children }: { children: ReactNode }) {
|
|||
setEdgesInternal(newChange);
|
||||
};
|
||||
|
||||
useEffect(() => {
|
||||
if (!isAuthenticated) {
|
||||
hardReset();
|
||||
}
|
||||
}, [isAuthenticated]);
|
||||
|
||||
const newNodeId = useRef(uid());
|
||||
|
||||
function incrementNodeId() {
|
||||
|
|
@ -295,14 +289,6 @@ export function FlowsProvider({ children }: { children: ReactNode }) {
|
|||
setFlows(tabsData);
|
||||
}
|
||||
|
||||
function hardReset() {
|
||||
newNodeId.current = uid();
|
||||
setTabId("");
|
||||
setFlows([]);
|
||||
setIsLoading(true);
|
||||
setId(uid());
|
||||
}
|
||||
|
||||
/**
|
||||
* Downloads the current flow as a JSON file
|
||||
*/
|
||||
|
|
@ -799,7 +785,6 @@ export function FlowsProvider({ children }: { children: ReactNode }) {
|
|||
setIsBuilt,
|
||||
lastCopiedSelection,
|
||||
setLastCopiedSelection,
|
||||
hardReset,
|
||||
tabId,
|
||||
setTabId,
|
||||
flows,
|
||||
|
|
|
|||
|
|
@ -11,7 +11,9 @@ import {
|
|||
applyEdgeChanges,
|
||||
applyNodeChanges,
|
||||
} from "reactflow";
|
||||
import ShortUniqueId from "short-unique-id";
|
||||
import { create } from "zustand";
|
||||
const uid = new ShortUniqueId({ length: 5 });
|
||||
|
||||
type RFState = {
|
||||
nodes: Node[];
|
||||
|
|
@ -27,6 +29,8 @@ type RFState = {
|
|||
position: { x: number; y: number; paneX?: number; paneY?: number }
|
||||
) => void;
|
||||
lastCopiedSelection: { nodes: any; edges: any };
|
||||
nodeId: string;
|
||||
incrementNodeId: () => void;
|
||||
};
|
||||
|
||||
// this is our useStore hook that we can use in our components to get parts of the store and call actions
|
||||
|
|
@ -63,6 +67,10 @@ const useStore = create<RFState>((set, get) => ({
|
|||
},
|
||||
paste: (selection, position) => {},
|
||||
lastCopiedSelection: { nodes: [], edges: [] },
|
||||
nodeId: uid(),
|
||||
incrementNodeId: () => {
|
||||
set((state) => ({ nodeId: uid() }));
|
||||
},
|
||||
}));
|
||||
|
||||
export default useStore;
|
||||
|
|
|
|||
|
|
@ -40,7 +40,6 @@ export type FlowsContextType = {
|
|||
isComponent?: boolean;
|
||||
position?: XYPosition;
|
||||
}) => Promise<String | never>;
|
||||
hardReset: () => void;
|
||||
getNodeId: (nodeType: string) => string;
|
||||
isPending: boolean;
|
||||
setPending: (pending: boolean) => void;
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue