Added Notifications
This commit is contained in:
@@ -0,0 +1,20 @@
|
||||
// useFlights.ts
|
||||
import {onMounted, ref} from "vue";
|
||||
import {Flight} from "@/Types/types";
|
||||
import axios from "axios";
|
||||
|
||||
export function useFlights(url: string) {
|
||||
const flights = ref<Flight[]>([])
|
||||
const flightsLoading = ref(true)
|
||||
|
||||
onMounted(async () => {
|
||||
try {
|
||||
const response = await axios.get(url)
|
||||
flights.value = response.data
|
||||
} finally {
|
||||
flightsLoading.value = false
|
||||
}
|
||||
})
|
||||
|
||||
return { flights, flightsLoading }
|
||||
}
|
||||
@@ -0,0 +1,53 @@
|
||||
// composables/useRegionFlights.ts
|
||||
import {computed, Ref} from "vue";
|
||||
import {Flight, Region} from "@/Types/types";
|
||||
|
||||
export function useRegionFlights(
|
||||
flights: Ref<Flight[]>,
|
||||
regionCodes: string[],
|
||||
countryCode: string,
|
||||
regions: Ref<Region[]>,
|
||||
) {
|
||||
const filteredFlights = computed(() => {
|
||||
return flights.value.filter(flight => {
|
||||
const depCode = flight.departure_airport?.region?.local_code
|
||||
const depCountry = flight.departure_airport?.region?.country?.code
|
||||
const arrCode = flight.arrival_airport?.region?.local_code
|
||||
const arrCountry = flight.arrival_airport?.region?.country?.code
|
||||
|
||||
return (depCountry === countryCode && depCode && regionCodes.includes(depCode)) ||
|
||||
(arrCountry === countryCode && arrCode && regionCodes.includes(arrCode))
|
||||
})
|
||||
})
|
||||
|
||||
const flightsByRegion = computed(() => {
|
||||
return filteredFlights.value.reduce((grouped, flight) => {
|
||||
const dep = flight.departure_airport?.region
|
||||
const arr = flight.arrival_airport?.region
|
||||
|
||||
const regions = [
|
||||
dep?.country?.code === countryCode ? dep?.local_code : null,
|
||||
arr?.country?.code === countryCode ? arr?.local_code : null,
|
||||
].filter((code): code is string => !!code && regionCodes.includes(code))
|
||||
|
||||
;[...new Set(regions)].forEach(code => {
|
||||
if (!grouped[code]) grouped[code] = []
|
||||
grouped[code].push(flight)
|
||||
})
|
||||
|
||||
return grouped
|
||||
}, {} as Record<string, Flight[]>)
|
||||
})
|
||||
|
||||
const regionNames = computed(() => {
|
||||
return Object.fromEntries(
|
||||
regions.value
|
||||
.filter(r => regionCodes.includes(r.local_code))
|
||||
.map(r => [r.local_code, r.name])
|
||||
)
|
||||
})
|
||||
|
||||
const visitedRegions = computed(() => new Set(Object.keys(flightsByRegion.value)))
|
||||
|
||||
return { filteredFlights, flightsByRegion, visitedRegions, regionNames }
|
||||
}
|
||||
Reference in New Issue
Block a user