Skip to content

Commit 79130a5

Browse files
committed
fix side panel toggling on vertical icon click
1 parent e9e3e81 commit 79130a5

File tree

3 files changed

+106
-24
lines changed

3 files changed

+106
-24
lines changed

apps/remix-ide/src/app/components/side-panel.tsx

Lines changed: 80 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -53,24 +53,94 @@ export class SidePanel extends AbstractPanel {
5353
// Toggle content
5454
this.on('menuicons', 'toggleContent', (name) => {
5555
if (!this.plugins[name]) return
56+
57+
// If panel is hidden, always show it when any icon is clicked
58+
if (this.isHidden) {
59+
this.isHidden = false
60+
61+
// Immediately remove d-none class for instant visual feedback
62+
const sidePanel = document.querySelector('#side-panel')
63+
sidePanel?.classList.remove('d-none')
64+
65+
// Update localStorage before showing content
66+
const panelStates = JSON.parse(window.localStorage.getItem('panelStates') || '{}')
67+
if (!panelStates.leftSidePanel) panelStates.leftSidePanel = {}
68+
panelStates.leftSidePanel.isHidden = false
69+
panelStates.leftSidePanel.pluginProfile = this.plugins[name]?.profile
70+
window.localStorage.setItem('panelStates', JSON.stringify(panelStates))
71+
72+
this.showContent(name)
73+
this.emit('leftSidePanelShown')
74+
this.events.emit('leftSidePanelShown')
75+
return
76+
}
77+
78+
// Panel is visible - check if plugin is active
5679
if (this.plugins[name].active) {
57-
// TODO: Only keep `this.emit` (issue#2210)
58-
this.emit('toggle', name)
59-
this.events.emit('toggle', name)
80+
// Plugin is active, so toggling will hide the panel
81+
this.isHidden = true
82+
83+
// Immediately add d-none class for instant visual feedback
84+
const sidePanel = document.querySelector('#side-panel')
85+
sidePanel?.classList.add('d-none')
86+
87+
// Update localStorage
88+
const panelStates = JSON.parse(window.localStorage.getItem('panelStates') || '{}')
89+
panelStates.leftSidePanel = {
90+
isHidden: true,
91+
pluginProfile: this.plugins[name]?.profile
92+
}
93+
window.localStorage.setItem('panelStates', JSON.stringify(panelStates))
94+
95+
// Emit explicit panel state events for proper synchronization
96+
this.emit('leftSidePanelHidden')
97+
this.events.emit('leftSidePanelHidden')
6098
return
6199
}
100+
101+
// Plugin is not active, show it
102+
const panelStates = JSON.parse(window.localStorage.getItem('panelStates') || '{}')
103+
if (!panelStates.leftSidePanel) panelStates.leftSidePanel = {}
104+
panelStates.leftSidePanel.isHidden = false
105+
panelStates.leftSidePanel.pluginProfile = this.plugins[name]?.profile
106+
window.localStorage.setItem('panelStates', JSON.stringify(panelStates))
107+
62108
this.showContent(name)
63-
// TODO: Only keep `this.emit` (issue#2210)
64-
this.emit('showing', name)
65-
this.events.emit('showing', name)
109+
this.emit('leftSidePanelShown')
110+
this.events.emit('leftSidePanelShown')
66111
})
67112
// Force opening
68113
this.on('menuicons', 'showContent', (name) => {
69114
if (!this.plugins[name]) return
70-
this.showContent(name)
71-
// TODO: Only keep `this.emit` (issue#2210)
72-
this.emit('showing', name)
73-
this.events.emit('showing', name)
115+
116+
// Read the saved state from localStorage to check if panel should stay hidden
117+
const panelStates = JSON.parse(window.localStorage.getItem('panelStates') || '{}')
118+
const savedIsHidden = panelStates.leftSidePanel?.isHidden
119+
120+
// If panel is currently hidden AND it was intentionally hidden (saved in localStorage),
121+
// just load content without showing the panel (this happens during initialization)
122+
if (this.isHidden && savedIsHidden === true) {
123+
this.showContent(name)
124+
return
125+
}
126+
127+
// Otherwise, force show the panel if it's hidden
128+
if (this.isHidden) {
129+
this.isHidden = false
130+
131+
// Update localStorage
132+
if (!panelStates.leftSidePanel) panelStates.leftSidePanel = {}
133+
panelStates.leftSidePanel.isHidden = false
134+
panelStates.leftSidePanel.pluginProfile = this.plugins[name]?.profile
135+
window.localStorage.setItem('panelStates', JSON.stringify(panelStates))
136+
137+
this.showContent(name)
138+
this.emit('leftSidePanelShown')
139+
this.events.emit('leftSidePanelShown')
140+
} else {
141+
// Panel is already visible, just switch content
142+
this.showContent(name)
143+
}
74144
})
75145
}
76146

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

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -86,6 +86,15 @@ const RemixApp = (props: IRemixAppUi) => {
8686

8787
function setListeners() {
8888
if (!props.app.desktopClientMode){
89+
// Listen to explicit panel state events instead of toggle
90+
props.app.sidePanel.events.on('leftSidePanelHidden', () => {
91+
setHideSidePanel(true)
92+
})
93+
props.app.sidePanel.events.on('leftSidePanelShown', () => {
94+
setHideSidePanel(false)
95+
})
96+
97+
// Keep legacy event listeners for backward compatibility
8998
props.app.sidePanel.events.on('toggle', () => {
9099
setHideSidePanel((prev) => {
91100
return !prev

libs/remix-ui/top-bar/src/lib/remix-ui-topbar.tsx

Lines changed: 17 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -127,22 +127,25 @@ export function RemixUiTopbar() {
127127
setRightPanelHidden(false)
128128
})
129129

130-
// Initialize panel states
130+
// Initialize panel states from localStorage
131131
const initializePanelStates = async () => {
132132
try {
133-
const leftHidden = await plugin.call('sidePanel', 'isPanelHidden')
134-
setLeftPanelHidden(leftHidden)
135-
} catch (e) {}
136-
137-
try {
138-
const bottomHidden = await plugin.call('terminal', 'isPanelHidden')
139-
setBottomPanelHidden(bottomHidden)
140-
} catch (e) {}
141-
142-
try {
143-
const rightHidden = await plugin.call('rightSidePanel', 'isPanelHidden')
144-
setRightPanelHidden(rightHidden)
145-
} catch (e) {}
133+
const panelStatesStr = window.localStorage.getItem('panelStates')
134+
if (panelStatesStr) {
135+
const panelStates = JSON.parse(panelStatesStr)
136+
if (panelStates.leftSidePanel) {
137+
setLeftPanelHidden(panelStates.leftSidePanel.isHidden || false)
138+
}
139+
if (panelStates.bottomPanel) {
140+
setBottomPanelHidden(panelStates.bottomPanel.isHidden || false)
141+
}
142+
if (panelStates.rightSidePanel) {
143+
setRightPanelHidden(panelStates.rightSidePanel.isHidden || false)
144+
}
145+
}
146+
} catch (e) {
147+
console.error('Error reading panel states:', e)
148+
}
146149
}
147150
initializePanelStates()
148151

0 commit comments

Comments
 (0)