fix: extract competitive_signals array from API response wrapper
The /api/patterns/{ticker}/competitive-signals endpoint returns
{competitive_signals: [...], count: N} but the hook was typed as
returning a raw array. The component called .map() on the object,
causing 'e.map is not a function'. Now extracts the array from the
response wrapper.
This commit is contained in:
@@ -662,12 +662,18 @@ export interface CompetitiveSignal {
|
|||||||
}
|
}
|
||||||
|
|
||||||
export function useCompetitiveSignals(ticker: string | undefined) {
|
export function useCompetitiveSignals(ticker: string | undefined) {
|
||||||
return useGet<CompetitiveSignal[]>(
|
const result = useGet<CompetitiveSignal[] | { competitive_signals: CompetitiveSignal[] }>(
|
||||||
['competitive-signals', ticker],
|
['competitive-signals', ticker],
|
||||||
'query',
|
'query',
|
||||||
`/api/patterns/${ticker}/competitive-signals`,
|
`/api/patterns/${ticker}/competitive-signals`,
|
||||||
!!ticker,
|
!!ticker,
|
||||||
);
|
);
|
||||||
|
// API returns { competitive_signals: [...] } wrapper — extract the array
|
||||||
|
const data = result.data;
|
||||||
|
const signals: CompetitiveSignal[] | undefined = data
|
||||||
|
? (Array.isArray(data) ? data : (data as { competitive_signals: CompetitiveSignal[] }).competitive_signals ?? [])
|
||||||
|
: undefined;
|
||||||
|
return { ...result, data: signals };
|
||||||
}
|
}
|
||||||
|
|
||||||
// ---------------------------------------------------------------------------
|
// ---------------------------------------------------------------------------
|
||||||
|
|||||||
Reference in New Issue
Block a user