Updated UI
This commit is contained in:
@@ -247,8 +247,17 @@ export class AirTrafficLayer {
|
||||
// ── Private ───────────────────────────────────────────────────────────────
|
||||
|
||||
private async _fetch() {
|
||||
const j = await fetch(`${API}/air-traffic`).then(r => r.json())
|
||||
this.data = j.data || []
|
||||
const j = await fetch(`${API}/air-traffic`).then(r => r.json())
|
||||
this.data = (j.data || []).map((a: any) => ({
|
||||
...a,
|
||||
icao: a.hex,
|
||||
latitude: a.lat,
|
||||
longitude: a.lon,
|
||||
heading: a.track,
|
||||
speed: a.gs,
|
||||
climb: a.baro_rate ?? a.geom_rate ?? 0,
|
||||
name: a.flight?.trim(),
|
||||
}))
|
||||
}
|
||||
|
||||
private _draw() {
|
||||
|
||||
@@ -2,6 +2,14 @@ export const BASE = import.meta.env.DEV ? 'http://10.69.5.23:3000' : ''
|
||||
|
||||
export type DataRow = Record<string, number | string | null>
|
||||
|
||||
export async function fetchDaily(start?: string, end?: string): Promise<DataRow[]> {
|
||||
const params = new URLSearchParams()
|
||||
if (start) params.set('start', start)
|
||||
if (end) params.set('end', end)
|
||||
const res = await fetch(`/api/daily?${params}`)
|
||||
return res.json()
|
||||
}
|
||||
|
||||
async function get<T>(path: string, params: Record<string, string> = {}): Promise<T> {
|
||||
const url = new URL(`${BASE}${path}`, window.location.origin)
|
||||
Object.entries(params).forEach(([k, v]) => url.searchParams.set(k, v))
|
||||
|
||||
@@ -8,8 +8,13 @@ export const loading = ref(false)
|
||||
export const lastFetch = ref<Date | null>(null)
|
||||
|
||||
export async function fetchAll() {
|
||||
const date = (d: Date = new Date()) => `${d.getFullYear()}-${(d.getMonth() + 1).toString().padStart(2, '0')}-${d.getDate().toString().padStart(2, '0')}`
|
||||
|
||||
loading.value = true
|
||||
const [c, h, d] = await Promise.allSettled([api.current(), api.hourly(), api.daily()])
|
||||
const start = new Date(), end = new Date();
|
||||
start.setDate(start.getDate() + 1);
|
||||
end.setDate(end.getDate() + 5);
|
||||
const [c, h, d] = await Promise.allSettled([api.current(), api.hourly(), api.daily(date(start), date(end))])
|
||||
if (c.status === 'fulfilled') current.value = c.value
|
||||
if (h.status === 'fulfilled') hourly.value = h.value
|
||||
if (d.status === 'fulfilled') daily.value = d.value
|
||||
|
||||
Reference in New Issue
Block a user