@@ -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,29 +24,36 @@ 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 {
32
- setCurrentFilePath ( '' )
33
- setCurrentExt ( '' )
34
- }
27
+ const handleExtChange = ( ext : string ) => {
28
+ setCurrentExt ( ext || '' )
35
29
}
36
30
31
+ const handleFileChange = ( path : string ) => {
32
+ setCurrentFilePath ( path || '' )
33
+ }
34
+
37
35
getAI ( )
38
- getCurrentExt ( )
39
36
40
37
const onCopilot = ( isChecked : boolean ) => setAiSwitch ( ! ! isChecked )
41
38
39
+ plugin . on ( 'tabs' , 'extChanged' , handleExtChange )
40
+
42
41
plugin . on ( 'settings' , 'copilotChoiceUpdated' , onCopilot )
43
- plugin . on ( 'fileManager' , 'currentFileChanged' , getCurrentExt )
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
+ } )
44
52
45
53
return ( ) => {
46
- plugin . off ( 'settings ' , 'copilotChoiceUpdated ' )
54
+ plugin . off ( 'tabs ' , 'extChanged ' )
47
55
plugin . off ( 'fileManager' , 'currentFileChanged' )
56
+ plugin . off ( 'settings' , 'copilotChoiceUpdated' )
48
57
}
49
58
} , [ plugin ] )
50
59
@@ -80,19 +89,21 @@ export const BottomBar = ({ plugin }: BottomBarProps) => {
80
89
return ''
81
90
}
82
91
92
+ if ( ! SUPPORTED_EXTENSIONS . includes ( currentExt ) ) {
93
+ return null
94
+ }
95
+
83
96
return (
84
97
< div className = "bottom-bar border-top border-bottom" data-id = "bottomBarPanel" >
85
- { getExplainLabel ( ) && (
86
- < button
87
- className = "btn btn-ai"
88
- onClick = { handleExplain }
89
- disabled = { explaining || ! currentFilePath }
90
- data-id = "bottomBarExplainBtn"
91
- >
92
- < img src = "assets/img/remixAI_small.svg" alt = "Remix AI" className = "explain-icon" />
93
- < span > { getExplainLabel ( ) } </ span >
94
- </ button >
95
- ) }
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 >
96
107
< div className = "copilot-toggle" >
97
108
< span className = { aiSwitch ? 'on' : '' } > AI copilot</ span >
98
109
< label className = "switch" data-id = "copilot_toggle" >
0 commit comments