From 82819e1445d14d3076e7127616e348952887590b Mon Sep 17 00:00:00 2001 From: rcarteraz Date: Sun, 4 Jun 2023 12:32:30 -0700 Subject: [PATCH] Resolves issue with channels outside range shown --- src/components/tools/FrequencyCalculator.tsx | 19 +++++++++++-------- 1 file changed, 11 insertions(+), 8 deletions(-) diff --git a/src/components/tools/FrequencyCalculator.tsx b/src/components/tools/FrequencyCalculator.tsx index 6356ed54..82923759 100644 --- a/src/components/tools/FrequencyCalculator.tsx +++ b/src/components/tools/FrequencyCalculator.tsx @@ -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]);