- Create ToastService extending BaseService with context-specific toast methods - Add useToast composable for convenient dependency injection access - Provide standardized toast patterns: auth, payment, clipboard, operations - Include async operation support with automatic loading/success/error states - Integrate with DI container and base module for automatic initialization - Demonstrate refactoring in LoginDialog.vue with context-specific methods - Eliminate duplicate vue-sonner imports across 20+ files for better maintainability - Support custom ToastOptions interface with full TypeScript compatibility 🤖 Generated with [Claude Code](https://claude.ai/code) Co-Authored-By: Claude <noreply@anthropic.com>
108 lines
No EOL
3.1 KiB
TypeScript
108 lines
No EOL
3.1 KiB
TypeScript
import type { App } from 'vue'
|
|
import type { ModulePlugin } from '@/core/types'
|
|
import { container, SERVICE_TOKENS } from '@/core/di-container'
|
|
import { relayHub } from './nostr/relay-hub'
|
|
|
|
// Import auth services
|
|
import { auth } from './auth/auth-service'
|
|
|
|
// Import PWA services
|
|
import { pwaService } from './pwa/pwa-service'
|
|
|
|
// Import core services
|
|
import { paymentService } from '@/core/services/PaymentService'
|
|
import { visibilityService } from '@/core/services/VisibilityService'
|
|
import { storageService } from '@/core/services/StorageService'
|
|
import { toastService } from '@/core/services/ToastService'
|
|
|
|
/**
|
|
* Base Module Plugin
|
|
* Provides core infrastructure: Nostr, Auth, PWA, and UI components
|
|
*/
|
|
export const baseModule: ModulePlugin = {
|
|
name: 'base',
|
|
version: '1.0.0',
|
|
|
|
async install(_app: App, options?: any) {
|
|
console.log('🔧 Installing base module...')
|
|
|
|
// Register core Nostr services
|
|
container.provide(SERVICE_TOKENS.RELAY_HUB, relayHub)
|
|
|
|
// Register auth service
|
|
container.provide(SERVICE_TOKENS.AUTH_SERVICE, auth)
|
|
|
|
// Register payment service
|
|
container.provide(SERVICE_TOKENS.PAYMENT_SERVICE, paymentService)
|
|
|
|
// Register visibility service
|
|
container.provide(SERVICE_TOKENS.VISIBILITY_SERVICE, visibilityService)
|
|
|
|
// Register storage service
|
|
container.provide(SERVICE_TOKENS.STORAGE_SERVICE, storageService)
|
|
|
|
// Register toast service
|
|
container.provide(SERVICE_TOKENS.TOAST_SERVICE, toastService)
|
|
|
|
// Register PWA service
|
|
container.provide('pwaService', pwaService)
|
|
|
|
// Initialize core services
|
|
relayHub.setRelayUrls(options?.config?.nostr?.relays || [])
|
|
await relayHub.initialize()
|
|
await auth.initialize({
|
|
waitForDependencies: false, // Auth has no dependencies
|
|
maxRetries: 1
|
|
})
|
|
await paymentService.initialize({
|
|
waitForDependencies: true, // PaymentService depends on AuthService
|
|
maxRetries: 3
|
|
})
|
|
await visibilityService.initialize({
|
|
waitForDependencies: false, // VisibilityService has no dependencies
|
|
maxRetries: 1
|
|
})
|
|
await storageService.initialize({
|
|
waitForDependencies: true, // StorageService depends on AuthService
|
|
maxRetries: 3
|
|
})
|
|
await toastService.initialize({
|
|
waitForDependencies: false, // ToastService has no dependencies
|
|
maxRetries: 1
|
|
})
|
|
|
|
console.log('✅ Base module installed successfully')
|
|
},
|
|
|
|
async uninstall() {
|
|
console.log('🗑️ Uninstalling base module...')
|
|
|
|
// Cleanup services
|
|
await relayHub.dispose()
|
|
await auth.dispose()
|
|
await paymentService.dispose()
|
|
await visibilityService.dispose()
|
|
await storageService.dispose()
|
|
await toastService.dispose()
|
|
|
|
console.log('✅ Base module uninstalled')
|
|
},
|
|
|
|
services: {
|
|
relayHub,
|
|
auth,
|
|
paymentService,
|
|
visibilityService,
|
|
storageService,
|
|
toastService,
|
|
pwaService
|
|
},
|
|
|
|
// No routes - base module is pure infrastructure
|
|
routes: [],
|
|
|
|
// No UI components at module level - they'll be imported as needed
|
|
components: {}
|
|
}
|
|
|
|
export default baseModule |