From 800e0d82a2522a6ef023f8b8247570a59d15e667 Mon Sep 17 00:00:00 2001 From: Tom Butcher Date: Fri, 5 Sep 2025 23:21:14 +0100 Subject: [PATCH] Enhance PrinterTemperaturePanel component by adding sendObjectAction for temperature setting; refactor handleSetTemperature to support async operations and improve event handling for temperature input changes. --- .../common/PrinterTemperaturePanel.jsx | 50 +++++++++++++------ 1 file changed, 34 insertions(+), 16 deletions(-) diff --git a/src/components/Dashboard/common/PrinterTemperaturePanel.jsx b/src/components/Dashboard/common/PrinterTemperaturePanel.jsx index 165c77c..b64b5d2 100644 --- a/src/components/Dashboard/common/PrinterTemperaturePanel.jsx +++ b/src/components/Dashboard/common/PrinterTemperaturePanel.jsx @@ -53,7 +53,8 @@ const PrinterTemperaturePanel = ({ ambiant: 0 }) - const { subscribeToObjectEvent, connected } = useContext(ApiServerContext) + const { subscribeToObjectEvent, connected, sendObjectAction } = + useContext(ApiServerContext) // Sync input values with actual temperature targets useEffect(() => { @@ -90,10 +91,19 @@ const PrinterTemperaturePanel = ({ const [extruderTarget, setExtruderTarget] = useState(0) const [bedTarget, setBedTarget] = useState(0) - const handleSetTemperature = (data) => { + const handleSetTemperature = async (data) => { if (id && connected == true) { - console.log(data) - //sendObjectAction(id, 'printer', { type: 'setTemperature', data }) + await sendObjectAction( + id, + 'printer', + { + type: 'setTemperature', + data + }, + (result) => { + console.log('setTemperatureResult', result) + } + ) } } @@ -169,16 +179,20 @@ const PrinterTemperaturePanel = ({ style={{ width: '120px' }} addonAfter='°C' onChange={(value) => setExtruderTarget(value || 0)} - onPressEnter={handleSetTemperature({ - extruder: { target: extruderTarget } - })} + onPressEnter={() => + handleSetTemperature({ + extruder: { target: extruderTarget } + }) + } /> @@ -226,16 +240,20 @@ const PrinterTemperaturePanel = ({ style={{ width: '120px' }} addonAfter='°C' onChange={(value) => setBedTarget(value || 0)} - onPressEnter={handleSetTemperature({ - bed: { target: bedTarget } - })} + onPressEnter={() => + handleSetTemperature({ + bed: { target: bedTarget } + }) + } />