Skip to content

Commit

Permalink
chore: get state after switch update
Browse files Browse the repository at this point in the history
  • Loading branch information
mdvanes committed May 22, 2024
1 parent 002ff5a commit cc34a44
Showing 1 changed file with 13 additions and 13 deletions.
26 changes: 13 additions & 13 deletions apps/client/src/Components/Molecules/SwitchBarList/HaSwitchBar.tsx
Original file line number Diff line number Diff line change
@@ -1,42 +1,42 @@
import { HomeRemoteHaSwitch } from "@homeremote/types";
import { FC } from "react";
import { useUpdateHaSwitchMutation } from "../../../Services/generated/switchesApi";
import { useAppDispatch } from "../../../store";
import SwitchBar from "./SwitchBar";
import SwitchBarInnerButton from "./SwitchBarInnerButton";
import { getSwitches } from "./getSwitchesThunk";

interface HaSwitchBarProps {
haSwitch: HomeRemoteHaSwitch;
}

const HaSwitchBar: FC<HaSwitchBarProps> = ({ haSwitch }) => {
// Implement the HaSwitchBar component logic here
const [updateHaSwitch] = useUpdateHaSwitchMutation();
const dispatch = useAppDispatch();

const toggle = (nextState: "On" | "Off") => async () => {
await updateHaSwitch({
entityId: haSwitch.idx,
body: { state: nextState },
});
dispatch(getSwitches());
};

return (
<SwitchBar
label={haSwitch.name}
leftButton={
<SwitchBarInnerButton
isReadOnly={false}
clickAction={() => {
updateHaSwitch({
entityId: haSwitch.idx,
body: { state: "On" },
});
}}
clickAction={toggle("On")}
icon="radio_button_checked"
isActive={haSwitch.status === "On"}
/>
}
rightButton={
<SwitchBarInnerButton
isReadOnly={false}
clickAction={() => {
updateHaSwitch({
entityId: haSwitch.idx,
body: { state: "Off" },
});
}}
clickAction={toggle("Off")}
icon="radio_button_unchecked"
isActive={haSwitch.status === "Off"}
/>
Expand Down

0 comments on commit cc34a44

Please sign in to comment.