diff --git a/src/app.ts b/src/app.ts index 1b5a930..037bc52 100644 --- a/src/app.ts +++ b/src/app.ts @@ -34,11 +34,21 @@ export async function createAppInstance() { // Create Vue app const app = createApp(App) - // Create router + // Collect all module routes automatically to avoid duplication + const moduleRoutes = [ + // Extract routes from modules directly + ...baseModule.routes || [], + ...nostrFeedModule.routes || [], + ...chatModule.routes || [], + ...eventsModule.routes || [], + ...marketModule.routes || [] + ].filter(Boolean) + + // Create router with all routes available immediately const router = createRouter({ history: createWebHistory(), routes: [ - // Default route - will be populated by modules + // Default routes { path: '/', name: 'home', @@ -50,7 +60,9 @@ export async function createAppInstance() { name: 'login', component: () => import('./pages/LoginDemo.vue'), meta: { requiresAuth: false } - } + }, + // Pre-register module routes + ...moduleRoutes ] }) diff --git a/src/composables/useModuleReady.ts b/src/composables/useModuleReady.ts new file mode 100644 index 0000000..282be41 --- /dev/null +++ b/src/composables/useModuleReady.ts @@ -0,0 +1,40 @@ +import { ref, onMounted } from 'vue' + +/** + * Simple composable to handle module loading and readiness + * Uses Vue's reactivity system - no polling, no complex logic + */ +export function useModuleReady(moduleName: string) { + const isReady = ref(false) + const isLoading = ref(true) + const error = ref(null) + + onMounted(async () => { + try { + // Dynamic import to avoid circular dependencies + const { pluginManager } = await import('@/core/plugin-manager') + + // Install module if not already installed + if (!pluginManager.isInstalled(moduleName)) { + console.log(`🔄 Installing ${moduleName} module...`) + await pluginManager.install(moduleName) + } + + // Module is ready - Vue reactivity handles the rest + isReady.value = true + console.log(`✅ ${moduleName} module ready`) + + } catch (err) { + console.error(`❌ Failed to load ${moduleName} module:`, err) + error.value = err instanceof Error ? err.message : 'Failed to load module' + } finally { + isLoading.value = false + } + }) + + return { + isReady, + isLoading, + error + } +} \ No newline at end of file diff --git a/src/core/plugin-manager.ts b/src/core/plugin-manager.ts index 436feff..bd84151 100644 --- a/src/core/plugin-manager.ts +++ b/src/core/plugin-manager.ts @@ -53,6 +53,12 @@ export class PluginManager { this.modules.set(plugin.name, registration) console.log(`📦 Registered module: ${plugin.name} v${plugin.version}`) + // Routes are now pre-registered during router creation + // This registration step is kept for potential dynamic route additions in the future + if (plugin.routes && this.router) { + console.log(`🛤️ ${plugin.name} routes already pre-registered (${plugin.routes.length} routes)`) + } + // Auto-install if enabled and not lazy if (config.enabled && !config.lazy) { await this.install(plugin.name) @@ -98,12 +104,7 @@ export class PluginManager { await plugin.install(this.app, { config: config.config }) - // Register routes if provided - if (plugin.routes && this.router) { - for (const route of plugin.routes) { - this.router.addRoute(route) - } - } + // Routes are already registered during the register() phase // Register services in DI container if (plugin.services) { diff --git a/src/modules/chat/views/ChatPage.vue b/src/modules/chat/views/ChatPage.vue index 210a5c1..d22544e 100644 --- a/src/modules/chat/views/ChatPage.vue +++ b/src/modules/chat/views/ChatPage.vue @@ -1,9 +1,36 @@ \ No newline at end of file diff --git a/src/modules/events/views/EventsPage.vue b/src/modules/events/views/EventsPage.vue index 51f8e07..261a786 100644 --- a/src/modules/events/views/EventsPage.vue +++ b/src/modules/events/views/EventsPage.vue @@ -1,6 +1,7 @@