@@ -27,91 +27,33 @@ const agentInfo: Record<string, { name: string; description: string }> = {
2727 } ,
2828}
2929
30- const Tooltip = ( { agent, text } : { agent : Agent , text : string } ) => {
31- const [ showTooltip , setShowTooltip ] = useState ( false ) ;
32- const [ tooltipPosition , setTooltipPosition ] = useState ( { x : 0 , y : 0 } ) ;
33- const [ mounted , setMounted ] = useState ( false ) ;
34-
35- useEffect ( ( ) => {
36- setMounted ( true ) ;
37- return ( ) => setMounted ( false ) ;
38- } , [ ] ) ;
39-
40- const handleMouseEnter = ( e : React . MouseEvent ) => {
41- const rect = e . currentTarget . getBoundingClientRect ( ) ;
42- setTooltipPosition ( {
43- x : rect . left + rect . width / 2 ,
44- y : rect . top
45- } ) ;
46- setShowTooltip ( true ) ;
47- } ;
48-
49- const handleMouseLeave = ( ) => {
50- setShowTooltip ( false ) ;
51- } ;
52-
53- return (
54- < >
55- < span
56- style = { {
57- cursor : 'help' ,
58- position : 'relative' ,
59- display : 'inline-block'
60- } }
61- onMouseEnter = { handleMouseEnter }
62- onMouseLeave = { handleMouseLeave }
63- >
64- < svg width = "16" height = "16" viewBox = "0 0 24 24" fill = "none" stroke = "currentColor" strokeWidth = "2" strokeLinecap = "round" strokeLinejoin = "round" >
65- < circle cx = "12" cy = "12" r = "10" > </ circle >
66- < path d = "M12 16v-4" > </ path >
67- < path d = "M12 8h.01" > </ path >
68- </ svg >
69- </ span >
70- { mounted && showTooltip && createPortal (
71- < div
72- style = { {
73- position : 'fixed' ,
74- left : tooltipPosition . x ,
75- top : tooltipPosition . y ,
76- transform : `translate(${ agent === Agent . LLM ? '-30%' : '-80%' } , -100%)` ,
77- padding : '8px' ,
78- background : 'rgba(0, 0, 0, 0.8)' ,
79- color : 'white' ,
80- borderRadius : '4px' ,
81- fontSize : '12px' ,
82- zIndex : 1000 ,
83- pointerEvents : 'none' ,
84- width : '300px' ,
85- marginTop : '-8px'
86- } }
87- >
88- { text }
89- </ div > ,
90- document . body
91- ) }
92- </ >
93- ) ;
94- } ;
95-
9630const AiInfo : React . FC < AiInfoProps > = ( { selectedSatellite } ) => {
9731
9832 if ( ! selectedSatellite ) return null ;
9933
100- const [ agent , setAgent ] = useState < keyof typeof agentInfo > ( 'llm' ) ;
101- const [ isHovered , setIsHovered ] = useState ( false ) ;
34+ const [ agent , setAgent ] = useState < keyof typeof agentInfo | null > ( null ) ;
10235 const [ isLoading , setIsLoading ] = useState < boolean > ( false ) ;
10336 const [ llmSatelliteInfo , setLlmSatelliteInfo ] = useState < string > ( '' ) ;
10437 const [ ragSatelliteInfo , setRagSatelliteInfo ] = useState < string > ( '' ) ;
105-
106- const satelliteInfo = agent === 'llm' ? llmSatelliteInfo : ragSatelliteInfo ;
107- const setSatelliteInfo = agent === 'llm' ? setLlmSatelliteInfo : setRagSatelliteInfo ;
38+ const satelliteInfo = agent === null ? '' : ( agent === Agent . LLM ? llmSatelliteInfo : ragSatelliteInfo ) ;
10839
10940 useEffect ( ( ) => {
11041 setLlmSatelliteInfo ( '' ) ;
11142 setRagSatelliteInfo ( '' ) ;
11243 } , [ selectedSatellite ] ) ;
11344
114- const fetchSatelliteInfoInChuncks = async ( ) : Promise < void > => {
45+ const onAgentSelect = async ( agent : keyof typeof agentInfo ) => {
46+
47+ // Check if we already have info for this agent
48+ const currentInfo = agent === Agent . LLM ? llmSatelliteInfo : ragSatelliteInfo ;
49+ if ( currentInfo ) {
50+ setAgent ( agent ) ;
51+ return ;
52+ }
53+
54+ setAgent ( agent ) ;
55+ const setSatelliteInfo = agent === Agent . LLM ? setLlmSatelliteInfo : setRagSatelliteInfo ;
56+
11557 setIsLoading ( true ) ;
11658 if ( ! selectedSatellite ) return ;
11759 try {
@@ -129,43 +71,17 @@ const AiInfo: React.FC<AiInfoProps> = ({ selectedSatellite }) => {
12971 return (
13072 < >
13173 < div className = "toggle-buttons" >
132- { Object . entries ( agentInfo ) . map ( ( [ key , value ] ) => (
74+ { Object . keys ( agentInfo ) . map ( ( key : keyof typeof agentInfo ) => (
13375 < button
13476 key = { key }
13577 className = { `toggle-button w-full flex items-center justify-center gap-2 ${ agent === key ? 'active' : '' } ` }
136- onClick = { ( ) => setAgent ( key ) }
78+ onClick = { ( ) => onAgentSelect ( key ) }
13779 >
13880 < span className = "pt-1" > { key . toUpperCase ( ) } </ span >
13981 < Tooltip agent = { key as Agent } text = { agentInfo [ key ] . description } />
14082 </ button >
14183 ) ) }
14284 </ div >
143- { ! satelliteInfo && ! isLoading && (
144- < p className = "mt-4" >
145- < button
146- onClick = { ( ) => fetchSatelliteInfoInChuncks ( ) }
147- onMouseEnter = { ( ) => setIsHovered ( true ) }
148- onMouseLeave = { ( ) => setIsHovered ( false ) }
149- style = { {
150- width : '100%' ,
151- marginBottom : '16px' ,
152- padding : '8px 16px' ,
153- background : isHovered ? 'rgba(59, 130, 246, 0.9)' : 'rgba(59, 130, 246, 0.8)' ,
154- border : '1px solid rgba(147, 197, 253, 0.3)' ,
155- borderRadius : '4px' ,
156- color : 'white' ,
157- fontSize : '14px' ,
158- fontFamily : 'Shentox' ,
159- fontWeight : 500 ,
160- cursor : 'pointer' ,
161- transition : 'all 0.2s ease-in-out' ,
162- transform : isHovered ? 'translateY(-1px)' : 'none'
163- } }
164- >
165- Get AI-Powered Satellite Info
166- </ button >
167- </ p >
168- ) }
16985
17086 < div className = "satellite-info" >
17187 { isLoading ? (
@@ -241,4 +157,70 @@ const AiInfo: React.FC<AiInfoProps> = ({ selectedSatellite }) => {
241157 ) ;
242158} ;
243159
160+ const Tooltip = ( { agent, text } : { agent : Agent , text : string } ) => {
161+ const [ showTooltip , setShowTooltip ] = useState ( false ) ;
162+ const [ tooltipPosition , setTooltipPosition ] = useState ( { x : 0 , y : 0 } ) ;
163+ const [ mounted , setMounted ] = useState ( false ) ;
164+
165+ useEffect ( ( ) => {
166+ setMounted ( true ) ;
167+ return ( ) => setMounted ( false ) ;
168+ } , [ ] ) ;
169+
170+ const handleMouseEnter = ( e : React . MouseEvent ) => {
171+ const rect = e . currentTarget . getBoundingClientRect ( ) ;
172+ setTooltipPosition ( {
173+ x : rect . left + rect . width / 2 ,
174+ y : rect . top
175+ } ) ;
176+ setShowTooltip ( true ) ;
177+ } ;
178+
179+ const handleMouseLeave = ( ) => {
180+ setShowTooltip ( false ) ;
181+ } ;
182+
183+ return (
184+ < >
185+ < span
186+ style = { {
187+ cursor : 'help' ,
188+ position : 'relative' ,
189+ display : 'inline-block'
190+ } }
191+ onMouseEnter = { handleMouseEnter }
192+ onMouseLeave = { handleMouseLeave }
193+ >
194+ < svg width = "16" height = "16" viewBox = "0 0 24 24" fill = "none" stroke = "currentColor" strokeWidth = "2" strokeLinecap = "round" strokeLinejoin = "round" >
195+ < circle cx = "12" cy = "12" r = "10" > </ circle >
196+ < path d = "M12 16v-4" > </ path >
197+ < path d = "M12 8h.01" > </ path >
198+ </ svg >
199+ </ span >
200+ { mounted && showTooltip && createPortal (
201+ < div
202+ style = { {
203+ position : 'fixed' ,
204+ left : tooltipPosition . x ,
205+ top : tooltipPosition . y ,
206+ transform : `translate(${ agent === Agent . LLM ? '-30%' : '-80%' } , -100%)` ,
207+ padding : '8px' ,
208+ background : 'rgba(0, 0, 0, 0.8)' ,
209+ color : 'white' ,
210+ borderRadius : '4px' ,
211+ fontSize : '12px' ,
212+ zIndex : 1000 ,
213+ pointerEvents : 'none' ,
214+ width : '300px' ,
215+ marginTop : '-8px'
216+ } }
217+ >
218+ { text }
219+ </ div > ,
220+ document . body
221+ ) }
222+ </ >
223+ ) ;
224+ } ;
225+
244226export default AiInfo ;
0 commit comments