feat: add usePrediction composable
This commit is contained in:
31
resources/js/composables/usePrediction.js
Normal file
31
resources/js/composables/usePrediction.js
Normal file
@@ -0,0 +1,31 @@
|
||||
import { ref } from 'vue'
|
||||
import api from '../axios.js'
|
||||
|
||||
export function usePrediction() {
|
||||
const prediction = ref(null)
|
||||
const loading = ref(false)
|
||||
const error = ref(null)
|
||||
|
||||
async function fetch({ lat, lng } = {}) {
|
||||
loading.value = true
|
||||
error.value = null
|
||||
prediction.value = null
|
||||
|
||||
const params = {}
|
||||
if (lat && lng) {
|
||||
params.lat = lat
|
||||
params.lng = lng
|
||||
}
|
||||
|
||||
try {
|
||||
const response = await api.get('/prediction', { params })
|
||||
prediction.value = response.data
|
||||
} catch (err) {
|
||||
error.value = 'Unable to load prediction.'
|
||||
} finally {
|
||||
loading.value = false
|
||||
}
|
||||
}
|
||||
|
||||
return { prediction, loading, error, fetch }
|
||||
}
|
||||
Reference in New Issue
Block a user