From 0e0c138146890eeaf29a50be3545c79549bd67be Mon Sep 17 00:00:00 2001 From: Maximilian Giller <m.giller@tu-bs.de> Date: Fri, 14 Oct 2022 02:35:19 +0200 Subject: [PATCH] Fixed change trigger calling too often --- src/editor/components/referenceentry.tsx | 17 +++++++++++++++-- 1 file changed, 15 insertions(+), 2 deletions(-) diff --git a/src/editor/components/referenceentry.tsx b/src/editor/components/referenceentry.tsx index c0914d8..e674e83 100644 --- a/src/editor/components/referenceentry.tsx +++ b/src/editor/components/referenceentry.tsx @@ -1,4 +1,4 @@ -import React from "react"; +import React, { useState } from "react"; import { DescriptiveReference } from "../../common/graph/node"; import "./nodetypeentry.css"; @@ -13,15 +13,28 @@ function ReferenceEntry({ onReferenceDelete, onReferenceChange, }: ReferenceEntryProps) { + const [change, setChange] = useState(false); + const onPropChange = ( prop: keyof DescriptiveReference, newValue: string ) => { reference[prop] = newValue; + setChange(true); + }; + + const handleOnBlur = () => { + // Did anything change? + if (!change) { + return; + } + + onReferenceChange(reference); + setChange(false); }; return ( - <div className="reference" onBlur={() => onReferenceChange(reference)}> + <div className="reference" onBlur={handleOnBlur}> <label htmlFor="reference-url">Url</label> <br /> <input -- GitLab