fix: move cutoffTs declaration before its use in filtered
Variable was used before declaration (temporal dead zone error). Moved windowHours/hoursBack/cutoffTs above the filtered const that references cutoffTs.
This commit is contained in:
@@ -590,17 +590,7 @@ function TrendTooltip({ active, payload, label }: Record<string, unknown>) {
|
||||
function TrendHistoryChart({ trends, latestTrends, ticker, marketPrices }: { trends: TrendSummary[]; latestTrends: TrendSummary[]; ticker: string; marketPrices: MarketPrice[] }) {
|
||||
const [selectedWindow, setSelectedWindow] = useState('7d');
|
||||
|
||||
// Use history data for charts — filter to selected window and time range
|
||||
const filtered = (trends ?? [])
|
||||
.filter((t) => t.entity_id === ticker && t.window === selectedWindow && new Date(t.generated_at).getTime() >= cutoffTs)
|
||||
.sort((a, b) => new Date(a.generated_at).getTime() - new Date(b.generated_at).getTime());
|
||||
|
||||
// Build a price lookup — match by closest timestamp to each trend point
|
||||
const sortedPrices = [...(marketPrices ?? [])]
|
||||
.filter((p) => p.bar_timestamp != null && p.close != null)
|
||||
.sort((a, b) => a.bar_timestamp - b.bar_timestamp);
|
||||
|
||||
// Determine the time range for the selected window to filter prices
|
||||
// Determine the time range for the selected window to filter data
|
||||
const windowHours: Record<string, number> = {
|
||||
intraday: 12,
|
||||
'1d': 24,
|
||||
@@ -611,6 +601,16 @@ function TrendHistoryChart({ trends, latestTrends, ticker, marketPrices }: { tre
|
||||
const hoursBack = windowHours[selectedWindow] ?? 7 * 24;
|
||||
const cutoffTs = Date.now() - hoursBack * 3600_000;
|
||||
|
||||
// Use history data for charts — filter to selected window and time range
|
||||
const filtered = (trends ?? [])
|
||||
.filter((t) => t.entity_id === ticker && t.window === selectedWindow && new Date(t.generated_at).getTime() >= cutoffTs)
|
||||
.sort((a, b) => new Date(a.generated_at).getTime() - new Date(b.generated_at).getTime());
|
||||
|
||||
// Build a price lookup — match by closest timestamp to each trend point
|
||||
const sortedPrices = [...(marketPrices ?? [])]
|
||||
.filter((p) => p.bar_timestamp != null && p.close != null)
|
||||
.sort((a, b) => a.bar_timestamp - b.bar_timestamp);
|
||||
|
||||
// Filter prices to the selected window's time range
|
||||
const windowPrices = sortedPrices.filter((p) => p.bar_timestamp >= cutoffTs);
|
||||
|
||||
|
||||
Reference in New Issue
Block a user