diff --git a/frontend/js/bookslm.js b/frontend/js/bookslm.js index 4039ede..d2ec5b3 100644 --- a/frontend/js/bookslm.js +++ b/frontend/js/bookslm.js @@ -1,6 +1,7 @@ // BooksLM — Directory-scoped AI chat panel (style NotebookLM) import { t } from './i18n.js'; import { buildAIPickerUI } from './ai.js'; +import { safeCreateIcons } from './utils.js'; class BooksLM { constructor() { @@ -43,6 +44,14 @@ class BooksLM { // Open with animation requestAnimationFrame(() => { this._panel.classList.add('open'); + // Apply persisted hidden state (user toggled off in a previous session) + try { + const savedHidden = localStorage.getItem('obsigate-bookslm-hidden'); + if (savedHidden === 'true') { + this._panel.classList.add('hidden'); + this._updateToggleIcon(); + } + } catch { /* */ } }); this._isOpen = true; @@ -77,6 +86,39 @@ class BooksLM { } } + /** + * Toggle the BooksLM sidebar visibility (collapsed/hidden to the right edge + * while the panel stays mounted). The state is persisted in localStorage so + * the user choice survives page reloads — same UX as the left sidebar toggle. + * + * The panel stays in the DOM (no teardown); only a CSS transform is applied, + * which is what makes this fast and matches the right-sidebar pattern in + * ObsiGate. + */ + _toggleSidebar() { + if (!this._panel) return; + const isHidden = this._panel.classList.toggle('hidden'); + try { + localStorage.setItem('obsigate-bookslm-hidden', isHidden ? 'true' : 'false'); + } catch { /* */ } + this._updateToggleIcon(); + } + + /** + * Swap the toggle icon between "panel-right-close" (visible) and + * "panel-right-open" (hidden) so the button visually reflects the state. + */ + _updateToggleIcon() { + if (!this._panel) return; + const btn = this._panel.querySelector('.bookslm-btn-toggle'); + if (!btn) return; + const isHidden = this._panel.classList.contains('hidden'); + const icon = btn.querySelector('i[data-lucide]'); + if (!icon) return; + icon.setAttribute('data-lucide', isHidden ? 'panel-right-open' : 'panel-right-close'); + if (typeof safeCreateIcons === 'function') safeCreateIcons(); + } + newConversation() { this._messages = []; this._saveHistory(); @@ -117,6 +159,9 @@ class BooksLM { panel.className = 'bookslm-panel'; panel.innerHTML = `