From b95cfb664db2b9f05ee43355f49990972551264c Mon Sep 17 00:00:00 2001 From: Aleksandr Gumroian Date: Fri, 18 Feb 2022 12:35:41 +0100 Subject: [PATCH] Set best Wi-Fi HT mode depending on the checked frequency --- src/common/WiFiSettings/WiFiForm.js | 28 ++++++++++++++++++---------- 1 file changed, 18 insertions(+), 10 deletions(-) diff --git a/src/common/WiFiSettings/WiFiForm.js b/src/common/WiFiSettings/WiFiForm.js index 02f50aa..5115a2a 100644 --- a/src/common/WiFiSettings/WiFiForm.js +++ b/src/common/WiFiSettings/WiFiForm.js @@ -64,6 +64,7 @@ DeviceForm.propTypes = { channel: PropTypes.string.isRequired, guest_wifi: PropTypes.object.isRequired, encryption: PropTypes.string.isRequired, + available_bands: PropTypes.array.isRequired, }), formErrors: PropTypes.object.isRequired, setFormValue: PropTypes.func.isRequired, @@ -87,6 +88,7 @@ function DeviceForm({ ...props }) { const deviceID = formData.id; + const bnds = formData.available_bands; return ( <> ({ - devices: { - [deviceIndex]: { - hwmode: { $set: value }, - channel: { $set: "0" }, - htmode: { - $set: - value === "11a" ? "VHT80" : "HT20", + onChange={setFormValue((value) => { + // Get the last item in an array of available HT modes + const [best2] = bnds[0].available_htmodes.slice(-1); + const [best5] = bnds[1].available_htmodes.slice(-1); + return { + devices: { + [deviceIndex]: { + hwmode: { $set: value }, + channel: { $set: "0" }, + htmode: { + $set: + // Set HT mode depending on checked frequency + value === "11a" ? best5 : best2, + }, }, }, - }, - }))} + }; + })} {...props} />