Forecast fixes
This commit is contained in:
@@ -16,5 +16,9 @@ export const api = {
|
||||
position: (fields?: string) => get<{latitude: number, longitude: number, altitude: number}>('/api/position', fields ? { fields } : {}),
|
||||
current: (fields?: string) => get<DataRow>('/api/current', fields ? { fields } : {}),
|
||||
hourly: (start?: string, end?: string, fields?: string) => get<DataRow[]>('/api/hourly', { ...(start ? { start } : {}), ...(end ? { end } : {}), ...(fields ? { fields } : {}) }),
|
||||
daily: (start?: string, end?: string, fields?: string) => get<DataRow[]>('/api/daily', { ...(start ? { start } : {}), ...(end ? { end } : {}), ...(fields ? { fields } : {}) }),
|
||||
daily: (start?: Date, end?: Date, fields?: string) => get<DataRow[]>('/api/daily', {
|
||||
...(start ? { start: start.toISOString().slice(0, 10) } : {}),
|
||||
...(end ? { end: end.toISOString().slice(0, 10) } : {}),
|
||||
...(fields ? { fields } : {})
|
||||
}),
|
||||
}
|
||||
|
||||
@@ -1,33 +0,0 @@
|
||||
import { ref, computed } from 'vue'
|
||||
import { api, type DataRow } from './api'
|
||||
|
||||
export const current = ref<DataRow>({})
|
||||
export const hourly = ref<DataRow[]>([])
|
||||
export const daily = ref<DataRow[]>([])
|
||||
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 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
|
||||
lastFetch.value = new Date()
|
||||
loading.value = false
|
||||
}
|
||||
|
||||
export async function fetchHistoricHourly(start: string, end: string): Promise<DataRow[]> {
|
||||
return api.hourly(start, end)
|
||||
}
|
||||
|
||||
export async function fetchHistoricDaily(start: string, end: string): Promise<DataRow[]> {
|
||||
return api.daily(start, end)
|
||||
}
|
||||
|
||||
export const isDaytime = computed(() => current.value.sun_is_day === 1)
|
||||
Reference in New Issue
Block a user