feat: Refactor SidebarManager integration and cleanup methods for improved state management

This commit is contained in:
Will Miao
2025-08-26 21:38:33 +08:00
parent 083f4805b2
commit d62cff9841
5 changed files with 110 additions and 94 deletions

View File

@@ -3,6 +3,7 @@ import { getCurrentPageState, setCurrentPageType } from '../../state/index.js';
import { getStorageItem, setStorageItem, getSessionItem, setSessionItem } from '../../utils/storageHelpers.js';
import { showToast } from '../../utils/uiHelpers.js';
import { SidebarManager } from '../SidebarManager.js';
import { sidebarManager } from '../SidebarManager.js';
/**
* PageControls class - Unified control management for model pages
@@ -24,8 +25,8 @@ export class PageControls {
// Store API methods
this.api = null;
// Initialize sidebar manager
this.sidebarManager = null;
// Use global sidebar manager
this.sidebarManager = sidebarManager;
// Initialize event listeners
this.initEventListeners();
@@ -69,7 +70,7 @@ export class PageControls {
*/
async initSidebarManager() {
try {
this.sidebarManager = new SidebarManager(this);
await this.sidebarManager.initialize(this);
console.log('SidebarManager initialized');
} catch (error) {
console.error('Failed to initialize SidebarManager:', error);
@@ -440,8 +441,10 @@ export class PageControls {
* Clean up resources
*/
destroy() {
if (this.sidebarManager) {
this.sidebarManager.destroy();
// Note: We don't destroy the global sidebar manager, just clean it up
// The global instance will be reused for other page controls
if (this.sidebarManager && this.sidebarManager.isInitialized) {
this.sidebarManager.cleanup();
}
}
}