Added achievement data
This commit is contained in:
@@ -1,10 +1,10 @@
|
||||
<script setup lang="ts">
|
||||
import MainLayout from "@/Layouts/MainLayout.vue";
|
||||
import { Head } from '@inertiajs/vue3'
|
||||
import {ref, computed, watchEffect} from 'vue'
|
||||
import { Flight, ProfileView, User } from "@/Types/types"
|
||||
import { router } from '@inertiajs/vue3'
|
||||
import { useFlightStats } from "@/Composables/useFlightStats"
|
||||
import {Head, router} from '@inertiajs/vue3'
|
||||
import {computed, onMounted, ref, watchEffect} from 'vue'
|
||||
import axios from 'axios'
|
||||
import {Flight, ProfileView, User} from "@/Types/types"
|
||||
import {useFlightStats} from "@/Composables/useFlightStats"
|
||||
import ProfileViewSwitcher from "@/Components/FlightsGoneBy/ProfileViewSwitcher.vue"
|
||||
import ProfileLayout from "@/Components/FlightsGoneBy/ProfileLayout.vue"
|
||||
import DepartureBoard from "@/Components/FlightsGoneBy/DepartureBoard.vue"
|
||||
@@ -15,13 +15,27 @@ defineOptions({ layout: MainLayout })
|
||||
|
||||
const props = defineProps<{
|
||||
user: User
|
||||
flights: Flight[]
|
||||
canEdit: boolean
|
||||
selectedFlightId?: number | null
|
||||
initialView?: ProfileView
|
||||
isFollowing: boolean
|
||||
flight_api_url: string
|
||||
}>()
|
||||
|
||||
// ── Flights state ─────────────────────────────────────────────────────────────
|
||||
const flights = ref<Flight[]>([])
|
||||
const flightsLoading = ref(true)
|
||||
|
||||
onMounted(async () => {
|
||||
try {
|
||||
const response = await axios.get(props.flight_api_url)
|
||||
|
||||
flights.value = response.data
|
||||
} finally {
|
||||
flightsLoading.value = false
|
||||
}
|
||||
})
|
||||
|
||||
const localSelectedFlightId = ref(props.selectedFlightId ?? null)
|
||||
|
||||
// ── Filter state ──────────────────────────────────────────────────────────────
|
||||
@@ -70,8 +84,7 @@ function matchesFilters(f: Flight): boolean {
|
||||
}
|
||||
|
||||
const filteredFlights = computed(() => {
|
||||
const result = props.flights.filter(matchesFilters)
|
||||
return result
|
||||
return flights.value.filter(matchesFilters)
|
||||
})
|
||||
|
||||
const stats = useFlightStats(filteredFlights)
|
||||
@@ -92,13 +105,18 @@ watchEffect(() => {
|
||||
// ── View switching ────────────────────────────────────────────────────────────
|
||||
const activeView = ref<ProfileView>(props.initialView ?? 'board')
|
||||
|
||||
const routeNames = {
|
||||
const routeNames: Record<Exclude<ProfileView, 'achievements'>, string> = {
|
||||
map: 'profile.map',
|
||||
board: 'profile.departure-board',
|
||||
passes: 'profile.boarding-passes',
|
||||
} as const
|
||||
|
||||
function switchView(view: ProfileView) {
|
||||
if (view === 'achievements') {
|
||||
router.visit(route('profile.achievements', { user: props.user.name }))
|
||||
return
|
||||
}
|
||||
|
||||
const flightId = view === 'board' ? localSelectedFlightId.value : null
|
||||
localSelectedFlightId.value = null
|
||||
activeView.value = view
|
||||
@@ -115,8 +133,8 @@ function switchView(view: ProfileView) {
|
||||
|
||||
<template>
|
||||
<Head :title="`${user.name}'s Flights`" />
|
||||
<ProfileLayout :is-following="isFollowing" :flights="flights" :user="user">
|
||||
<ProfileViewSwitcher :active-view="activeView" @update:active-view="switchView" />
|
||||
<ProfileLayout :is-following="isFollowing" :flightCount="flights.length" :user="user" :loading="flightsLoading">
|
||||
<ProfileViewSwitcher :user="user" :active-view="activeView" @update:active-view="switchView" />
|
||||
<DepartureBoard v-if="activeView === 'board'" :flight-id="localSelectedFlightId" :flight-stats="stats" :canEdit="canEdit" />
|
||||
<BoardingPasses v-if="activeView === 'passes'" :flight-stats="stats" :canEdit="canEdit" />
|
||||
<FlightMapAndCharts
|
||||
|
||||
Reference in New Issue
Block a user