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:
@@ -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,
|
||||
});
|
||||
}
|
||||
|
||||
// ---------------------------------------------------------------------------
|
||||
|
||||
Reference in New Issue
Block a user