Skip to content

Commit 310ac1e

Browse files
committed
[*] refactor optimistic UI
1 parent 98c7c13 commit 310ac1e

File tree

1 file changed

+2
-10
lines changed

1 file changed

+2
-10
lines changed

internal/webui/src/pages/SourcesPage/components/SourcesGrid/components/EnabledSourceSwitch.tsx

Lines changed: 2 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,3 @@
1-
import { useEffect, useState } from "react";
21
import { Switch } from "@mui/material";
32
import { Source } from "types/Source/Source";
43
import { useEditSourceEnable } from "queries/Source";
@@ -9,23 +8,16 @@ type EnabledSourceSwitchProps = {
98
};
109

1110
export const EnabledSourceSwitch = ({ source }: EnabledSourceSwitchProps) => {
12-
const [checked, setChecked] = useState(source.IsEnabled);
13-
1411
const editEnabled = useEditSourceEnable();
15-
const { status } = editEnabled;
1612

1713
const handleChange = (_e: any, value: boolean) => {
18-
setChecked(value);
1914
editEnabled.mutate({
2015
...source,
2116
IsEnabled: value,
2217
});
2318
};
24-
useEffect(() => {
25-
if (status === "error") {
26-
setChecked((prev) => !prev);
27-
}
28-
}, [status]);
19+
20+
const checked = editEnabled.isPending ? !source.IsEnabled : source.IsEnabled;
2921

3022
return (
3123
<Switch

0 commit comments

Comments
 (0)