Initial commit: SIBU 2.0 MISSION
This commit is contained in:
46
frontend/src/stores/schedule.ts
Normal file
46
frontend/src/stores/schedule.ts
Normal file
@ -0,0 +1,46 @@
|
||||
/** Pinia store for schedule management */
|
||||
import { defineStore } from 'pinia'
|
||||
import { ref } from 'vue'
|
||||
import type { BusSchedule } from '@/types'
|
||||
import { schedulesService } from '@/services/schedulesService'
|
||||
|
||||
export const useScheduleStore = defineStore('schedule', () => {
|
||||
const schedules = ref<BusSchedule[]>([])
|
||||
const isLoading = ref(false)
|
||||
const error = ref<string | null>(null)
|
||||
|
||||
async function loadRouteSchedules(routeId: string) {
|
||||
isLoading.value = true
|
||||
error.value = null
|
||||
try {
|
||||
schedules.value = await schedulesService.getRouteSchedules(routeId)
|
||||
} catch (e) {
|
||||
error.value = e instanceof Error ? e.message : 'Failed to load schedules'
|
||||
console.error('Error loading schedules:', e)
|
||||
} finally {
|
||||
isLoading.value = false
|
||||
}
|
||||
}
|
||||
|
||||
async function loadStopSchedules(stopId: string) {
|
||||
isLoading.value = true
|
||||
error.value = null
|
||||
try {
|
||||
schedules.value = await schedulesService.getStopSchedules(stopId)
|
||||
} catch (e) {
|
||||
error.value = e instanceof Error ? e.message : 'Failed to load schedules'
|
||||
console.error('Error loading schedules:', e)
|
||||
} finally {
|
||||
isLoading.value = false
|
||||
}
|
||||
}
|
||||
|
||||
return {
|
||||
schedules,
|
||||
isLoading,
|
||||
error,
|
||||
loadRouteSchedules,
|
||||
loadStopSchedules,
|
||||
}
|
||||
})
|
||||
|
||||
Reference in New Issue
Block a user