From fedc6c889a4acbd873bdcc119777416d8ad5b2f2 Mon Sep 17 00:00:00 2001 From: Ari Date: Wed, 13 Apr 2022 22:06:38 -0400 Subject: [PATCH] added lazy saving --- .../AutomationEditor/index.stories.tsx | 4 +- .../src/components/AutomationEditor/index.tsx | 48 ++++++++++++++----- .../src/components/AutomationEditor/styles.ts | 10 +++- webapp/src/components/Inputs/styles.ts | 4 +- 4 files changed, 49 insertions(+), 17 deletions(-) diff --git a/webapp/src/components/AutomationEditor/index.stories.tsx b/webapp/src/components/AutomationEditor/index.stories.tsx index 659a0c1..e36363d 100644 --- a/webapp/src/components/AutomationEditor/index.stories.tsx +++ b/webapp/src/components/AutomationEditor/index.stories.tsx @@ -27,7 +27,9 @@ const Template: ComponentStory = args => { { + window.setTimeout(() => setState(s), 3000) + }} /> } diff --git a/webapp/src/components/AutomationEditor/index.tsx b/webapp/src/components/AutomationEditor/index.tsx index bde36ee..ba31e98 100644 --- a/webapp/src/components/AutomationEditor/index.tsx +++ b/webapp/src/components/AutomationEditor/index.tsx @@ -1,8 +1,8 @@ import "./index.css"; import { DAGBoardElmDims } from "components/DAGSvgs/DAGBoard"; -import { ArrowIcon, ZoomIcon } from "components/Icons"; +import { ArrowIcon, CheckMarkIcon, ZoomIcon } from "components/Icons"; import { SequenceNodes } from "components/SequenceNodes"; -import { FC, useState } from "react"; +import { FC, useEffect, useState } from "react"; import { AutomationData, AutomationSequenceNode } from "types/automations"; import useWindowSize from "utils/useWindowSize"; import { AutoInfoBox } from "./AutoInfoBox"; @@ -13,6 +13,7 @@ import { AutomationTrigger } from 'types/automations/triggers'; import { Modal } from "components/Modal"; import { NodeEditor } from "components/NodeEditor"; import { ButtonIcon } from "components/Icons/ButtonIcons"; +import { Button } from "components/Inputs/Button"; interface TriggerEditorModalState { trigger: AutomationTrigger; @@ -25,10 +26,13 @@ interface Props { } export const AutomationEditor: FC = ({ dims, - automation, - onUpdate, + automation: propsAutos, + onUpdate: propsOnUpdate, }) => { // state + const [[autoChanged, automation], setAutomation] = useState<[ + 'unchanged' | 'changed' | 'loading', AutomationData] + >(['unchanged', propsAutos]); const [zoomLevel, setZoomLevel] = useState(40); const { ratioWbh } = useWindowSize(); const [closeInfo, setCloseInfo] = useState(false); @@ -47,6 +51,12 @@ export const AutomationEditor: FC = ({ ...automation, trigger, }); + const onUpdate = (a: AutomationData) => setAutomation(['changed', a]); + + // effects + useEffect(() => { + setAutomation(['unchanged', propsAutos]); + }, [propsAutos]) // render return
@@ -75,14 +85,28 @@ export const AutomationEditor: FC = ({
- - setZoomLevel(z.target.valueAsNumber ?? 40)} - /> +
+ + setZoomLevel(z.target.valueAsNumber ?? 40)} + /> +
+ {autoChanged !== 'unchanged' && }
({ export const useButtonStyles = createAppUseStyles<{}>(theme => ({ input: { ...commonInputStyle(theme).input, - paddingTop: '2%', - paddingBottom: '2%', + paddingTop: '1em', + paddingBottom: '1em', cursor: 'pointer', }, }));