mirror of https://github.com/jetkvm/kvm.git
refactor: fix infinite useEffect
This commit is contained in:
parent
d1824c5727
commit
bc1992ea13
|
|
@ -12,19 +12,19 @@ import notifications from "../notifications";
|
||||||
|
|
||||||
export default function SettingsAudioRoute() {
|
export default function SettingsAudioRoute() {
|
||||||
const { send } = useJsonRpc();
|
const { send } = useJsonRpc();
|
||||||
const settings = useSettingsStore();
|
const { setAudioOutputEnabled, setAudioInputAutoEnable, audioOutputEnabled, audioInputAutoEnable } = useSettingsStore();
|
||||||
|
|
||||||
useEffect(() => {
|
useEffect(() => {
|
||||||
send("getAudioOutputEnabled", {}, (resp: JsonRpcResponse) => {
|
send("getAudioOutputEnabled", {}, (resp: JsonRpcResponse) => {
|
||||||
if ("error" in resp) return;
|
if ("error" in resp) return;
|
||||||
settings.setAudioOutputEnabled(resp.result as boolean);
|
setAudioOutputEnabled(resp.result as boolean);
|
||||||
});
|
});
|
||||||
|
|
||||||
send("getAudioInputAutoEnable", {}, (resp: JsonRpcResponse) => {
|
send("getAudioInputAutoEnable", {}, (resp: JsonRpcResponse) => {
|
||||||
if ("error" in resp) return;
|
if ("error" in resp) return;
|
||||||
settings.setAudioInputAutoEnable(resp.result as boolean);
|
setAudioInputAutoEnable(resp.result as boolean);
|
||||||
});
|
});
|
||||||
}, [send, settings]);
|
}, [send, setAudioOutputEnabled, setAudioInputAutoEnable]);
|
||||||
|
|
||||||
const handleAudioOutputEnabledChange = (enabled: boolean) => {
|
const handleAudioOutputEnabledChange = (enabled: boolean) => {
|
||||||
send("setAudioOutputEnabled", { enabled }, (resp: JsonRpcResponse) => {
|
send("setAudioOutputEnabled", { enabled }, (resp: JsonRpcResponse) => {
|
||||||
|
|
@ -35,7 +35,7 @@ export default function SettingsAudioRoute() {
|
||||||
notifications.error(errorMsg);
|
notifications.error(errorMsg);
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
settings.setAudioOutputEnabled(enabled);
|
setAudioOutputEnabled(enabled);
|
||||||
const successMsg = enabled ? m.audio_output_enabled() : m.audio_output_disabled();
|
const successMsg = enabled ? m.audio_output_enabled() : m.audio_output_disabled();
|
||||||
notifications.success(successMsg);
|
notifications.success(successMsg);
|
||||||
});
|
});
|
||||||
|
|
@ -47,7 +47,7 @@ export default function SettingsAudioRoute() {
|
||||||
notifications.error(String(resp.error.data || m.unknown_error()));
|
notifications.error(String(resp.error.data || m.unknown_error()));
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
settings.setAudioInputAutoEnable(enabled);
|
setAudioInputAutoEnable(enabled);
|
||||||
const successMsg = enabled
|
const successMsg = enabled
|
||||||
? m.audio_input_auto_enable_enabled()
|
? m.audio_input_auto_enable_enabled()
|
||||||
: m.audio_input_auto_enable_disabled();
|
: m.audio_input_auto_enable_disabled();
|
||||||
|
|
@ -67,7 +67,7 @@ export default function SettingsAudioRoute() {
|
||||||
description={m.audio_settings_output_description()}
|
description={m.audio_settings_output_description()}
|
||||||
>
|
>
|
||||||
<Checkbox
|
<Checkbox
|
||||||
checked={settings.audioOutputEnabled || false}
|
checked={audioOutputEnabled || false}
|
||||||
onChange={(e) => handleAudioOutputEnabledChange(e.target.checked)}
|
onChange={(e) => handleAudioOutputEnabledChange(e.target.checked)}
|
||||||
/>
|
/>
|
||||||
</SettingsItem>
|
</SettingsItem>
|
||||||
|
|
@ -77,7 +77,7 @@ export default function SettingsAudioRoute() {
|
||||||
description={m.audio_settings_auto_enable_microphone_description()}
|
description={m.audio_settings_auto_enable_microphone_description()}
|
||||||
>
|
>
|
||||||
<Checkbox
|
<Checkbox
|
||||||
checked={settings.audioInputAutoEnable || false}
|
checked={audioInputAutoEnable || false}
|
||||||
onChange={(e) => handleAudioInputAutoEnableChange(e.target.checked)}
|
onChange={(e) => handleAudioInputAutoEnableChange(e.target.checked)}
|
||||||
/>
|
/>
|
||||||
</SettingsItem>
|
</SettingsItem>
|
||||||
|
|
|
||||||
Loading…
Reference in New Issue