Add more airlines and fix edit bugs

This commit is contained in:
2026-04-20 16:42:11 +10:00
parent 061ee9dd07
commit e007824fa9
15 changed files with 458 additions and 276 deletions
+34 -7
View File
@@ -1,7 +1,7 @@
<script setup lang="ts">
import MainLayout from "@/Layouts/MainLayout.vue";
import { Head } from '@inertiajs/vue3'
import { ref, computed, defineAsyncComponent } from 'vue'
import {ref, computed, defineAsyncComponent, watchEffect, onMounted} from 'vue'
import { Flight, ProfileView, User } from "@/Types/types"
import { router } from '@inertiajs/vue3'
import { useFlightStats, FlightStats } from "@/Composables/useFlightStats"
@@ -17,9 +17,12 @@ const props = defineProps<{
user: User
flights: Flight[]
canEdit: boolean
selectedFlightId: number | null
initialView?: ProfileView
}>()
const localSelectedFlightId = ref(props.selectedFlightId)
// ── Filter state ──────────────────────────────────────────────────────────────
const selectedYears = ref<number[]>([])
const selectedAirlines = ref<number[]>([])
@@ -34,13 +37,17 @@ function onFiltersChange(filters: {
continents: string[]
flightClasses: number[]
}) {
localSelectedFlightId.value = null
console.time('filter+stats')
selectedYears.value = filters.years
selectedAirlines.value = filters.airlines
selectedCountries.value = filters.countries
selectedContinents.value = filters.continents
selectedFlightClasses.value = filters.flightClasses
console.timeEnd('filter+stats')
}
function matchesFilters(f: Flight): boolean {
const date = new Date(f.departure_date)
if (selectedYears.value.length && !selectedYears.value.includes(date.getFullYear())) return false
@@ -55,14 +62,33 @@ function matchesFilters(f: Flight): boolean {
const arrCode = f.arrival_airport.region?.continent?.code
if (!selectedContinents.value.includes(depCode ?? '') && !selectedContinents.value.includes(arrCode ?? '')) return false
}
if (selectedFlightClasses.value.length && !selectedFlightClasses.value.includes(f.flight_class?.id ?? -1)) return false
return true
return !(selectedFlightClasses.value.length && !selectedFlightClasses.value.includes(f.flight_class?.id ?? -1));
}
const filteredFlights = computed(() => props.flights.filter(matchesFilters))
const filteredFlights = computed(() => {
console.time('filteredFlights')
const result = props.flights.filter(matchesFilters)
console.timeEnd('filteredFlights')
return result
})
const stats = useFlightStats(filteredFlights)
watchEffect(() => {
console.time('all.charts.input')
// just access each stat to trigger the log
const _ = [
stats.perYear.value,
stats.perMonth.value,
stats.perDay.value,
stats.topAirlines.value,
stats.topAirports.value,
stats.countries.value,
]
console.timeEnd('all.charts.input')
})
// ── View switching ────────────────────────────────────────────────────────────
const activeView = ref<ProfileView>(props.initialView ?? 'board')
@@ -73,6 +99,7 @@ const routeNames = {
} as const
function switchView(view: ProfileView) {
localSelectedFlightId.value = null
activeView.value = view
window.history.replaceState(
window.history.state,
@@ -86,10 +113,10 @@ function switchView(view: ProfileView) {
<Head :title="`${user.name}'s Flights`" />
<ProfileLayout :flights="flights" :user="user">
<ProfileViewSwitcher :active-view="activeView" @update:active-view="switchView" />
<DepartureBoard v-show="activeView === 'board'" :flight-stats="stats" :canEdit="canEdit" />
<BoardingPasses v-show="activeView === 'passes'" :flight-stats="stats" :canEdit="canEdit" />
<DepartureBoard v-if="activeView === 'board'" :flight-id="localSelectedFlightId" :flight-stats="stats" :canEdit="canEdit" />
<BoardingPasses v-if="activeView === 'passes'" :flight-stats="stats" :canEdit="canEdit" />
<FlightMapAndCharts
v-show="activeView === 'map'"
v-if="activeView === 'map'"
:stats="stats"
:canEdit="canEdit"
@filters-change="onFiltersChange"