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
This commit is contained in:
anovazzi1 2023-09-26 19:42:46 -03:00 committed by anovazzi1
commit 6fd2b0c743
3 changed files with 7 additions and 5 deletions

View file

@ -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);

View file

@ -168,7 +168,7 @@ export default function Page({
let updatedSeconds = prevSeconds + 1;
if (updatedSeconds % 30 === 0) {
saveFlow(flow);
saveFlow(flow, true);
updatedSeconds = 0;
}

View file

@ -2,7 +2,7 @@ import { tweakType } from "../components";
import { FlowType } from "../flow";
export type TabsContextType = {
saveFlow: (flow: FlowType) => Promise<void>;
saveFlow: (flow: FlowType, silent?: boolean) => Promise<void>;
save: () => void;
tabId: string;
isLoading: boolean;