From fe01d2d6d0bb99f67396162b545492363d9456f6 Mon Sep 17 00:00:00 2001 From: Ovidiu U Date: Fri, 10 Apr 2026 18:08:38 +0100 Subject: [PATCH] feat: add useSavedStations composable --- resources/js/composables/useSavedStations.js | 33 ++++++++++++++++++++ 1 file changed, 33 insertions(+) create mode 100644 resources/js/composables/useSavedStations.js diff --git a/resources/js/composables/useSavedStations.js b/resources/js/composables/useSavedStations.js new file mode 100644 index 0000000..ae96f26 --- /dev/null +++ b/resources/js/composables/useSavedStations.js @@ -0,0 +1,33 @@ +import { ref } from 'vue' +import api from '../axios.js' + +export function useSavedStations() { + const savedStations = ref([]) + const loading = ref(false) + + async function fetch() { + loading.value = true + try { + const response = await api.get('/user/saved-stations') + savedStations.value = response.data.data + } finally { + loading.value = false + } + } + + async function save(stationId) { + await api.post('/user/saved-stations', { station_id: stationId }) + await fetch() + } + + async function remove(stationId) { + await api.delete(`/user/saved-stations/${stationId}`) + savedStations.value = savedStations.value.filter(s => s.station_id !== stationId) + } + + function isSaved(stationId) { + return savedStations.value.some(s => s.station_id === stationId) + } + + return { savedStations, loading, fetch, save, remove, isSaved } +}