Added API
This commit is contained in:
@@ -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 }
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user