Skip to content

Commit 72b44ad

Browse files
author
ci-bot
committed
fix: Prevent bottom bar from showing on unsupported file types
1 parent 296cd48 commit 72b44ad

File tree

2 files changed

+39
-24
lines changed

2 files changed

+39
-24
lines changed

apps/remix-ide/src/app/components/bottom-bar.tsx

Lines changed: 35 additions & 24 deletions
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,8 @@ interface BottomBarProps {
66
plugin: Plugin
77
}
88

9+
const SUPPORTED_EXTENSIONS = ['sol', 'vy', 'circom', 'js', 'ts']
10+
911
export const BottomBar = ({ plugin }: BottomBarProps) => {
1012
const [explaining, setExplaining] = useState(false)
1113
const [aiSwitch, setAiSwitch] = useState(true)
@@ -22,29 +24,36 @@ export const BottomBar = ({ plugin }: BottomBarProps) => {
2224
}
2325
}
2426

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 || '')
3529
}
3630

31+
const handleFileChange = (path: string) => {
32+
setCurrentFilePath(path || '')
33+
}
34+
3735
getAI()
38-
getCurrentExt()
3936

4037
const onCopilot = (isChecked: boolean) => setAiSwitch(!!isChecked)
4138

39+
plugin.on('tabs', 'extChanged', handleExtChange)
40+
4241
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+
})
4452

4553
return () => {
46-
plugin.off('settings', 'copilotChoiceUpdated')
54+
plugin.off('tabs', 'extChanged')
4755
plugin.off('fileManager', 'currentFileChanged')
56+
plugin.off('settings', 'copilotChoiceUpdated')
4857
}
4958
}, [plugin])
5059

@@ -80,19 +89,21 @@ export const BottomBar = ({ plugin }: BottomBarProps) => {
8089
return ''
8190
}
8291

92+
if (!SUPPORTED_EXTENSIONS.includes(currentExt)) {
93+
return null
94+
}
95+
8396
return (
8497
<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>
96107
<div className="copilot-toggle">
97108
<span className={aiSwitch ? 'on' : ''}>AI copilot</span>
98109
<label className="switch" data-id="copilot_toggle">

libs/remix-ui/tabs/src/lib/remix-ui-tabs.tsx

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -173,6 +173,8 @@ export const TabsUI = (props: TabsUIProps) => {
173173
const activateTab = (name: string) => {
174174
const index = tabs.current.findIndex((tab) => tab.name === name)
175175
currentIndexRef.current = index
176+
const ext = getExt(name)
177+
props.plugin.emit('extChanged', ext)
176178
dispatch({ type: 'SELECT_INDEX', payload: index, ext: getExt(name) })
177179
}
178180

@@ -582,6 +584,8 @@ export const TabsUI = (props: TabsUIProps) => {
582584
onSelect={(index) => {
583585
props.onSelect(index)
584586
currentIndexRef.current = index
587+
const ext = getExt(props.tabs[currentIndexRef.current].name)
588+
props.plugin.emit('extChanged', ext)
585589
dispatch({
586590
type: 'SELECT_INDEX',
587591
payload: index,

0 commit comments

Comments
 (0)