Files
fuel-price/resources/js/composables/useStations.js
Ovidiu U b4bd78ab4c
Some checks failed
linter / quality (push) Has been cancelled
tests / ci (8.3) (push) Has been cancelled
tests / ci (8.4) (push) Has been cancelled
tests / ci (8.5) (push) Has been cancelled
Rename SearchBar to PostSearchFilters, add sort controls and brand filter, relocate station count display
- Move SearchBar.vue to PostSearchFilters.vue and expand to include sort buttons, brand filter dropdown, and station count
- Integrate sort controls (Reliable/Price/Distance/Updated) with icons into filter bar
- Add brand filter dropdown with dynamic brand list from parent, emit update events
- Move station count from StationList to PostSearchFilters, display as "X station(s) found"
- Remove sort tabs and brand filter from StationList component
- Add force-new-line div for mobile layout between Refine and Sort groups
- Include brand filter in hasActive check and resetFilters function
- Update Home.vue to pass brands/brandFilter props and handle brandFilter updates
- Add reset() method to useStations composable to clear state on empty query
- Clear search state when route query is empty instead of attempting search
- Update Fuel Finder API base URL to include /api/v1 path
- Adjust map zoom levels for 10-15 mile radius range
- Update API token request to use retry and increase timeout to 60s
2026-04-22 11:50:59 +01:00

46 lines
1.2 KiB
JavaScript

import { ref } from 'vue'
import api from '../axios.js'
export function useStations() {
const stations = ref([])
const meta = ref(null)
const loading = ref(false)
const error = ref(null)
async function search({ postcode, lat, lng, fuelType = 'e10', radius = 10, sort = 'price' }) {
loading.value = true
error.value = null
stations.value = []
meta.value = null
const params = { fuel_type: fuelType, radius, sort }
if (postcode) {
params.postcode = postcode
} else if (lat && lng) {
params.lat = lat
params.lng = lng
}
try {
const response = await api.get('/stations', { params })
stations.value = response.data.data
meta.value = response.data.meta
} catch (err) {
error.value = err.response?.data?.errors
?? { general: ['Unable to load stations. Please try again.'] }
} finally {
loading.value = false
}
}
function reset() {
stations.value = []
meta.value = null
error.value = null
loading.value = false
}
return { stations, meta, loading, error, search, reset }
}