Skip to content

Commit

Permalink
Fix for hitting enter after typing location name in filter
Browse files Browse the repository at this point in the history
Threre are a bunch of other bugs with this behaviour, mostly performance related, but can get to that in refactoring
  • Loading branch information
iaincollins committed Oct 26, 2024
1 parent 3967034 commit fdea3f8
Show file tree
Hide file tree
Showing 3 changed files with 19 additions and 10 deletions.
19 changes: 14 additions & 5 deletions components/tab-options/commodities.js
Original file line number Diff line number Diff line change
Expand Up @@ -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)
}
Expand All @@ -52,15 +52,18 @@ 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)
}
}, [router.query])

return (
<div className='tab-options'>
<form onSubmit={(e) => { e.preventDefault(); window.dispatchEvent(new CustomEvent('CommodityFilterChangeEvent')); document.activeElement.blur() }}>
<form method='GET' action='/' onSubmit={(e) => {
e.preventDefault()
document.activeElement.blur()
}}>
<label>
<span className='tab-options__label-text'>Updated</span>
<select
Expand Down Expand Up @@ -123,6 +126,12 @@ export default ({ disabled = false }) => {
defaultValue={locationFilter}
previous-value={locationFilter}
size={12}
onKeyDown={(e) => {
if (e.key === 'Enter') {
e.preventDefault()
document.activeElement.blur()
}
}}
onBlur={async (e) => {
const value = e.target.value.replace(/\u200B/g, '').trim()
if (e.target.value === ZERO_WIDTH_SPACE) {
Expand Down
2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "ardent-www",
"version": "0.88.0",
"version": "0.89.0",
"description": "Ardent Industry",
"main": "index.js",
"scripts": {
Expand Down
8 changes: 4 additions & 4 deletions pages/commodity/[commodity-name]/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -297,15 +297,15 @@ export default () => {
</p>
</td>
</tr>}
<tr>
{!commodity?.rare &&<tr>
<th className='is-hidden-mobile'>&nbsp;</th>
<td>
<ul style={{ padding: '0 0 0 1rem' }}>
<li style={{ marginBottom: '1rem' }}><Link href={`/commodity/${router.query['commodity-name'].toLocaleLowerCase()}/importers`}>Where to sell {commodity.name}</Link></li>
<ul style={{ padding: '0 0 0 1.5rem' }}>
<li style={{ marginBottom: '.5rem' }}><Link href={`/commodity/${router.query['commodity-name'].toLocaleLowerCase()}/importers`}>Where to sell {commodity.name}</Link></li>
<li><Link href={`/commodity/${router.query['commodity-name'].toLocaleLowerCase()}/exporters`}>Where to buy {commodity.name}</Link></li>
</ul>
</td>
</tr>
</tr>}
</tbody>
</table>

Expand Down

0 comments on commit fdea3f8

Please sign in to comment.