fix: company detail crash — patterns API returns object not array

/api/patterns/{ticker} returns {ticker, patterns, count} but
useHistoricalPatterns typed its response as HistoricalPattern[].
The .map() call on the object caused 'e.map is not a function'.
Fixed by unwrapping resp.patterns in the hook's queryFn.
This commit is contained in:
Celes Renata
2026-04-17 00:50:51 +00:00
parent 7c589353f8
commit 5593ee6d92
+8 -1
View File
@@ -556,7 +556,14 @@ export function useHistoricalPatterns(ticker: string | undefined, params?: { cat
if (params?.catalyst_type) qs.set('catalyst_type', params.catalyst_type);
if (params?.time_horizon) qs.set('time_horizon', params.time_horizon);
const path = `/api/patterns/${ticker}${qs.toString() ? '?' + qs : ''}`;
return useGet<HistoricalPattern[]>(['historical-patterns', ticker, params], 'query', path, !!ticker);
return useQuery<HistoricalPattern[]>({
queryKey: ['historical-patterns', ticker, params],
queryFn: async () => {
const resp = await apiGet<{ patterns: HistoricalPattern[] }>('query', path);
return resp.patterns ?? [];
},
enabled: !!ticker,
});
}
// ---------------------------------------------------------------------------