Added splash page
This commit is contained in:
@@ -1,6 +1,8 @@
|
||||
import { ref, onMounted, onUnmounted, type Ref } from 'vue'
|
||||
import axios from 'axios'
|
||||
import { api } from '@/api'
|
||||
import { SharedProps } from "@/Types/types"
|
||||
import { usePage } from "@inertiajs/vue3"
|
||||
|
||||
interface UseApiResourceReturn<T> {
|
||||
data: Ref<T | null>
|
||||
@@ -9,7 +11,9 @@ interface UseApiResourceReturn<T> {
|
||||
refresh: () => Promise<void>
|
||||
}
|
||||
|
||||
export function useApiResource<T>(url: string, immediate = true): UseApiResourceReturn<T> {
|
||||
export function useApiResource<T>(route: string, immediate = true): UseApiResourceReturn<T> {
|
||||
const page = usePage<SharedProps>() // resolved when the composable runs, inside setup()
|
||||
|
||||
const data = ref<T | null>(null) as Ref<T | null>
|
||||
const loading = ref(true)
|
||||
const error = ref<string | null>(null)
|
||||
@@ -22,6 +26,8 @@ export function useApiResource<T>(url: string, immediate = true): UseApiResource
|
||||
loading.value = true
|
||||
error.value = null
|
||||
|
||||
// build the url here too, so it always reflects current page props
|
||||
const url = `${page.props.logo_api_url}${route}`
|
||||
try {
|
||||
const response = await api.get<T>(url, { signal: controller.signal })
|
||||
data.value = response.data
|
||||
|
||||
@@ -2,9 +2,8 @@ import { computed } from 'vue'
|
||||
import { useApiResource } from '@/Composables/useApiResource'
|
||||
import type { Flight } from '@/Types/types'
|
||||
|
||||
export function useFlights(url: string, departedOnly: boolean = false) {
|
||||
const requestUrl = departedOnly ? `${url}/departed` : url
|
||||
const { data, loading, error } = useApiResource<Flight[]>(requestUrl)
|
||||
export function useFlights(url: string) {
|
||||
const { data, loading, error } = useApiResource<Flight[]>(url)
|
||||
|
||||
const flights = computed(() => data.value ?? [])
|
||||
|
||||
|
||||
Reference in New Issue
Block a user