Initial commit: SIBU 2.0 MISSION
This commit is contained in:
57
frontend/src/stores/busStop.ts
Normal file
57
frontend/src/stores/busStop.ts
Normal file
@ -0,0 +1,57 @@
|
||||
/** Pinia store for bus stop management */
|
||||
import { defineStore } from 'pinia'
|
||||
import { ref } from 'vue'
|
||||
import type { BusStop } from '@/types'
|
||||
import { busStopsService } from '@/services/busStopsService'
|
||||
|
||||
export const useBusStopStore = defineStore('busStop', () => {
|
||||
const selectedStop = ref<BusStop | null>(null)
|
||||
const busStops = ref<BusStop[]>([])
|
||||
const isLoading = ref(false)
|
||||
const error = ref<string | null>(null)
|
||||
|
||||
async function loadBusStops(force = false) {
|
||||
if (!force && busStops.value.length > 0) {
|
||||
return
|
||||
}
|
||||
|
||||
isLoading.value = true
|
||||
error.value = null
|
||||
try {
|
||||
busStops.value = await busStopsService.getAllBusStops()
|
||||
} catch (e) {
|
||||
error.value = e instanceof Error ? e.message : 'Failed to load bus stops'
|
||||
console.error('Error loading bus stops:', e)
|
||||
} finally {
|
||||
isLoading.value = false
|
||||
}
|
||||
}
|
||||
|
||||
async function loadBusStopById(id: string) {
|
||||
isLoading.value = true
|
||||
error.value = null
|
||||
try {
|
||||
selectedStop.value = await busStopsService.getBusStopById(id)
|
||||
} catch (e) {
|
||||
error.value = e instanceof Error ? e.message : 'Failed to load bus stop'
|
||||
console.error('Error loading bus stop:', e)
|
||||
} finally {
|
||||
isLoading.value = false
|
||||
}
|
||||
}
|
||||
|
||||
function setSelectedStop(stop: BusStop | null) {
|
||||
selectedStop.value = stop
|
||||
}
|
||||
|
||||
return {
|
||||
selectedStop,
|
||||
busStops,
|
||||
isLoading,
|
||||
error,
|
||||
loadBusStops,
|
||||
loadBusStopById,
|
||||
setSelectedStop,
|
||||
}
|
||||
})
|
||||
|
||||
Reference in New Issue
Block a user