fix prices reloading
This commit is contained in:
@@ -3,9 +3,7 @@ import { useCallback, useEffect, useMemo, useRef, useState } from 'react'
|
||||
|
||||
import {
|
||||
getCurrentPlan,
|
||||
getSitePrices,
|
||||
getForecastPvSlotsRangeCorrected,
|
||||
type SiteEffectivePriceRowDto,
|
||||
} from '../api/backend'
|
||||
import { getJson } from '../api/postgrest'
|
||||
import {
|
||||
@@ -22,6 +20,7 @@ import type {
|
||||
HeatPumpLatestRow,
|
||||
ModeLogRecentRow,
|
||||
SiteStatusRow,
|
||||
SiteEffectivePriceRow,
|
||||
Telemetry15m7dRow,
|
||||
} from '../types/ems'
|
||||
import type { PlanningIntervalDto } from '../types/plan'
|
||||
@@ -197,7 +196,7 @@ export function useDashboardData(siteId: number | null) {
|
||||
auditHourly,
|
||||
modeLog,
|
||||
hpArr,
|
||||
...priceLists
|
||||
priceRows,
|
||||
] = await Promise.all([
|
||||
getCurrentPlan(siteId).catch((e: unknown) => {
|
||||
if (axios.isAxiosError(e) && e.response?.status === 404) {
|
||||
@@ -221,7 +220,15 @@ export function useDashboardData(siteId: number | null) {
|
||||
limit: '200',
|
||||
}),
|
||||
getJson<HeatPumpLatestRow[]>('/vw_latest_heat_pump', { site_id: `eq.${siteId}` }),
|
||||
...[...dates].map((d) => getSitePrices(siteId, d)),
|
||||
// Ceny bereme v jednom range dotazu přes PostgREST view (místo N× /api/v1/sites/{id}/prices?date=...).
|
||||
// Okno: [windowStart, windowStart + TOTAL_SLOTS) pro mapování na sloty.
|
||||
getJson<SiteEffectivePriceRow[]>('/vw_site_effective_price', {
|
||||
site_id: `eq.${siteId}`,
|
||||
interval_start: `gte.${new Date(windowStart).toISOString()}`,
|
||||
interval_end: `lt.${new Date(windowStart + TOTAL_SLOTS * SLOT_MS).toISOString()}`,
|
||||
order: 'interval_start.asc',
|
||||
limit: String(TOTAL_SLOTS + 32),
|
||||
}),
|
||||
])
|
||||
|
||||
const status = Array.isArray(statusArr) && statusArr[0] ? statusArr[0]! : null
|
||||
@@ -235,7 +242,7 @@ export function useDashboardData(siteId: number | null) {
|
||||
}
|
||||
|
||||
const priceBySlot = new Map<string, { buy: number | null; sell: number | null }>()
|
||||
const flatPrices: SiteEffectivePriceRowDto[] = priceLists.flat() as SiteEffectivePriceRowDto[]
|
||||
const flatPrices: SiteEffectivePriceRow[] = Array.isArray(priceRows) ? priceRows : []
|
||||
for (const r of flatPrices) {
|
||||
const k = slotTimeKey(new Date(r.interval_start).getTime())
|
||||
priceBySlot.set(k, {
|
||||
|
||||
Reference in New Issue
Block a user