@@ -6,6 +6,8 @@ interface BottomBarProps {
6
6
plugin : Plugin
7
7
}
8
8
9
+ const SUPPORTED_EXTENSIONS = [ 'sol' , 'vy' , 'circom' , 'js' , 'ts' ]
10
+
9
11
export const BottomBar = ( { plugin } : BottomBarProps ) => {
10
12
const [ explaining , setExplaining ] = useState ( false )
11
13
const [ aiSwitch , setAiSwitch ] = useState ( true )
@@ -22,48 +24,52 @@ export const BottomBar = ({ plugin }: BottomBarProps) => {
22
24
}
23
25
}
24
26
25
- const getCurrentExt = async ( ) => {
26
- try {
27
- const path = await plugin . call ( 'fileManager' , 'getCurrentFile' )
28
- setCurrentFilePath ( path )
29
- const ext = path ?. split ( '.' ) . pop ( ) ?. toLowerCase ( ) || ''
30
- setCurrentExt ( ext )
31
- } catch ( err ) {
32
- console . info ( 'No current file selected.' )
33
- setCurrentFilePath ( '' )
34
- setCurrentExt ( '' )
35
- }
27
+ const handleExtChange = ( ext : string ) => {
28
+ setCurrentExt ( ext || '' )
29
+ }
30
+
31
+ const handleFileChange = ( path : string ) => {
32
+ setCurrentFilePath ( path || '' )
36
33
}
37
34
38
35
getAI ( )
39
- getCurrentExt ( )
40
36
41
- plugin . on ( 'settings' , 'copilotChoiceUpdated' , ( isChecked ) => {
42
- setAiSwitch ( isChecked )
43
- } )
37
+ const onCopilot = ( isChecked : boolean ) => setAiSwitch ( ! ! isChecked )
44
38
45
- plugin . on ( 'fileManager' , 'currentFileChanged' , getCurrentExt )
39
+ plugin . on ( 'tabs' , 'extChanged' , handleExtChange )
40
+
41
+ plugin . on ( 'settings' , 'copilotChoiceUpdated' , onCopilot )
42
+ plugin . on ( 'fileManager' , 'currentFileChanged' , handleFileChange )
43
+
44
+ plugin . call ( 'fileManager' , 'getCurrentFile' ) . then ( path => {
45
+ handleFileChange ( path )
46
+ const ext = path ?. split ( '.' ) . pop ( ) ?. toLowerCase ( ) || ''
47
+ handleExtChange ( ext )
48
+ } ) . catch ( ( ) => {
49
+ handleFileChange ( '' )
50
+ handleExtChange ( '' )
51
+ } )
46
52
47
53
return ( ) => {
54
+ plugin . off ( 'tabs' , 'extChanged' )
48
55
plugin . off ( 'fileManager' , 'currentFileChanged' )
56
+ plugin . off ( 'settings' , 'copilotChoiceUpdated' )
49
57
}
50
-
51
58
} , [ plugin ] )
52
59
53
60
const handleExplain = async ( ) => {
54
61
if ( ! currentFilePath ) {
55
- plugin . call ( 'notification' , 'toast' , 'No file selected to explain.' ) ;
62
+ plugin . call ( 'notification' , 'toast' , 'No file selected to explain.' )
56
63
return
57
64
}
58
65
setExplaining ( true )
59
66
try {
60
67
await plugin . call ( 'menuicons' , 'select' , 'remixaiassistant' )
61
- await new Promise ( resolve => setTimeout ( resolve , 500 ) )
68
+ await new Promise ( ( resolve ) => setTimeout ( resolve , 500 ) )
62
69
const content = await plugin . call ( 'fileManager' , 'readFile' , currentFilePath )
63
70
await plugin . call ( 'remixAI' , 'chatPipe' , 'code_explaining' , content + "\n\nExplain briefly the snipped above!" )
64
-
65
71
} catch ( err ) {
66
- console . error ( " Explain failed:" , err )
72
+ console . error ( ' Explain failed:' , err )
67
73
}
68
74
setExplaining ( false )
69
75
}
@@ -83,22 +89,25 @@ export const BottomBar = ({ plugin }: BottomBarProps) => {
83
89
return ''
84
90
}
85
91
92
+ if ( ! SUPPORTED_EXTENSIONS . includes ( currentExt ) ) {
93
+ return null
94
+ }
95
+
86
96
return (
87
- < div className = "bottom-bar border-top border-bottom" >
88
- { getExplainLabel ( ) && (
89
- < button
90
- className = "btn btn-ai"
91
- onClick = { handleExplain }
92
- disabled = { explaining || ! currentFilePath }
93
- >
94
- < img src = "assets/img/remixAI_small.svg" alt = "Remix AI" className = "explain-icon" />
95
- < span > { getExplainLabel ( ) } </ span >
96
- </ button >
97
- ) }
97
+ < div className = "bottom-bar border-top border-bottom" data-id = "bottomBarPanel" >
98
+ < button
99
+ className = "btn btn-ai"
100
+ onClick = { handleExplain }
101
+ disabled = { explaining || ! currentFilePath }
102
+ data-id = "bottomBarExplainBtn"
103
+ >
104
+ < img src = "assets/img/remixAI_small.svg" alt = "Remix AI" className = "explain-icon" />
105
+ < span > { getExplainLabel ( ) } </ span >
106
+ </ button >
98
107
< div className = "copilot-toggle" >
99
- < span className = { aiSwitch ? "on" : "" } > AI copilot</ span >
100
- < label className = "switch" data-id = "copilot_toggle" >
101
- < input type = "checkbox" checked = { aiSwitch } onChange = { toggleAI } />
108
+ < span className = { aiSwitch ? 'on' : '' } > AI copilot</ span >
109
+ < label className = "switch" data-id = "copilot_toggle" >
110
+ < input type = "checkbox" checked = { aiSwitch } onChange = { toggleAI } />
102
111
< span className = "slider" > </ span >
103
112
</ label >
104
113
</ div >
0 commit comments