Skip to content

Commit

Permalink
🚸 Improve set temperature UX
Browse files Browse the repository at this point in the history
Update the UI before the temperature change gets effective to prevent
the lagging feeling.
Value would get rolled back if it errors while setting.
  • Loading branch information
AndreMiras committed Dec 8, 2024
1 parent c3c89a2 commit d362283
Showing 1 changed file with 4 additions and 1 deletion.
5 changes: 4 additions & 1 deletion src/pages/fireplace/[mac].tsx
Original file line number Diff line number Diff line change
Expand Up @@ -74,14 +74,17 @@ const Fireplace: NextPage = () => {

const onTemperatureChange = async (newTemperature: number) => {
try {
await setTargetTemperature(token!, mac!, newTemperature);
// set the state before hand to avoid the lag feeling
setTemperature(newTemperature);
await setTargetTemperature(token!, mac!, newTemperature);
} catch (error) {
console.error(error);
addErrorCallback({
title: "Temperature Update Failed",
body: "Unable to update the temperature. Please try again.",
});
// rollback the temperature to the actual/previous) value
setTemperature(temperature);
}
};

Expand Down

0 comments on commit d362283

Please sign in to comment.