From 6fd2b0c7432efa374e9052cea1458861f5f7559d Mon Sep 17 00:00:00 2001 From: anovazzi1 Date: Tue, 26 Sep 2023 19:42:46 -0300 Subject: [PATCH] fix(tabsContext.tsx): add optional 'silent' parameter to the saveFlow function to control whether to show success message or not fix(PageComponent/index.tsx): pass 'true' as the second argument to the saveFlow function to prevent showing success message when saving flow every 30 seconds fix(types/tabs/index.ts): update the saveFlow function signature to include the optional 'silent' parameter --- src/frontend/src/contexts/tabsContext.tsx | 8 +++++--- .../src/pages/FlowPage/components/PageComponent/index.tsx | 2 +- src/frontend/src/types/tabs/index.ts | 2 +- 3 files changed, 7 insertions(+), 5 deletions(-) diff --git a/src/frontend/src/contexts/tabsContext.tsx b/src/frontend/src/contexts/tabsContext.tsx index 6190a6e56..88f5005fe 100644 --- a/src/frontend/src/contexts/tabsContext.tsx +++ b/src/frontend/src/contexts/tabsContext.tsx @@ -52,7 +52,7 @@ const TabsContextInitialValue: TabsContextType = { isBuilt: false, setIsBuilt: (state: boolean) => {}, hardReset: () => {}, - saveFlow: async (flow: FlowType) => {}, + saveFlow: async (flow: FlowType, silent?: boolean) => {}, lastCopiedSelection: null, setLastCopiedSelection: (selection: any) => {}, tabsState: {}, @@ -588,13 +588,15 @@ export function TabsProvider({ children }: { children: ReactNode }) { }); } - async function saveFlow(newFlow: FlowType) { + async function saveFlow(newFlow: FlowType, silent?: boolean) { try { // updates flow in db const updatedFlow = await updateFlowInDatabase(newFlow); if (updatedFlow) { // updates flow in state - setSuccessData({ title: "Changes saved successfully" }); + if (!silent) { + setSuccessData({ title: "Changes saved successfully" }); + } setFlows((prevState) => { const newFlows = [...prevState]; const index = newFlows.findIndex((flow) => flow.id === newFlow.id); diff --git a/src/frontend/src/pages/FlowPage/components/PageComponent/index.tsx b/src/frontend/src/pages/FlowPage/components/PageComponent/index.tsx index 73b322d16..beef5a201 100644 --- a/src/frontend/src/pages/FlowPage/components/PageComponent/index.tsx +++ b/src/frontend/src/pages/FlowPage/components/PageComponent/index.tsx @@ -168,7 +168,7 @@ export default function Page({ let updatedSeconds = prevSeconds + 1; if (updatedSeconds % 30 === 0) { - saveFlow(flow); + saveFlow(flow, true); updatedSeconds = 0; } diff --git a/src/frontend/src/types/tabs/index.ts b/src/frontend/src/types/tabs/index.ts index 4c5b99dd7..a06b514a4 100644 --- a/src/frontend/src/types/tabs/index.ts +++ b/src/frontend/src/types/tabs/index.ts @@ -2,7 +2,7 @@ import { tweakType } from "../components"; import { FlowType } from "../flow"; export type TabsContextType = { - saveFlow: (flow: FlowType) => Promise; + saveFlow: (flow: FlowType, silent?: boolean) => Promise; save: () => void; tabId: string; isLoading: boolean;