@@ -34,7 +34,7 @@ interface ISourceData {
3434 url : string ;
3535}
3636
37- export const FetchSource = ( { Detail, ChunkData } : FetchSourceProps ) => {
37+ export const FetchSource = ( { Detail, ChunkData, loading } : FetchSourceProps ) => {
3838 const { t } = useTranslation ( ) ;
3939 const [ isSourceExpanded , setIsSourceExpanded ] = useState ( false ) ;
4040
@@ -51,30 +51,34 @@ export const FetchSource = ({ Detail, ChunkData }: FetchSourceProps) => {
5151 useEffect ( ( ) => {
5252 if ( ! ChunkData ?. message_chunk ) return ;
5353
54- try {
55- const match = ChunkData . message_chunk . match (
56- / \u003c P a y l o a d t o t a l = ( \d + ) \u003e /
57- ) ;
58- if ( match ) {
59- setTotal ( Number ( match [ 1 ] ) ) ;
60- }
54+ if ( ! loading ) {
55+ try {
56+ const match = ChunkData . message_chunk . match (
57+ // /\u003cPayload total=(\d+)\u003e/
58+ / < P a y l o a d t o t a l = ( \d + ) > /
59+ ) ;
60+ if ( match ) {
61+ setTotal ( Number ( match [ 1 ] ) ) ;
62+ }
6163
62- const jsonMatch = ChunkData . message_chunk . match ( / \[ ( .* ) \] / s) ;
63- if ( jsonMatch ) {
64- const jsonData = JSON . parse ( jsonMatch [ 0 ] ) ;
65- setData ( jsonData ) ;
64+ // const jsonMatch = ChunkData.message_chunk.match(/\[(.*)\]/s);
65+ const jsonMatch = ChunkData . message_chunk . match ( / \[ ( [ \s \S ] * ) \] / ) ;
66+ if ( jsonMatch ) {
67+ const jsonData = JSON . parse ( jsonMatch [ 0 ] ) ;
68+ setData ( jsonData ) ;
69+ }
70+ } catch ( e ) {
71+ console . error ( "Failed to parse fetch source data:" , e ) ;
6672 }
67- } catch ( e ) {
68- console . error ( "Failed to parse fetch source data:" , e ) ;
6973 }
70- } , [ ChunkData ?. message_chunk ] ) ;
74+ } , [ ChunkData ?. message_chunk , loading ] ) ;
7175
7276 // Must be after hooks !!!
7377 if ( ! ChunkData && ! Detail ) return null ;
7478
7579 return (
7680 < div
77- className = { `mt-2 mb-2 w-[610px] ${
81+ className = { `mt-2 mb-2 max-w-full w-full md: w-[610px] ${
7882 isSourceExpanded
7983 ? "rounded-lg overflow-hidden border border-[#E6E6E6] dark:border-[#272626]"
8084 : ""
@@ -120,13 +124,13 @@ export const FetchSource = ({ Detail, ChunkData }: FetchSourceProps) => {
120124 className = "group flex items-center p-2 hover:bg-[#F7F7F7] dark:hover:bg-[#2C2C2C] border-b border-[#E6E6E6] dark:border-[#272626] last:border-b-0 cursor-pointer transition-colors"
121125 >
122126 < div className = "w-full flex items-center gap-2" >
123- < div className = "w-[75%] flex items-center gap-1" >
127+ < div className = "w-full md:w- [75%] flex items-center gap-1" >
124128 < Globe className = "w-3 h-3 flex-shrink-0" />
125129 < div className = "text-xs text-[#333333] dark:text-[#D8D8D8] truncate font-normal group-hover:text-[#0072FF] dark:group-hover:text-[#0072FF]" >
126130 { item . title || item . category }
127131 </ div >
128132 </ div >
129- < div className = "w-[25%] flex items-center justify-end gap-2" >
133+ < div className = "hidden md:flex w-[25%] items-center justify-end gap-2" >
130134 < span className = "text-xs text-[#999999] dark:text-[#999999] truncate" >
131135 { item . source ?. name }
132136 </ span >
0 commit comments