diff --git a/src/pages/fireplace/[mac].tsx b/src/pages/fireplace/[mac].tsx index a57f7b5..eb1ad88 100644 --- a/src/pages/fireplace/[mac].tsx +++ b/src/pages/fireplace/[mac].tsx @@ -67,9 +67,20 @@ const Fireplace: NextPage = () => { fetch(); }, [addErrorCallback, mac, token]); - const onPowerChange = (value: number) => { - setPower(token!, mac!, value); + const onPowerChange = async (value: number) => { + // set the state before hand to avoid the lag feeling setPowerState(Boolean(value)); + try { + await setPower(token!, mac!, value); + } catch (error) { + console.error(error); + addErrorCallback({ + title: "Power State Update Failed", + body: "Unable to change the power state. Please try again.", + }); + // rollback to the actual/previous value + setPowerState(powerState); + } }; const onTemperatureChange = async (newTemperature: number) => {