feat: add sort option to station search form
This commit is contained in:
@@ -19,6 +19,9 @@ class StationSearch extends Component
|
|||||||
#[Validate('required|integer|min:1|max:20')]
|
#[Validate('required|integer|min:1|max:20')]
|
||||||
public int $radius = 5;
|
public int $radius = 5;
|
||||||
|
|
||||||
|
#[Validate('required|string|in:price,distance,updated,brand')]
|
||||||
|
public string $sort = 'price';
|
||||||
|
|
||||||
public array $results = [];
|
public array $results = [];
|
||||||
|
|
||||||
public array $meta = [];
|
public array $meta = [];
|
||||||
@@ -42,7 +45,7 @@ class StationSearch extends Component
|
|||||||
'postcode' => $this->search,
|
'postcode' => $this->search,
|
||||||
'fuel_type' => $this->fuelType,
|
'fuel_type' => $this->fuelType,
|
||||||
'radius' => $radiusKm,
|
'radius' => $radiusKm,
|
||||||
'sort' => 'price',
|
'sort' => $this->sort,
|
||||||
]);
|
]);
|
||||||
} catch (ConnectionException) {
|
} catch (ConnectionException) {
|
||||||
$this->apiError = 'Unable to fetch stations. Please try again.';
|
$this->apiError = 'Unable to fetch stations. Please try again.';
|
||||||
|
|||||||
@@ -41,6 +41,15 @@
|
|||||||
</flux:select>
|
</flux:select>
|
||||||
</div>
|
</div>
|
||||||
|
|
||||||
|
<div class="w-full sm:w-40">
|
||||||
|
<flux:select wire:model="sort" name="sort" label="Sort by">
|
||||||
|
<flux:select.option value="price">Cheapest first</flux:select.option>
|
||||||
|
<flux:select.option value="distance">Nearest first</flux:select.option>
|
||||||
|
<flux:select.option value="updated">Recently updated</flux:select.option>
|
||||||
|
<flux:select.option value="brand">Brand A–Z</flux:select.option>
|
||||||
|
</flux:select>
|
||||||
|
</div>
|
||||||
|
|
||||||
<div>
|
<div>
|
||||||
<flux:button type="submit" variant="primary" wire:loading.attr="disabled">
|
<flux:button type="submit" variant="primary" wire:loading.attr="disabled">
|
||||||
<span wire:loading.remove wire:target="findStations">Search</span>
|
<span wire:loading.remove wire:target="findStations">Search</span>
|
||||||
|
|||||||
@@ -24,6 +24,7 @@ it('validates search is required', function () {
|
|||||||
it('validates fuelType is required', function () {
|
it('validates fuelType is required', function () {
|
||||||
Livewire::test(StationSearch::class)
|
Livewire::test(StationSearch::class)
|
||||||
->set('search', 'SW1A 1AA')
|
->set('search', 'SW1A 1AA')
|
||||||
|
->set('fuelType', '')
|
||||||
->call('findStations')
|
->call('findStations')
|
||||||
->assertHasErrors(['fuelType' => 'required']);
|
->assertHasErrors(['fuelType' => 'required']);
|
||||||
});
|
});
|
||||||
|
|||||||
Reference in New Issue
Block a user