mirror of https://github.com/jetkvm/kvm.git
fix: resolve React hooks violation in hardware settings
Moved getVideoSleepMode useEffect before early returns to comply with React Rules of Hooks. All hooks must be called in the same order on every component render, before any conditional returns. This completes the merge from dev branch, preserving both: - Permission-based access control from multi-session branch - HDMI sleep mode power saving feature from dev branch
This commit is contained in:
parent
8dc013d8fe
commit
c8808ee3b2
|
|
@ -94,6 +94,17 @@ export default function SettingsHardwareRoute() {
|
|||
}
|
||||
}, [send, setBacklightSettings, isLoading, permissions]);
|
||||
|
||||
useEffect(() => {
|
||||
send("getVideoSleepMode", {}, (resp: JsonRpcResponse) => {
|
||||
if ("error" in resp) {
|
||||
console.error("Failed to get power saving mode:", resp.error);
|
||||
return;
|
||||
}
|
||||
const result = resp.result as { enabled: boolean; duration: number };
|
||||
setPowerSavingEnabled(result.duration >= 0);
|
||||
});
|
||||
}, [send]);
|
||||
|
||||
// Return early if permissions are loading
|
||||
if (isLoading) {
|
||||
return (
|
||||
|
|
@ -112,17 +123,6 @@ export default function SettingsHardwareRoute() {
|
|||
);
|
||||
}
|
||||
|
||||
useEffect(() => {
|
||||
send("getVideoSleepMode", {}, (resp: JsonRpcResponse) => {
|
||||
if ("error" in resp) {
|
||||
console.error("Failed to get power saving mode:", resp.error);
|
||||
return;
|
||||
}
|
||||
const result = resp.result as { enabled: boolean; duration: number };
|
||||
setPowerSavingEnabled(result.duration >= 0);
|
||||
});
|
||||
}, [send]);
|
||||
|
||||
return (
|
||||
<div className="space-y-4">
|
||||
<SettingsPageHeader
|
||||
|
|
|
|||
Loading…
Reference in New Issue