feat: add sort select to homepage SearchBar

This commit is contained in:
Ovidiu U
2026-04-11 18:57:03 +01:00
parent b8adc98669
commit 951bb0b98d
2 changed files with 16 additions and 2 deletions

View File

@@ -25,7 +25,7 @@
</button> </button>
</div> </div>
<!-- Row 2: fuel type + radius --> <!-- Row 2: fuel type + radius + sort -->
<div class="flex gap-3"> <div class="flex gap-3">
<select <select
v-model="fuelType" v-model="fuelType"
@@ -49,6 +49,17 @@
<option :value="10">10 miles</option> <option :value="10">10 miles</option>
<option :value="20">20 miles</option> <option :value="20">20 miles</option>
</select> </select>
<select
v-model="sort"
aria-label="Sort by"
class="w-32 h-10 px-3 bg-white border border-zinc-300 rounded-xl text-sm font-medium text-zinc-700 focus:outline-none focus:ring-2 focus:ring-accent"
>
<option value="price">Price</option>
<option value="distance">Distance</option>
<option value="updated">Updated</option>
<option value="brand">Brand</option>
<option value="reliable">Reliable</option>
</select>
</div> </div>
</div> </div>
</template> </template>
@@ -61,6 +72,7 @@ const emit = defineEmits(['search'])
const postcode = ref('') const postcode = ref('')
const fuelType = ref('e10') const fuelType = ref('e10')
const radius = ref(10) const radius = ref(10)
const sort = ref('price')
function onSearch() { function onSearch() {
if (!postcode.value.trim()) return if (!postcode.value.trim()) return
@@ -68,6 +80,7 @@ function onSearch() {
postcode: postcode.value.trim(), postcode: postcode.value.trim(),
fuelType: fuelType.value, fuelType: fuelType.value,
radius: radius.value, radius: radius.value,
sort: sort.value,
}) })
} }
</script> </script>

View File

@@ -426,8 +426,9 @@ const searchAttempted = ref(false)
async function onSearch(params) { async function onSearch(params) {
lastParams.value = params lastParams.value = params
sort.value = params.sort ?? sort.value
searchAttempted.value = true searchAttempted.value = true
await search({ ...params, sort: sort.value }) await search(params)
} }
async function onSort(newSort) { async function onSort(newSort) {