mirror of
				https://gitlab.nic.cz/turris/reforis/foris-js.git
				synced 2025-11-03 23:00:31 +01:00 
			
		
		
		
	Set best Wi-Fi HT mode depending on the checked frequency
This commit is contained in:
		@@ -64,6 +64,7 @@ DeviceForm.propTypes = {
 | 
				
			|||||||
        channel: PropTypes.string.isRequired,
 | 
					        channel: PropTypes.string.isRequired,
 | 
				
			||||||
        guest_wifi: PropTypes.object.isRequired,
 | 
					        guest_wifi: PropTypes.object.isRequired,
 | 
				
			||||||
        encryption: PropTypes.string.isRequired,
 | 
					        encryption: PropTypes.string.isRequired,
 | 
				
			||||||
 | 
					        available_bands: PropTypes.array.isRequired,
 | 
				
			||||||
    }),
 | 
					    }),
 | 
				
			||||||
    formErrors: PropTypes.object.isRequired,
 | 
					    formErrors: PropTypes.object.isRequired,
 | 
				
			||||||
    setFormValue: PropTypes.func.isRequired,
 | 
					    setFormValue: PropTypes.func.isRequired,
 | 
				
			||||||
@@ -87,6 +88,7 @@ function DeviceForm({
 | 
				
			|||||||
    ...props
 | 
					    ...props
 | 
				
			||||||
}) {
 | 
					}) {
 | 
				
			||||||
    const deviceID = formData.id;
 | 
					    const deviceID = formData.id;
 | 
				
			||||||
 | 
					    const bnds = formData.available_bands;
 | 
				
			||||||
    return (
 | 
					    return (
 | 
				
			||||||
        <>
 | 
					        <>
 | 
				
			||||||
            <Switch
 | 
					            <Switch
 | 
				
			||||||
@@ -159,18 +161,24 @@ function DeviceForm({
 | 
				
			|||||||
                        value={formData.hwmode}
 | 
					                        value={formData.hwmode}
 | 
				
			||||||
                        helpText={HELP_TEXTS.hwmode}
 | 
					                        helpText={HELP_TEXTS.hwmode}
 | 
				
			||||||
                        inline
 | 
					                        inline
 | 
				
			||||||
                        onChange={setFormValue((value) => ({
 | 
					                        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: {
 | 
					                                devices: {
 | 
				
			||||||
                                    [deviceIndex]: {
 | 
					                                    [deviceIndex]: {
 | 
				
			||||||
                                        hwmode: { $set: value },
 | 
					                                        hwmode: { $set: value },
 | 
				
			||||||
                                        channel: { $set: "0" },
 | 
					                                        channel: { $set: "0" },
 | 
				
			||||||
                                        htmode: {
 | 
					                                        htmode: {
 | 
				
			||||||
                                            $set:
 | 
					                                            $set:
 | 
				
			||||||
                                            value === "11a" ? "VHT80" : "HT20",
 | 
					                                                // Set HT mode depending on checked frequency
 | 
				
			||||||
 | 
					                                                value === "11a" ? best5 : best2,
 | 
				
			||||||
                                        },
 | 
					                                        },
 | 
				
			||||||
                                    },
 | 
					                                    },
 | 
				
			||||||
                                },
 | 
					                                },
 | 
				
			||||||
                        }))}
 | 
					                            };
 | 
				
			||||||
 | 
					                        })}
 | 
				
			||||||
                        {...props}
 | 
					                        {...props}
 | 
				
			||||||
                    />
 | 
					                    />
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 
 | 
				
			|||||||
		Reference in New Issue
	
	Block a user