feat(dashboard): integrate Dashboard v2 into main extension (Phase 3.2)
- Add dashboard initialization in initUI() after template load - Inject all required dependencies for widgets: - Data accessors (getContext, getExtensionSettings, getUserAvatar, etc.) - Data setters (setCharacterThoughts) - Event callbacks (onDataChange, onStatsChange, onDashboardChange) - Create default layout on first load if no dashboard config exists - Fallback to legacy rendering (renderUserStats, etc.) on error - Comprehensive error handling with console logging - Auto-save on all data changes
This commit is contained in:
@@ -126,6 +126,14 @@ import {
|
||||
clearExtensionPrompts
|
||||
} from './src/systems/integration/sillytavern.js';
|
||||
|
||||
// Dashboard v2 System
|
||||
import {
|
||||
initializeDashboard,
|
||||
createDefaultLayout,
|
||||
refreshDashboard,
|
||||
getDashboardManager
|
||||
} from './src/systems/dashboard/dashboardIntegration.js';
|
||||
|
||||
// Old state variable declarations removed - now imported from core modules
|
||||
// (extensionSettings, lastGeneratedData, committedTrackerData, etc. are now in src/core/state.js)
|
||||
|
||||
@@ -494,11 +502,76 @@ async function initUI() {
|
||||
// Setup collapse/expand toggle button
|
||||
setupCollapseToggle();
|
||||
|
||||
// Render initial data if available
|
||||
// Initialize Dashboard v2 System
|
||||
try {
|
||||
console.log('[RPG Companion] Initializing Dashboard v2...');
|
||||
|
||||
// Prepare dependencies for widgets
|
||||
const dashboardDependencies = {
|
||||
// Data accessors
|
||||
getContext: () => getContext(),
|
||||
getExtensionSettings: () => extensionSettings,
|
||||
getUserAvatar: () => user_avatar,
|
||||
getCharacters: () => characters,
|
||||
getCurrentCharId: () => this_chid,
|
||||
getGroupMembers: () => getGroupMembers(),
|
||||
getFallbackAvatar: () => FALLBACK_AVATAR_DATA_URI,
|
||||
getAvatarUrl: (type, avatar) => getThumbnailUrl(type, avatar),
|
||||
getCharacterThoughts: () => extensionSettings.characterThoughts || '',
|
||||
|
||||
// Data setters
|
||||
setCharacterThoughts: (value) => {
|
||||
extensionSettings.characterThoughts = value;
|
||||
saveSettings();
|
||||
},
|
||||
|
||||
// Event callbacks
|
||||
onDataChange: (dataType, field, value, extra) => {
|
||||
console.log(`[RPG Companion] Dashboard data changed: ${dataType}.${field}`, value);
|
||||
saveSettings();
|
||||
saveChatData();
|
||||
updateMessageSwipeData();
|
||||
},
|
||||
|
||||
onStatsChange: (category, field, value) => {
|
||||
console.log(`[RPG Companion] Stats changed: ${category}.${field}`, value);
|
||||
saveSettings();
|
||||
saveChatData();
|
||||
updateMessageSwipeData();
|
||||
},
|
||||
|
||||
onDashboardChange: (data) => {
|
||||
console.log('[RPG Companion] Dashboard layout changed');
|
||||
saveSettings();
|
||||
}
|
||||
};
|
||||
|
||||
// Initialize dashboard
|
||||
const manager = await initializeDashboard(dashboardDependencies);
|
||||
|
||||
if (manager) {
|
||||
console.log('[RPG Companion] Dashboard v2 initialized successfully');
|
||||
|
||||
// Check if this is first time - create default layout
|
||||
if (!extensionSettings.dashboard || !extensionSettings.dashboard.tabs) {
|
||||
console.log('[RPG Companion] Creating default dashboard layout...');
|
||||
createDefaultLayout(manager);
|
||||
}
|
||||
} else {
|
||||
console.warn('[RPG Companion] Dashboard initialization returned null, falling back to legacy rendering');
|
||||
throw new Error('Dashboard initialization failed');
|
||||
}
|
||||
} catch (error) {
|
||||
console.error('[RPG Companion] Dashboard v2 initialization failed, using legacy rendering:', error);
|
||||
|
||||
// Fallback to legacy rendering
|
||||
renderUserStats();
|
||||
renderInfoBox();
|
||||
renderThoughts();
|
||||
renderInventory();
|
||||
}
|
||||
|
||||
// Setup remaining UI components
|
||||
updateDiceDisplay();
|
||||
setupDiceRoller();
|
||||
setupClassicStatsButtons();
|
||||
|
||||
Reference in New Issue
Block a user