@@ -10,6 +10,7 @@ export const BottomBar = ({ plugin }: BottomBarProps) => {
10
10
const [ explaining , setExplaining ] = useState ( false )
11
11
const [ aiSwitch , setAiSwitch ] = useState ( true )
12
12
const [ currentExt , setCurrentExt ] = useState ( '' )
13
+ const [ currentFilePath , setCurrentFilePath ] = useState ( '' )
13
14
14
15
useEffect ( ( ) => {
15
16
const getAI = async ( ) => {
@@ -24,10 +25,12 @@ export const BottomBar = ({ plugin }: BottomBarProps) => {
24
25
const getCurrentExt = async ( ) => {
25
26
try {
26
27
const path = await plugin . call ( 'fileManager' , 'getCurrentFile' )
28
+ setCurrentFilePath ( path )
27
29
const ext = path ?. split ( '.' ) . pop ( ) ?. toLowerCase ( ) || ''
28
30
setCurrentExt ( ext )
29
31
} catch ( err ) {
30
32
console . error ( 'Failed to get current file' , err )
33
+ setCurrentFilePath ( '' )
31
34
setCurrentExt ( '' )
32
35
}
33
36
}
@@ -44,12 +47,15 @@ export const BottomBar = ({ plugin }: BottomBarProps) => {
44
47
} , [ plugin ] )
45
48
46
49
const handleExplain = async ( ) => {
50
+ if ( ! currentFilePath ) {
51
+ plugin . call ( 'notification' , 'toast' , 'No file selected to explain.' ) ;
52
+ return
53
+ }
47
54
setExplaining ( true )
48
55
try {
49
56
await plugin . call ( 'menuicons' , 'select' , 'remixaiassistant' )
50
57
await new Promise ( resolve => setTimeout ( resolve , 500 ) )
51
- const path = await plugin . call ( 'fileManager' , 'getCurrentFile' )
52
- const content = await plugin . call ( 'fileManager' , 'readFile' , path )
58
+ const content = await plugin . call ( 'fileManager' , 'readFile' , currentFilePath )
53
59
await plugin . call ( 'remixAI' , 'chatPipe' , 'code_explaining' , content )
54
60
55
61
} catch ( err ) {
@@ -79,7 +85,7 @@ export const BottomBar = ({ plugin }: BottomBarProps) => {
79
85
< button
80
86
className = "btn explain-btn"
81
87
onClick = { handleExplain }
82
- disabled = { explaining }
88
+ disabled = { explaining || ! currentFilePath }
83
89
>
84
90
< img src = "assets/img/remixAI_small.svg" alt = "Remix AI" className = "explain-icon" />
85
91
< span > { getExplainLabel ( ) } </ span >
0 commit comments