11import { useCallback , useEffect , useRef , useState } from 'react'
22import { news , research } from '../../api/client'
33import type { FeedArticle , MarketDynamicsData } from '../../types/schemas'
4- import type { MarketDynamicsTab } from './marketDynamicsStorage'
54
65const NEWS_REFRESH_MS = 60_000
76const MARKET_REFRESH_MS = 30_000
87
9- export function useMarketInsights ( market : MarketDynamicsTab = 'cn' ) {
8+ function filterCnArticles ( articles : FeedArticle [ ] ) : FeedArticle [ ] {
9+ return articles . filter ( article => {
10+ const text = `${ article . title } ${ article . source_title ?? '' } ` . toLowerCase ( )
11+ return / a 股 | 沪 深 | 上 证 | 深 证 | 创 业 板 | 科 创 板 | 北 交 所 | c n \b | c h i n a / i. test ( text )
12+ || ! / 美 股 | n a s d a q | n y s e | 港 股 | 恒 生 | c r y p t o | b t c / i. test ( text )
13+ } )
14+ }
15+
16+ export function useMarketInsights ( ) {
1017 const [ articles , setArticles ] = useState < FeedArticle [ ] > ( [ ] )
1118 const [ loading , setLoading ] = useState ( true )
1219 const [ error , setError ] = useState ( '' )
@@ -19,20 +26,15 @@ export function useMarketInsights(market: MarketDynamicsTab = 'cn') {
1926 const feedResp = await news . getFeed ( { limit : 24 } ) . catch ( ( ) => null )
2027 if ( ! mountedRef . current ) return
2128 if ( feedResp ?. articles ) {
22- const filtered = feedResp . articles . filter ( article => {
23- const text = `${ article . title } ${ article . source_title ?? '' } ` . toLowerCase ( )
24- return / a 股 | 沪 深 | 上 证 | 深 证 | 创 业 板 | 科 创 板 | 北 交 所 | c n \b | c h i n a / i. test ( text )
25- || ! / 美 股 | n a s d a q | n y s e | 港 股 | 恒 生 | c r y p t o | b t c / i. test ( text )
26- } )
27- setArticles ( filtered . slice ( 0 , 12 ) )
29+ setArticles ( filterCnArticles ( feedResp . articles ) . slice ( 0 , 12 ) )
2830 }
2931 } catch ( e ) {
3032 if ( ! mountedRef . current ) return
3133 setError ( e instanceof Error ? e . message : '资讯加载失败' )
3234 } finally {
3335 if ( mountedRef . current ) setLoading ( false )
3436 }
35- } , [ market ] )
37+ } , [ ] )
3638
3739 useEffect ( ( ) => {
3840 mountedRef . current = true
@@ -47,7 +49,7 @@ export function useMarketInsights(market: MarketDynamicsTab = 'cn') {
4749 return { articles, loading, error, refresh : ( ) => load ( { silent : true } ) }
4850}
4951
50- export function useMarketDynamics ( market : MarketDynamicsTab = 'cn' ) {
52+ export function useMarketDynamics ( ) {
5153 const [ data , setData ] = useState < MarketDynamicsData | null > ( null )
5254 const [ loading , setLoading ] = useState ( true )
5355 const [ refreshing , setRefreshing ] = useState ( false )
@@ -60,10 +62,13 @@ export function useMarketDynamics(market: MarketDynamicsTab = 'cn') {
6062 else setRefreshing ( true )
6163 setError ( '' )
6264 try {
63- const resp = await research . marketDynamics ( { market } )
65+ const resp = await research . marketDynamics ( { market : 'cn' } )
6466 if ( ! mountedRef . current ) return
6567 if ( resp . success && resp . data ) {
66- setData ( resp . data )
68+ setData ( {
69+ ...resp . data ,
70+ market : resp . data . market ?? 'cn' ,
71+ } )
6772 } else {
6873 setError ( resp . message || '暂时无法获取市场数据' )
6974 }
@@ -76,7 +81,7 @@ export function useMarketDynamics(market: MarketDynamicsTab = 'cn') {
7681 setRefreshing ( false )
7782 }
7883 }
79- } , [ market ] )
84+ } , [ ] )
8085
8186 useEffect ( ( ) => {
8287 mountedRef . current = true
0 commit comments