@@ -44,48 +44,44 @@ export class RightSidePanel extends AbstractPanel {
4444 let panelStates = panelStatesStr ? JSON . parse ( panelStatesStr ) : { }
4545
4646 if ( panelStates . rightSidePanel ) {
47- this . isHidden = panelStates . rightSidePanel . isHidden || false
48-
49- // Apply d-none class to hide the panel on reload if it was hidden
50- if ( this . isHidden ) {
51- const pinnedPanel = document . querySelector ( '#right-side-panel' )
52- pinnedPanel ?. classList . add ( 'd-none' )
53- // Initialize hiddenPlugin from panelStates if we have a pluginProfile
54- if ( panelStates . rightSidePanel . pluginProfile ) {
47+ // If no plugin profile exists, ensure the panel is hidden
48+ if ( ! panelStates . rightSidePanel . pluginProfile ) {
49+ this . isHidden = true
50+ this . hiddenPlugin = null
51+ } else {
52+ this . isHidden = panelStates . rightSidePanel . isHidden || false
53+ // Apply d-none class to hide the panel on reload if it was hidden
54+ if ( this . isHidden ) {
5555 this . hiddenPlugin = panelStates . rightSidePanel . pluginProfile
5656 } else {
5757 this . hiddenPlugin = null
5858 }
59- } else {
60- this . hiddenPlugin = null
59+ }
60+
61+ if ( this . isHidden ) {
62+ const pinnedPanel = document . querySelector ( '#right-side-panel' )
63+ pinnedPanel ?. classList . add ( 'd-none' )
64+ this . emit ( 'rightSidePanelHidden' )
65+ this . events . emit ( 'rightSidePanelHidden' )
6166 }
6267 } else {
63- // Initialize with default state if not found
64- this . isHidden = false
68+ // Initialize with default state if not found - no plugin pinned means hidden
69+ this . isHidden = true
6570 this . hiddenPlugin = null
6671 // Note: pluginProfile will be set when a plugin is pinned
6772 panelStates . rightSidePanel = {
6873 isHidden : this . isHidden ,
6974 pluginProfile : null
7075 }
7176 window . localStorage . setItem ( 'panelStates' , JSON . stringify ( panelStates ) )
77+ const pinnedPanel = document . querySelector ( '#right-side-panel' )
78+ pinnedPanel ?. classList . add ( 'd-none' )
79+ this . emit ( 'rightSidePanelHidden' )
80+ this . events . emit ( 'rightSidePanelHidden' )
7281 }
7382 }
7483
7584 async pinView ( profile , view ) {
76- // Only show the panel if we're pinning a different plugin than the one that's currently hidden
77- if ( this . hiddenPlugin && this . hiddenPlugin . name !== profile . name ) {
78- const pinnedPanel = document . querySelector ( '#right-side-panel' )
79- pinnedPanel ?. classList . remove ( 'd-none' )
80- this . hiddenPlugin = null
81- this . isHidden = false
82- // Update panelStates
83- const panelStates = JSON . parse ( window . localStorage . getItem ( 'panelStates' ) || '{}' )
84- panelStates . rightSidePanel = { isHidden : false , pluginProfile : profile }
85- window . localStorage . setItem ( 'panelStates' , JSON . stringify ( panelStates ) )
86- this . events . emit ( 'rightSidePanelShown' )
87- this . emit ( 'rightSidePanelShown' )
88- }
8985 const activePlugin = this . currentFocus ( )
9086
9187 if ( activePlugin === profile . name ) throw new Error ( `Plugin ${ profile . name } already pinned` )
@@ -97,36 +93,50 @@ export class RightSidePanel extends AbstractPanel {
9793 this . addView ( profile , view )
9894 this . plugins [ profile . name ] . pinned = true
9995 this . plugins [ profile . name ] . active = true
100- // Read isHidden state from panelStates
101- const panelStates = window . localStorage . getItem ( 'panelStates' )
102- let isHidden = false
103- if ( panelStates ) {
104- try {
105- const states = JSON . parse ( panelStates )
106- if ( states . rightSidePanel ?. isHidden ) {
107- isHidden = true
108- const pinnedPanel = document . querySelector ( '#right-side-panel' )
109- pinnedPanel ?. classList . add ( 'd-none' )
110- this . hiddenPlugin = profile
111- this . isHidden = true
112- }
113- } catch ( e ) { }
114- }
115- if ( ! isHidden && ! this . hiddenPlugin ) {
96+
97+ // When pinning a plugin, check if panel was hidden because no plugin was pinned
98+ const panelStates = JSON . parse ( window . localStorage . getItem ( 'panelStates' ) || '{}' )
99+ const wasHiddenWithNoPlugin = this . isHidden && ! panelStates . rightSidePanel ?. pluginProfile
100+
101+ // Show the panel if it was hidden due to no plugin being pinned
102+ if ( wasHiddenWithNoPlugin ) {
103+ const pinnedPanel = document . querySelector ( '#right-side-panel' )
104+ pinnedPanel ?. classList . remove ( 'd-none' )
105+ this . hiddenPlugin = null
116106 this . isHidden = false
117107 this . events . emit ( 'rightSidePanelShown' )
118108 this . emit ( 'rightSidePanelShown' )
109+ } else if ( this . hiddenPlugin && this . hiddenPlugin . name !== profile . name ) {
110+ // Only show the panel if we're pinning a different plugin than the one that's currently hidden
111+ const pinnedPanel = document . querySelector ( '#right-side-panel' )
112+ pinnedPanel ?. classList . remove ( 'd-none' )
113+ this . hiddenPlugin = null
114+ this . isHidden = false
115+ this . events . emit ( 'rightSidePanelShown' )
116+ this . emit ( 'rightSidePanelShown' )
117+ } else if ( this . hiddenPlugin && this . hiddenPlugin . name === profile . name ) {
118+ // If we're pinning the same plugin that was hidden, keep it hidden
119+ const pinnedPanel = document . querySelector ( '#right-side-panel' )
120+ pinnedPanel ?. classList . add ( 'd-none' )
121+ this . hiddenPlugin = profile
122+ this . isHidden = true
119123 }
124+
125+ if ( ! this . isHidden && ! this . hiddenPlugin ) {
126+ this . events . emit ( 'rightSidePanelShown' )
127+ this . emit ( 'rightSidePanelShown' )
128+ }
129+
120130 // Save pinned plugin profile to panelStates
121131 const updatedPanelStates = JSON . parse ( window . localStorage . getItem ( 'panelStates' ) || '{}' )
122132 updatedPanelStates . rightSidePanel = {
123- isHidden : isHidden ,
133+ isHidden : this . isHidden ,
124134 pluginProfile : profile
125135 }
126136 window . localStorage . setItem ( 'panelStates' , JSON . stringify ( updatedPanelStates ) )
127137 this . renderComponent ( )
128- this . events . emit ( 'pinnedPlugin' , profile , isHidden )
129- this . emit ( 'pinnedPlugin' , profile , isHidden )
138+ this . events . emit ( 'pinnedPlugin' , profile , this . isHidden )
139+ this . emit ( 'pinnedPlugin' , profile , this . isHidden )
130140 }
131141
132142 async unPinView ( profile ) {
@@ -135,14 +145,22 @@ export class RightSidePanel extends AbstractPanel {
135145 if ( activePlugin !== profile . name ) throw new Error ( `Plugin ${ profile . name } is not pinned` )
136146 await this . call ( 'sidePanel' , 'unPinView' , profile , this . plugins [ profile . name ] . view )
137147 super . remove ( profile . name )
138- // Clear hiddenPlugin and panel state from localStorage
148+ // Clear hiddenPlugin and set panel to hidden state when no plugin is pinned
139149 this . hiddenPlugin = null
150+ this . isHidden = true
151+ const pinnedPanel = document . querySelector ( '#right-side-panel' )
152+ pinnedPanel ?. classList . add ( 'd-none' )
140153 const panelStates = JSON . parse ( window . localStorage . getItem ( 'panelStates' ) || '{}' )
141- delete panelStates . rightSidePanel
154+ panelStates . rightSidePanel = {
155+ isHidden : true ,
156+ pluginProfile : null
157+ }
142158 window . localStorage . setItem ( 'panelStates' , JSON . stringify ( panelStates ) )
143159 this . renderComponent ( )
144160 this . events . emit ( 'unPinnedPlugin' , profile )
145161 this . emit ( 'unPinnedPlugin' , profile )
162+ this . emit ( 'rightSidePanelHidden' )
163+ this . events . emit ( 'rightSidePanelHidden' )
146164 }
147165
148166 getHiddenPlugin ( ) {
@@ -155,6 +173,26 @@ export class RightSidePanel extends AbstractPanel {
155173 const panelStates = JSON . parse ( window . localStorage . getItem ( 'panelStates' ) || '{}' )
156174 const currentPlugin = this . currentFocus ( )
157175 const pluginProfile = currentPlugin && this . plugins [ currentPlugin ] ? this . plugins [ currentPlugin ] . profile : null
176+
177+ // Check if no plugin is pinned
178+ if ( ! pluginProfile ) {
179+ this . call ( 'notification' , 'toast' , 'No plugin pinned on right side panel' )
180+ // Ensure the panel is hidden and toggle icon is off
181+ if ( ! this . isHidden ) {
182+ this . isHidden = true
183+ pinnedPanel ?. classList . add ( 'd-none' )
184+ this . emit ( 'rightSidePanelHidden' )
185+ this . events . emit ( 'rightSidePanelHidden' )
186+ panelStates . rightSidePanel = {
187+ isHidden : this . isHidden ,
188+ pluginProfile : null
189+ }
190+ window . localStorage . setItem ( 'panelStates' , JSON . stringify ( panelStates ) )
191+ this . renderComponent ( )
192+ }
193+ return
194+ }
195+
158196 if ( this . isHidden ) {
159197 this . isHidden = false
160198 pinnedPanel ?. classList . remove ( 'd-none' )
0 commit comments