Resolves issue with channels outside range shown

This commit is contained in:
rcarteraz 2023-06-04 12:32:30 -07:00 committed by Sacha Weatherstone
parent e2a85f629e
commit 82819e1445

View file

@ -263,21 +263,24 @@ export const FrequencyCalculator = (): JSX.Element => {
useEffect(() => {
const selectedRegion = RegionData.get(region);
const selectedModemPreset = modemPresets.get(modemPreset);
setNumChannels(
Math.floor(
(selectedRegion.freq_end - selectedRegion.freq_start) /
(selectedRegion.spacing + selectedModemPreset.bw / 1000),
),
const calculatedNumChannels = Math.floor(
(selectedRegion.freq_end - selectedRegion.freq_start) /
(selectedRegion.spacing + selectedModemPreset.bw / 1000),
);
if (channel >= numChannels) {
setChannel(numChannels - 1);
setNumChannels(calculatedNumChannels);
let updatedChannel = channel;
if (updatedChannel >= calculatedNumChannels) {
updatedChannel = 0;
}
setChannel(updatedChannel);
setChannelFrequency(
selectedRegion.freq_start +
selectedModemPreset.bw / 2000 +
channel * (selectedModemPreset.bw / 1000),
updatedChannel * (selectedModemPreset.bw / 1000),
);
}, [modemPreset, region, channel]);