Added API

This commit is contained in:
2026-06-21 16:53:39 +10:00
parent 5850c849d0
commit 07e2796e09
12 changed files with 124 additions and 36 deletions
+7 -16
View File
@@ -1,21 +1,12 @@
// useFlights.ts
import {onMounted, ref} from "vue";
import {Flight} from "@/Types/types";
import axios from "axios";
import { computed } from 'vue'
import { useApiResource } from '@/Composables/useApiResource'
import type { Flight } from '@/Types/types'
export function useFlights(url: string, departedOnly: boolean = false) {
const flights = ref<Flight[]>([])
const flightsLoading = ref(true)
const requestUrl = departedOnly ? `${url}/departed` : url
const { data, loading, error } = useApiResource<Flight[]>(requestUrl)
onMounted(async () => {
try {
const requestUrl = departedOnly ? `${url}/departed` : url
const response = await axios.get(requestUrl)
flights.value = response.data
} finally {
flightsLoading.value = false
}
})
const flights = computed(() => data.value ?? [])
return { flights, flightsLoading }
return { flights, flightsLoading: loading, error }
}