Initial commit: SIBU 2.0 MISSION
This commit is contained in:
36
frontend/src/stores/shuttle.ts
Normal file
36
frontend/src/stores/shuttle.ts
Normal file
@ -0,0 +1,36 @@
|
||||
/** Pinia store for shuttle management (Intercity/Tourism) */
|
||||
import { defineStore } from 'pinia'
|
||||
import { ref } from 'vue'
|
||||
import type { Shuttle } from '@/types'
|
||||
import { shuttlesService, type ShuttleFilters } from '@/services/shuttlesService'
|
||||
|
||||
export const useShuttleStore = defineStore('shuttle', () => {
|
||||
const shuttles = ref<Shuttle[]>([])
|
||||
const isLoading = ref(false)
|
||||
const error = ref<string | null>(null)
|
||||
const filters = ref<ShuttleFilters>({})
|
||||
|
||||
async function loadShuttles(newFilters?: ShuttleFilters) {
|
||||
isLoading.value = true
|
||||
error.value = null
|
||||
if (newFilters) {
|
||||
filters.value = newFilters
|
||||
}
|
||||
try {
|
||||
shuttles.value = await shuttlesService.getAllShuttles(filters.value)
|
||||
} catch (e) {
|
||||
error.value = e instanceof Error ? e.message : 'Failed to load shuttles'
|
||||
console.error('Error loading shuttles:', e)
|
||||
} finally {
|
||||
isLoading.value = false
|
||||
}
|
||||
}
|
||||
|
||||
return {
|
||||
shuttles,
|
||||
isLoading,
|
||||
error,
|
||||
filters,
|
||||
loadShuttles,
|
||||
}
|
||||
})
|
||||
Reference in New Issue
Block a user