From f9befb463f825c419a76f0366a2a91e9b9413977 Mon Sep 17 00:00:00 2001 From: Ovidiu U Date: Fri, 10 Apr 2026 18:02:02 +0100 Subject: [PATCH] feat: add usePrediction composable --- resources/js/composables/usePrediction.js | 31 +++++++++++++++++++++++ 1 file changed, 31 insertions(+) create mode 100644 resources/js/composables/usePrediction.js diff --git a/resources/js/composables/usePrediction.js b/resources/js/composables/usePrediction.js new file mode 100644 index 0000000..8eb5284 --- /dev/null +++ b/resources/js/composables/usePrediction.js @@ -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 } +}