From fdea3f8269d1ca0ca48d3aa5962ae2ba4538e07a Mon Sep 17 00:00:00 2001 From: Iain Collins Date: Sat, 26 Oct 2024 05:48:13 +0100 Subject: [PATCH] Fix for hitting enter after typing location name in filter Threre are a bunch of other bugs with this behaviour, mostly performance related, but can get to that in refactoring --- components/tab-options/commodities.js | 19 ++++++++++++++----- package.json | 2 +- pages/commodity/[commodity-name]/index.js | 8 ++++---- 3 files changed, 19 insertions(+), 10 deletions(-) diff --git a/components/tab-options/commodities.js b/components/tab-options/commodities.js index 2ee4f1c..7f23386 100644 --- a/components/tab-options/commodities.js +++ b/components/tab-options/commodities.js @@ -35,15 +35,15 @@ export default ({ disabled = false }) => { }, [lastUpdatedFilter, fleetCarrierFilter, minVolumeFilter, locationFilter, distanceFilter]) useEffect(() => { - if (router.query?.maxDaysAgo && router.query.maxDaysAgo !== lastUpdatedFilter) { + if (router.query?.maxDaysAgo && parseInt(router.query.maxDaysAgo) !== parseInt(lastUpdatedFilter)) { setLastUpdatedFilter(router.query.maxDaysAgo) window.localStorage.setItem('lastUpdatedFilter', router.query.maxDaysAgo) } - if (router.query?.fleetCarriers && router.query.fleetCarriers !== fleetCarrierFilter) { + if (router.query?.fleetCarriers && router.query.fleetCarriers !== parseInt(fleetCarrierFilter)) { setFleetCarrierFilter(router.query.fleetCarriers) window.localStorage.setItem('fleetCarrierFilter', router.query.fleetCarriers) } - if (router.query?.minVolume && router.query.minVolume !== minVolumeFilter) { + if (router.query?.minVolume && parseInt(router.query.minVolume) !== parseInt(minVolumeFilter)) { setMinVolumeFilter(router.query.minVolume) window.localStorage.setItem('minVolumeFilter', router.query.minVolume) } @@ -52,7 +52,7 @@ export default ({ disabled = false }) => { window.localStorage.setItem('locationFilter', router.query.location.trim()) document.getElementById('location').value = router.query.location.trim() } - if (router.query?.maxDistance && router.query.maxDaysAgo !== distanceFilter) { + if (router.query?.maxDistance && parseInt(router.query.maxDaysAgo) !== parseInt(distanceFilter)) { setDistanceFilter(router.query.maxDistance) window.localStorage.setItem('distanceFilter', router.query.maxDistance) } @@ -60,7 +60,10 @@ export default ({ disabled = false }) => { return (
-
{ e.preventDefault(); window.dispatchEvent(new CustomEvent('CommodityFilterChangeEvent')); document.activeElement.blur() }}> + { + e.preventDefault() + document.activeElement.blur() + }}>