Refactor project structure and dependencies; rename package to azaion-ui, update version to 0.0.1, and remove unused files. Introduce new routing and authentication features in App component.

This commit is contained in:
Oleksandr Bezdieniezhnykh
2026-03-25 03:10:15 +02:00
parent e407308284
commit 157a33096a
112 changed files with 6530 additions and 17843 deletions
+52
View File
@@ -0,0 +1,52 @@
import { createContext, useContext, useState, useEffect, useCallback, type ReactNode } from 'react'
import { api } from '../api/client'
import type { Flight, UserSettings } from '../types'
interface FlightState {
flights: Flight[]
selectedFlight: Flight | null
selectFlight: (f: Flight | null) => void
refreshFlights: () => Promise<void>
}
const FlightContext = createContext<FlightState>(null!)
export function useFlight() {
return useContext(FlightContext)
}
export function FlightProvider({ children }: { children: ReactNode }) {
const [flights, setFlights] = useState<Flight[]>([])
const [selectedFlight, setSelectedFlight] = useState<Flight | null>(null)
const refreshFlights = useCallback(async () => {
try {
const data = await api.get<{ items: Flight[] }>('/api/flights?pageSize=1000')
setFlights(data.items ?? [])
} catch {}
}, [])
useEffect(() => {
refreshFlights()
api.get<UserSettings>('/api/annotations/settings/user')
.then(settings => {
if (settings?.selectedFlightId) {
api.get<Flight>(`/api/flights/${settings.selectedFlightId}`)
.then(f => setSelectedFlight(f))
.catch(() => {})
}
})
.catch(() => {})
}, [refreshFlights])
const selectFlight = useCallback((f: Flight | null) => {
setSelectedFlight(f)
api.put('/api/annotations/settings/user', { selectedFlightId: f?.id ?? null }).catch(() => {})
}, [])
return (
<FlightContext.Provider value={{ flights, selectedFlight, selectFlight, refreshFlights }}>
{children}
</FlightContext.Provider>
)
}